diff --git a/core/blockly.js b/core/blockly.js index 8b7083401..1e832ac16 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -402,11 +402,15 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) { * @param {boolean} opt_noCaptureIdentifier True if triggering on this event * should not block execution of other event handlers on this touch or other * simultaneous touches. + * @param {boolean} opt_noPreventDefault True if triggering on this event + * should prevent the default handler. False by default. If + * opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be + * provided. * @return {!Array.} Opaque data that can be passed to unbindEvent_. * @private */ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func, - opt_noCaptureIdentifier) { + opt_noCaptureIdentifier, opt_noPreventDefault) { var handled = false; var wrapFunc = function(e) { var captureIdentifier = !opt_noCaptureIdentifier; @@ -434,8 +438,10 @@ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func, if (name in Blockly.Touch.TOUCH_MAP) { var touchWrapFunc = function(e) { wrapFunc(e); - // Stop the browser from scrolling/zooming the page. - if (handled) { + // Calling preventDefault stops the browser from scrolling/zooming the + // page. + var preventDef = !opt_noPreventDefault; + if (handled && preventDef) { e.preventDefault(); } }; diff --git a/core/toolbox.js b/core/toolbox.js index 6d72c154f..40378e101 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -170,7 +170,7 @@ Blockly.Toolbox.prototype.init = function() { Blockly.hideChaff(true); } Blockly.Touch.clearTouchIdentifier(); // Don't block future drags. - }); + }, /*opt_noCaptureIdentifier*/ false, /*opt_noPreventDefault*/ true); var workspaceOptions = { disabledPatternId: workspace.options.disabledPatternId, parentWorkspace: workspace, @@ -511,7 +511,7 @@ Blockly.Toolbox.TreeControl.prototype.enterDocument = function() { // Add touch handler. if (goog.events.BrowserFeature.TOUCH_ENABLED) { var el = this.getElement(); - Blockly.bindEventWithChecks_(el, goog.events.EventType.TOUCHSTART, this, + Blockly.bindEventWithChecks_(el, goog.events.EventType.TOUCHEND, this, this.handleTouchEvent_); } }; @@ -522,13 +522,12 @@ Blockly.Toolbox.TreeControl.prototype.enterDocument = function() { * @private */ Blockly.Toolbox.TreeControl.prototype.handleTouchEvent_ = function(e) { - e.preventDefault(); var node = this.getNodeFromEvent_(e); - if (node && e.type === goog.events.EventType.TOUCHSTART) { + if (node && e.type === goog.events.EventType.TOUCHEND) { // Fire asynchronously since onMouseDown takes long enough that the browser // would fire the default mouse event before this method returns. setTimeout(function() { - node.onMouseDown(e); // Same behaviour for click and touch. + node.onClick_(e); // Same behaviour for click and touch. }, 1); } }; @@ -630,7 +629,7 @@ Blockly.Toolbox.TreeNode.prototype.getExpandIconSafeHtml = function() { * @param {!goog.events.BrowserEvent} e The browser event. * @override */ -Blockly.Toolbox.TreeNode.prototype.onMouseDown = function(e) { +Blockly.Toolbox.TreeNode.prototype.onClick_ = function(e) { // Expand icon. if (this.hasChildren() && this.isUserCollapsible_) { this.toggle(); @@ -643,6 +642,16 @@ Blockly.Toolbox.TreeNode.prototype.onMouseDown = function(e) { this.updateRow(); }; +/** + * Suppress the inherited mouse down behaviour. + * @param {!goog.events.BrowserEvent} e The browser event. + * @override + * @private + */ +Blockly.Toolbox.TreeNode.prototype.onMouseDown = function(e) { + // NOPE. +}; + /** * Suppress the inherited double-click behaviour. * @param {!goog.events.BrowserEvent} e The browser event.