Commit fdab10f6 authored by neil.fraser@gmail.com's avatar neil.fraser@gmail.com Committed by carlospamg

Fix touch bug which dropped blocks when created from an autoclosing flyout.

git-svn-id: http://blockly.googlecode.com/svn/trunk@1743 c400ca83-b69d-9dd7-9705-49c6b8615e23
parent 11e4a5a7
This diff is collapsed.
...@@ -302,27 +302,30 @@ Blockly.Flyout.prototype.hide = function() { ...@@ -302,27 +302,30 @@ Blockly.Flyout.prototype.hide = function() {
Blockly.unbindEvent_(this.reflowWrapper_); Blockly.unbindEvent_(this.reflowWrapper_);
this.reflowWrapper_ = null; this.reflowWrapper_ = null;
} }
// Delete all the blocks. // Do NOT delete the blocks here. Wait until Flyout.show.
// https://neil.fraser.name/news/2014/08/09/
};
/**
* Show and populate the flyout.
* @param {!Array|string} xmlList List of blocks to show.
* Variables and procedures have a custom set of blocks.
*/
Blockly.Flyout.prototype.show = function(xmlList) {
this.hide();
// Delete any blocks from a previous showing.
var blocks = this.workspace_.getTopBlocks(false); var blocks = this.workspace_.getTopBlocks(false);
for (var x = 0, block; block = blocks[x]; x++) { for (var x = 0, block; block = blocks[x]; x++) {
if (block.workspace == this.workspace_) { if (block.workspace == this.workspace_) {
block.dispose(false, false); block.dispose(false, false);
} }
} }
// Delete all the background buttons. // Delete any background buttons from a previous showing.
for (var x = 0, rect; rect = this.buttons_[x]; x++) { for (var x = 0, rect; rect = this.buttons_[x]; x++) {
goog.dom.removeNode(rect); goog.dom.removeNode(rect);
} }
this.buttons_.splice(0); this.buttons_.splice(0);
};
/**
* Show and populate the flyout.
* @param {!Array|string} xmlList List of blocks to show.
* Variables and procedures have a custom set of blocks.
*/
Blockly.Flyout.prototype.show = function(xmlList) {
this.hide();
var margin = this.CORNER_RADIUS; var margin = this.CORNER_RADIUS;
this.svgGroup_.style.display = 'block'; this.svgGroup_.style.display = 'block';
......
...@@ -100,9 +100,11 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) { ...@@ -100,9 +100,11 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) {
// Stop the browser from scrolling/zooming the page // Stop the browser from scrolling/zooming the page
e.preventDefault(); e.preventDefault();
}; };
node.addEventListener(Blockly.bindEvent_.TOUCH_MAP[name], for (var i = 0, eventName;
wrapFunc, false); eventName = Blockly.bindEvent_.TOUCH_MAP[name][i]; i++) {
bindData.push([node, Blockly.bindEvent_.TOUCH_MAP[name], wrapFunc]); node.addEventListener(eventName, wrapFunc, false);
bindData.push([node, eventName, wrapFunc]);
}
} }
return bindData; return bindData;
}; };
...@@ -115,9 +117,9 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) { ...@@ -115,9 +117,9 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) {
Blockly.bindEvent_.TOUCH_MAP = {}; Blockly.bindEvent_.TOUCH_MAP = {};
if ('ontouchstart' in document.documentElement) { if ('ontouchstart' in document.documentElement) {
Blockly.bindEvent_.TOUCH_MAP = { Blockly.bindEvent_.TOUCH_MAP = {
'mousedown': 'touchstart', 'mousedown': ['touchstart'],
'mousemove': 'touchmove', 'mousemove': ['touchmove'],
'mouseup': 'touchend' 'mouseup': ['touchend', 'touchcancel']
}; };
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment