diff --git a/core/block_svg.js b/core/block_svg.js index 6ae84884d..55c8673df 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -16,6 +16,7 @@ goog.require('Blockly.ASTNode'); goog.require('Blockly.Block'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockRendering.IPathObject'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); @@ -223,7 +224,7 @@ Blockly.BlockSvg.prototype.initSvg = function() { this.pathObject.updateMovable(this.isMovable()); var svg = this.getSvgRoot(); if (!this.workspace.options.readOnly && !this.eventsInit_ && svg) { - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( svg, 'mousedown', this, this.onMouseDown_); } this.eventsInit_ = true; diff --git a/core/comment.js b/core/comment.js index 2b261ed38..b8063d158 100644 --- a/core/comment.js +++ b/core/comment.js @@ -12,6 +12,7 @@ goog.provide('Blockly.Comment'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Bubble'); goog.require('Blockly.Css'); goog.require('Blockly.Events'); @@ -167,21 +168,21 @@ Blockly.Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - this.onMouseUpWrapper_ = Blockly.bindEventWithChecks_( + this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = Blockly.bindEventWithChecks_( + this.onWheelWrapper_ = Blockly.browserEvents.conditionalBind( textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - this.onChangeWrapper_ = Blockly.bindEventWithChecks_( + this.onChangeWrapper_ = Blockly.browserEvents.conditionalBind( textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { Blockly.Events.fire(new Blockly.Events.BlockChange( this.block_, 'comment', null, this.cachedText_, this.model_.text)); } }); - this.onInputWrapper_ = Blockly.bindEventWithChecks_( + this.onInputWrapper_ = Blockly.browserEvents.conditionalBind( textarea, 'input', this, function(_e) { this.model_.text = textarea.value; }); @@ -303,19 +304,19 @@ Blockly.Comment.prototype.createNonEditableBubble_ = function() { */ Blockly.Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { - Blockly.unbindEvent_(this.onMouseUpWrapper_); + Blockly.browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onWheelWrapper_) { - Blockly.unbindEvent_(this.onWheelWrapper_); + Blockly.browserEvents.unbind(this.onWheelWrapper_); this.onWheelWrapper_ = null; } if (this.onChangeWrapper_) { - Blockly.unbindEvent_(this.onChangeWrapper_); + Blockly.browserEvents.unbind(this.onChangeWrapper_); this.onChangeWrapper_ = null; } if (this.onInputWrapper_) { - Blockly.unbindEvent_(this.onInputWrapper_); + Blockly.browserEvents.unbind(this.onInputWrapper_); this.onInputWrapper_ = null; } this.bubble_.dispose(); diff --git a/core/contextmenu.js b/core/contextmenu.js index 7f64acef2..16d711154 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -16,6 +16,7 @@ */ goog.provide('Blockly.ContextMenu'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockCreate'); @@ -152,8 +153,9 @@ Blockly.ContextMenu.createWidget_ = function(menu) { Blockly.utils.dom.addClass( /** @type {!Element} */ (menuDom), 'blocklyContextMenu'); // Prevent system context menu when right-clicking a Blockly context menu. - Blockly.bindEventWithChecks_(/** @type {!EventTarget} */ (menuDom), - 'contextmenu', null, Blockly.utils.noEvent); + Blockly.browserEvents.conditionalBind( + /** @type {!EventTarget} */ (menuDom), 'contextmenu', null, + Blockly.utils.noEvent); // Focus only after the initial render to avoid issue #1329. menu.focus(); }; diff --git a/core/field.js b/core/field.js index abb903d22..f9c30937f 100644 --- a/core/field.js +++ b/core/field.js @@ -14,6 +14,7 @@ goog.provide('Blockly.Field'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Gesture'); @@ -381,9 +382,8 @@ Blockly.Field.prototype.createTextElement_ = function() { */ Blockly.Field.prototype.bindEvents_ = function() { Blockly.Tooltip.bindMouseEvents(this.getClickTarget_()); - this.mouseDownWrapper_ = - Blockly.bindEventWithChecks_( - this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); + this.mouseDownWrapper_ = Blockly.browserEvents.conditionalBind( + this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); }; /** @@ -419,7 +419,7 @@ Blockly.Field.prototype.dispose = function() { Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_()); if (this.mouseDownWrapper_) { - Blockly.unbindEvent_(this.mouseDownWrapper_); + Blockly.browserEvents.unbind(this.mouseDownWrapper_); } Blockly.utils.dom.removeNode(this.fieldGroup_); diff --git a/core/field_angle.js b/core/field_angle.js index a5db25434..d290fee43 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -12,6 +12,7 @@ goog.provide('Blockly.FieldAngle'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.fieldRegistry'); @@ -331,16 +332,14 @@ Blockly.FieldAngle.prototype.dropdownCreate_ = function() { // mousemove even if it's not in the middle of a drag. In future we may // change this behaviour. this.clickWrapper_ = - Blockly.bindEventWithChecks_(svg, 'click', this, this.hide_); + Blockly.browserEvents.conditionalBind(svg, 'click', this, this.hide_); // On touch devices, the picker's value is only updated with a drag. Add // a click handler on the drag surface to update the value if the surface // is clicked. - this.clickSurfaceWrapper_ = - Blockly.bindEventWithChecks_(circle, 'click', this, this.onMouseMove_, - true, true); - this.moveSurfaceWrapper_ = - Blockly.bindEventWithChecks_(circle, 'mousemove', this, this.onMouseMove_, - true, true); + this.clickSurfaceWrapper_ = Blockly.browserEvents.conditionalBind( + circle, 'click', this, this.onMouseMove_, true, true); + this.moveSurfaceWrapper_ = Blockly.browserEvents.conditionalBind( + circle, 'mousemove', this, this.onMouseMove_, true, true); return svg; }; @@ -350,15 +349,15 @@ Blockly.FieldAngle.prototype.dropdownCreate_ = function() { */ Blockly.FieldAngle.prototype.dropdownDispose_ = function() { if (this.clickWrapper_) { - Blockly.unbindEvent_(this.clickWrapper_); + Blockly.browserEvents.unbind(this.clickWrapper_); this.clickWrapper_ = null; } if (this.clickSurfaceWrapper_) { - Blockly.unbindEvent_(this.clickSurfaceWrapper_); + Blockly.browserEvents.unbind(this.clickSurfaceWrapper_); this.clickSurfaceWrapper_ = null; } if (this.moveSurfaceWrapper_) { - Blockly.unbindEvent_(this.moveSurfaceWrapper_); + Blockly.browserEvents.unbind(this.moveSurfaceWrapper_); this.moveSurfaceWrapper_ = null; } this.gauge_ = null; diff --git a/core/field_colour.js b/core/field_colour.js index 322516019..99c735ed0 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -12,6 +12,7 @@ goog.provide('Blockly.FieldColour'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Events'); @@ -556,16 +557,16 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { } // Configure event handler on the table to listen for any event in a cell. - this.onClickWrapper_ = Blockly.bindEventWithChecks_(table, - 'click', this, this.onClick_, true); - this.onMouseMoveWrapper_ = Blockly.bindEventWithChecks_(table, - 'mousemove', this, this.onMouseMove_, true); - this.onMouseEnterWrapper_ = Blockly.bindEventWithChecks_(table, - 'mouseenter', this, this.onMouseEnter_, true); - this.onMouseLeaveWrapper_ = Blockly.bindEventWithChecks_(table, - 'mouseleave', this, this.onMouseLeave_, true); - this.onKeyDownWrapper_ = Blockly.bindEventWithChecks_(table, - 'keydown', this, this.onKeyDown_); + this.onClickWrapper_ = Blockly.browserEvents.conditionalBind( + table, 'click', this, this.onClick_, true); + this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + table, 'mousemove', this, this.onMouseMove_, true); + this.onMouseEnterWrapper_ = Blockly.browserEvents.conditionalBind( + table, 'mouseenter', this, this.onMouseEnter_, true); + this.onMouseLeaveWrapper_ = Blockly.browserEvents.conditionalBind( + table, 'mouseleave', this, this.onMouseLeave_, true); + this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + table, 'keydown', this, this.onKeyDown_); return table; }; @@ -576,23 +577,23 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { */ Blockly.FieldColour.prototype.dropdownDispose_ = function() { if (this.onClickWrapper_) { - Blockly.unbindEvent_(this.onClickWrapper_); + Blockly.browserEvents.unbind(this.onClickWrapper_); this.onClickWrapper_ = null; } if (this.onMouseMoveWrapper_) { - Blockly.unbindEvent_(this.onMouseMoveWrapper_); + Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); this.onMouseMoveWrapper_ = null; } if (this.onMouseEnterWrapper_) { - Blockly.unbindEvent_(this.onMouseEnterWrapper_); + Blockly.browserEvents.unbind(this.onMouseEnterWrapper_); this.onMouseEnterWrapper_ = null; } if (this.onMouseLeaveWrapper_) { - Blockly.unbindEvent_(this.onMouseLeaveWrapper_); + Blockly.browserEvents.unbind(this.onMouseLeaveWrapper_); this.onMouseLeaveWrapper_ = null; } if (this.onKeyDownWrapper_) { - Blockly.unbindEvent_(this.onKeyDownWrapper_); + Blockly.browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } this.picker_ = null; diff --git a/core/field_textinput.js b/core/field_textinput.js index 186f27f75..9e1cb8d9f 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -12,6 +12,7 @@ goog.provide('Blockly.FieldTextInput'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); @@ -421,13 +422,11 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { */ Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { // Trap Enter without IME and Esc to hide. - this.onKeyDownWrapper_ = - Blockly.bindEventWithChecks_( - htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); + this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); // Resize after every input change. - this.onKeyInputWrapper_ = - Blockly.bindEventWithChecks_( - htmlInput, 'input', this, this.onHtmlInputChange_); + this.onKeyInputWrapper_ = Blockly.browserEvents.conditionalBind( + htmlInput, 'input', this, this.onHtmlInputChange_); }; /** @@ -436,11 +435,11 @@ Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { */ Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() { if (this.onKeyDownWrapper_) { - Blockly.unbindEvent_(this.onKeyDownWrapper_); + Blockly.browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } if (this.onKeyInputWrapper_) { - Blockly.unbindEvent_(this.onKeyInputWrapper_); + Blockly.browserEvents.unbind(this.onKeyInputWrapper_); this.onKeyInputWrapper_ = null; } }; diff --git a/core/flyout_base.js b/core/flyout_base.js index 06dcca4d0..16c0266ad 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -14,6 +14,7 @@ goog.provide('Blockly.Flyout'); goog.require('Blockly.Block'); goog.require('Blockly.blockRendering'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Events.VarCreate'); @@ -272,16 +273,19 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { this.hide(); - Array.prototype.push.apply(this.eventWrappers_, - Blockly.bindEventWithChecks_(this.svgGroup_, 'wheel', this, this.wheel_)); + Array.prototype.push.apply( + this.eventWrappers_, + Blockly.browserEvents.conditionalBind( + this.svgGroup_, 'wheel', this, this.wheel_)); if (!this.autoClose) { this.filterWrapper_ = this.filterForCapacity_.bind(this); this.targetWorkspace.addChangeListener(this.filterWrapper_); } // Dragging the flyout up and down. - Array.prototype.push.apply(this.eventWrappers_, - Blockly.bindEventWithChecks_( + Array.prototype.push.apply( + this.eventWrappers_, + Blockly.browserEvents.conditionalBind( this.svgBackground_, 'mousedown', this, this.onMouseDown_)); // A flyout connected to a workspace doesn't have its own current gesture. @@ -301,7 +305,7 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { */ Blockly.Flyout.prototype.dispose = function() { this.hide(); - Blockly.unbindEvent_(this.eventWrappers_); + Blockly.browserEvents.unbind(this.eventWrappers_); if (this.filterWrapper_) { this.targetWorkspace.removeChangeListener(this.filterWrapper_); this.filterWrapper_ = null; @@ -437,7 +441,7 @@ Blockly.Flyout.prototype.hide = function() { this.setVisible(false); // Delete all the event listeners. for (var i = 0, listen; (listen = this.listeners_[i]); i++) { - Blockly.unbindEvent_(listen); + Blockly.browserEvents.unbind(listen); } this.listeners_.length = 0; if (this.reflowWrapper_) { @@ -482,8 +486,8 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { } }; - this.listeners_.push(Blockly.bindEventWithChecks_(this.svgBackground_, - 'mouseover', this, deselectAll)); + this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.svgBackground_, 'mouseover', this, deselectAll)); if (this.horizontalLayout) { this.height_ = 0; @@ -712,18 +716,18 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { * @protected */ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { - this.listeners_.push(Blockly.bindEventWithChecks_(root, 'mousedown', null, - this.blockMouseDown_(block))); - this.listeners_.push(Blockly.bindEventWithChecks_(rect, 'mousedown', null, - this.blockMouseDown_(block))); - this.listeners_.push(Blockly.bindEvent_(root, 'mouseenter', block, - block.addSelect)); - this.listeners_.push(Blockly.bindEvent_(root, 'mouseleave', block, - block.removeSelect)); - this.listeners_.push(Blockly.bindEvent_(rect, 'mouseenter', block, - block.addSelect)); - this.listeners_.push(Blockly.bindEvent_(rect, 'mouseleave', block, - block.removeSelect)); + this.listeners_.push(Blockly.browserEvents.conditionalBind( + root, 'mousedown', null, this.blockMouseDown_(block))); + this.listeners_.push(Blockly.browserEvents.conditionalBind( + rect, 'mousedown', null, this.blockMouseDown_(block))); + this.listeners_.push( + Blockly.browserEvents.bind(root, 'mouseenter', block, block.addSelect)); + this.listeners_.push(Blockly.browserEvents.bind( + root, 'mouseleave', block, block.removeSelect)); + this.listeners_.push( + Blockly.browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); + this.listeners_.push(Blockly.browserEvents.bind( + rect, 'mouseleave', block, block.removeSelect)); }; /** @@ -825,9 +829,8 @@ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { button.show(); // Clicking on a flyout button or label is a lot like clicking on the // flyout background. - this.listeners_.push( - Blockly.bindEventWithChecks_( - buttonSvg, 'mousedown', this, this.onMouseDown_)); + this.listeners_.push(Blockly.browserEvents.conditionalBind( + buttonSvg, 'mousedown', this, this.onMouseDown_)); this.buttons_.push(button); }; diff --git a/core/flyout_button.js b/core/flyout_button.js index b29341cec..cf996f46d 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -12,6 +12,7 @@ goog.provide('Blockly.FlyoutButton'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); @@ -198,7 +199,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { this.updateTransform_(); - this.onMouseUpWrapper_ = Blockly.bindEventWithChecks_( + this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( this.svgGroup_, 'mouseup', this, this.onMouseUp_); return this.svgGroup_; }; @@ -268,7 +269,7 @@ Blockly.FlyoutButton.prototype.getTargetWorkspace = function() { */ Blockly.FlyoutButton.prototype.dispose = function() { if (this.onMouseUpWrapper_) { - Blockly.unbindEvent_(this.onMouseUpWrapper_); + Blockly.browserEvents.unbind(this.onMouseUpWrapper_); } if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); diff --git a/core/gesture.js b/core/gesture.js index 40e8caa68..edbbba096 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -16,6 +16,7 @@ goog.provide('Blockly.Gesture'); goog.require('Blockly.ASTNode'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.BlockDragger'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.BubbleDragger'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); @@ -239,10 +240,10 @@ Blockly.Gesture.prototype.dispose = function() { this.creatorWorkspace_.clearGesture(); if (this.onMoveWrapper_) { - Blockly.unbindEvent_(this.onMoveWrapper_); + Blockly.browserEvents.unbind(this.onMoveWrapper_); } if (this.onUpWrapper_) { - Blockly.unbindEvent_(this.onUpWrapper_); + Blockly.browserEvents.unbind(this.onUpWrapper_); } if (this.blockDragger_) { @@ -511,9 +512,9 @@ Blockly.Gesture.prototype.doStart = function(e) { * @package */ Blockly.Gesture.prototype.bindMouseEvents = function(e) { - this.onMoveWrapper_ = Blockly.bindEventWithChecks_( + this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this)); - this.onUpWrapper_ = Blockly.bindEventWithChecks_( + this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mouseup', null, this.handleUp.bind(this)); e.preventDefault(); diff --git a/core/icon.js b/core/icon.js index 79357c3c9..5e32a53a6 100644 --- a/core/icon.js +++ b/core/icon.js @@ -12,6 +12,7 @@ goog.provide('Blockly.Icon'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -90,7 +91,7 @@ Blockly.Icon.prototype.createIcon = function() { this.drawIcon_(this.iconGroup_); this.block_.getSvgRoot().appendChild(this.iconGroup_); - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( this.iconGroup_, 'mouseup', this, this.iconClick_); this.updateEditable(); }; diff --git a/core/inject.js b/core/inject.js index 85b7f6405..581e69e32 100644 --- a/core/inject.js +++ b/core/inject.js @@ -13,6 +13,7 @@ goog.provide('Blockly.inject'); goog.require('Blockly.BlockDragSurfaceSvg'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Events'); @@ -339,7 +340,7 @@ Blockly.init_ = function(mainWorkspace) { var svg = mainWorkspace.getParentSvg(); // Suppress the browser's context menu. - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( /** @type {!Element} */ (svg.parentNode), 'contextmenu', null, function(e) { if (!Blockly.utils.isTargetInput(e)) { @@ -347,9 +348,8 @@ Blockly.init_ = function(mainWorkspace) { } }); - var workspaceResizeHandler = Blockly.bindEventWithChecks_(window, 'resize', - null, - function() { + var workspaceResizeHandler = + Blockly.browserEvents.conditionalBind(window, 'resize', null, function() { Blockly.hideChaff(true); Blockly.svgResize(mainWorkspace); }); @@ -408,7 +408,7 @@ Blockly.init_ = function(mainWorkspace) { */ Blockly.inject.bindDocumentEvents_ = function() { if (!Blockly.documentEventsBound_) { - Blockly.bindEventWithChecks_(document, 'scroll', null, function() { + Blockly.browserEvents.conditionalBind(document, 'scroll', null, function() { var workspaces = Blockly.Workspace.getAll(); for (var i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.updateInverseScreenCTM) { @@ -416,15 +416,17 @@ Blockly.inject.bindDocumentEvents_ = function() { } } }); - Blockly.bindEventWithChecks_(document, 'keydown', null, Blockly.onKeyDown); + Blockly.browserEvents.conditionalBind( + document, 'keydown', null, Blockly.onKeyDown); // longStop needs to run to stop the context menu from showing up. It // should run regardless of what other touch event handlers have run. - Blockly.bindEvent_(document, 'touchend', null, Blockly.longStop_); - Blockly.bindEvent_(document, 'touchcancel', null, Blockly.longStop_); + Blockly.browserEvents.bind(document, 'touchend', null, Blockly.longStop_); + Blockly.browserEvents.bind( + document, 'touchcancel', null, Blockly.longStop_); // Some iPad versions don't fire resize after portrait to landscape change. if (Blockly.utils.userAgent.IPAD) { - Blockly.bindEventWithChecks_(window, 'orientationchange', document, - function() { + Blockly.browserEvents.conditionalBind( + window, 'orientationchange', document, function() { // TODO (#397): Fix for multiple Blockly workspaces. Blockly.svgResize(/** @type {!Blockly.WorkspaceSvg} */ (Blockly.getMainWorkspace())); @@ -465,7 +467,7 @@ Blockly.inject.loadSounds_ = function(pathToMedia, workspace) { var soundBinds = []; var unbindSounds = function() { while (soundBinds.length) { - Blockly.unbindEvent_(soundBinds.pop()); + Blockly.browserEvents.unbind(soundBinds.pop()); } audioMgr.preload(); }; @@ -476,10 +478,8 @@ Blockly.inject.loadSounds_ = function(pathToMedia, workspace) { // necessary. // Android ignores any sound not loaded as a result of a user action. - soundBinds.push( - Blockly.bindEventWithChecks_(document, 'mousemove', null, unbindSounds, - true)); - soundBinds.push( - Blockly.bindEventWithChecks_(document, 'touchstart', null, unbindSounds, - true)); + soundBinds.push(Blockly.browserEvents.conditionalBind( + document, 'mousemove', null, unbindSounds, true)); + soundBinds.push(Blockly.browserEvents.conditionalBind( + document, 'touchstart', null, unbindSounds, true)); }; diff --git a/core/menu.js b/core/menu.js index b0470efff..f4b52bd98 100644 --- a/core/menu.js +++ b/core/menu.js @@ -12,6 +12,7 @@ goog.provide('Blockly.Menu'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.utils.aria'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -132,16 +133,16 @@ Blockly.Menu.prototype.render = function(container) { } // Add event handlers. - this.mouseOverHandler_ = Blockly.bindEventWithChecks_(element, - 'mouseover', this, this.handleMouseOver_, true); - this.clickHandler_ = Blockly.bindEventWithChecks_(element, - 'click', this, this.handleClick_, true); - this.mouseEnterHandler_ = Blockly.bindEventWithChecks_(element, - 'mouseenter', this, this.handleMouseEnter_, true); - this.mouseLeaveHandler_ = Blockly.bindEventWithChecks_(element, - 'mouseleave', this, this.handleMouseLeave_, true); - this.onKeyDownHandler_ = Blockly.bindEventWithChecks_(element, - 'keydown', this, this.handleKeyEvent_); + this.mouseOverHandler_ = Blockly.browserEvents.conditionalBind( + element, 'mouseover', this, this.handleMouseOver_, true); + this.clickHandler_ = Blockly.browserEvents.conditionalBind( + element, 'click', this, this.handleClick_, true); + this.mouseEnterHandler_ = Blockly.browserEvents.conditionalBind( + element, 'mouseenter', this, this.handleMouseEnter_, true); + this.mouseLeaveHandler_ = Blockly.browserEvents.conditionalBind( + element, 'mouseleave', this, this.handleMouseLeave_, true); + this.onKeyDownHandler_ = Blockly.browserEvents.conditionalBind( + element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); }; @@ -194,23 +195,23 @@ Blockly.Menu.prototype.setRole = function(roleName) { Blockly.Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { - Blockly.unbindEvent_(this.mouseOverHandler_); + Blockly.browserEvents.unbind(this.mouseOverHandler_); this.mouseOverHandler_ = null; } if (this.clickHandler_) { - Blockly.unbindEvent_(this.clickHandler_); + Blockly.browserEvents.unbind(this.clickHandler_); this.clickHandler_ = null; } if (this.mouseEnterHandler_) { - Blockly.unbindEvent_(this.mouseEnterHandler_); + Blockly.browserEvents.unbind(this.mouseEnterHandler_); this.mouseEnterHandler_ = null; } if (this.mouseLeaveHandler_) { - Blockly.unbindEvent_(this.mouseLeaveHandler_); + Blockly.browserEvents.unbind(this.mouseLeaveHandler_); this.mouseLeaveHandler_ = null; } if (this.onKeyDownHandler_) { - Blockly.unbindEvent_(this.onKeyDownHandler_); + Blockly.browserEvents.unbind(this.onKeyDownHandler_); this.onKeyDownHandler_ = null; } diff --git a/core/scrollbar.js b/core/scrollbar.js index 9aa7dc54a..af6981d38 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -13,6 +13,7 @@ goog.provide('Blockly.Scrollbar'); goog.provide('Blockly.ScrollbarPair'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); @@ -372,10 +373,10 @@ Blockly.Scrollbar = function(workspace, horizontal, opt_pair, opt_class) { this.positionAttribute_ = 'y'; } var scrollbar = this; - this.onMouseDownBarWrapper_ = Blockly.bindEventWithChecks_( + this.onMouseDownBarWrapper_ = Blockly.browserEvents.conditionalBind( this.svgBackground_, 'mousedown', scrollbar, scrollbar.onMouseDownBar_); - this.onMouseDownHandleWrapper_ = Blockly.bindEventWithChecks_(this.svgHandle_, - 'mousedown', scrollbar, scrollbar.onMouseDownHandle_); + this.onMouseDownHandleWrapper_ = Blockly.browserEvents.conditionalBind( + this.svgHandle_, 'mousedown', scrollbar, scrollbar.onMouseDownHandle_); }; /** @@ -479,9 +480,9 @@ Blockly.Scrollbar.metricsAreEquivalent_ = function(first, second) { */ Blockly.Scrollbar.prototype.dispose = function() { this.cleanUp_(); - Blockly.unbindEvent_(this.onMouseDownBarWrapper_); + Blockly.browserEvents.unbind(this.onMouseDownBarWrapper_); this.onMouseDownBarWrapper_ = null; - Blockly.unbindEvent_(this.onMouseDownHandleWrapper_); + Blockly.browserEvents.unbind(this.onMouseDownHandleWrapper_); this.onMouseDownHandleWrapper_ = null; Blockly.utils.dom.removeNode(this.outerSvg_); @@ -897,10 +898,10 @@ Blockly.Scrollbar.prototype.onMouseDownHandle_ = function(e) { // Record the current mouse position. this.startDragMouse_ = this.horizontal_ ? e.clientX : e.clientY; - Blockly.Scrollbar.onMouseUpWrapper_ = Blockly.bindEventWithChecks_(document, - 'mouseup', this, this.onMouseUpHandle_); - Blockly.Scrollbar.onMouseMoveWrapper_ = Blockly.bindEventWithChecks_(document, - 'mousemove', this, this.onMouseMoveHandle_); + Blockly.Scrollbar.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + document, 'mouseup', this, this.onMouseUpHandle_); + Blockly.Scrollbar.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + document, 'mousemove', this, this.onMouseMoveHandle_); e.stopPropagation(); e.preventDefault(); }; @@ -938,11 +939,11 @@ Blockly.Scrollbar.prototype.onMouseUpHandle_ = function() { Blockly.Scrollbar.prototype.cleanUp_ = function() { Blockly.hideChaff(true); if (Blockly.Scrollbar.onMouseUpWrapper_) { - Blockly.unbindEvent_(Blockly.Scrollbar.onMouseUpWrapper_); + Blockly.browserEvents.unbind(Blockly.Scrollbar.onMouseUpWrapper_); Blockly.Scrollbar.onMouseUpWrapper_ = null; } if (Blockly.Scrollbar.onMouseMoveWrapper_) { - Blockly.unbindEvent_(Blockly.Scrollbar.onMouseMoveWrapper_); + Blockly.browserEvents.unbind(Blockly.Scrollbar.onMouseMoveWrapper_); Blockly.Scrollbar.onMouseMoveWrapper_ = null; } }; diff --git a/core/toolbox/toolbox.js b/core/toolbox/toolbox.js index b9ec8b80f..8201812b7 100644 --- a/core/toolbox/toolbox.js +++ b/core/toolbox/toolbox.js @@ -12,6 +12,7 @@ goog.provide('Blockly.Toolbox'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.CollapsibleToolboxCategory'); goog.require('Blockly.constants'); goog.require('Blockly.Css'); @@ -245,13 +246,15 @@ Blockly.Toolbox.prototype.createContentsContainer_ = function() { Blockly.Toolbox.prototype.attachEvents_ = function(container, contentsContainer) { // Clicking on toolbox closes popups. - var clickEvent = Blockly.bindEventWithChecks_(container, 'click', this, - this.onClick_, /* opt_noCaptureIdentifier */ false, + var clickEvent = Blockly.browserEvents.conditionalBind( + container, 'click', this, this.onClick_, + /* opt_noCaptureIdentifier */ false, /* opt_noPreventDefault */ true); this.boundEvents_.push(clickEvent); - var keyDownEvent = Blockly.bindEventWithChecks_(contentsContainer, 'keydown', - this, this.onKeyDown_, /* opt_noCaptureIdentifier */ false, + var keyDownEvent = Blockly.browserEvents.conditionalBind( + contentsContainer, 'keydown', this, this.onKeyDown_, + /* opt_noCaptureIdentifier */ false, /* opt_noPreventDefault */ true); this.boundEvents_.push(keyDownEvent); }; @@ -923,7 +926,7 @@ Blockly.Toolbox.prototype.dispose = function() { } for (var j = 0; j < this.boundEvents_.length; j++) { - Blockly.unbindEvent_(this.boundEvents_[j]); + Blockly.browserEvents.unbind(this.boundEvents_[j]); } this.boundEvents_ = []; this.contents_ = []; diff --git a/core/tooltip.js b/core/tooltip.js index c1acda700..663950879 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -21,6 +21,7 @@ */ goog.provide('Blockly.Tooltip'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.utils.string'); /** @@ -177,10 +178,10 @@ Blockly.Tooltip.createDom = function() { * @param {!Element} element SVG element onto which tooltip is to be bound. */ Blockly.Tooltip.bindMouseEvents = function(element) { - element.mouseOverWrapper_ = Blockly.bindEvent_(element, 'mouseover', null, - Blockly.Tooltip.onMouseOver_); - element.mouseOutWrapper_ = Blockly.bindEvent_(element, 'mouseout', null, - Blockly.Tooltip.onMouseOut_); + element.mouseOverWrapper_ = Blockly.browserEvents.bind( + element, 'mouseover', null, Blockly.Tooltip.onMouseOver_); + element.mouseOutWrapper_ = Blockly.browserEvents.bind( + element, 'mouseout', null, Blockly.Tooltip.onMouseOut_); // Don't use bindEvent_ for mousemove since that would create a // corresponding touch handler, even though this only makes sense in the @@ -196,8 +197,8 @@ Blockly.Tooltip.unbindMouseEvents = function(element) { if (!element) { return; } - Blockly.unbindEvent_(element.mouseOverWrapper_); - Blockly.unbindEvent_(element.mouseOutWrapper_); + Blockly.browserEvents.unbind(element.mouseOverWrapper_); + Blockly.browserEvents.unbind(element.mouseOutWrapper_); element.removeEventListener('mousemove', Blockly.Tooltip.onMouseMove_); }; diff --git a/core/touch_gesture.js b/core/touch_gesture.js index 8f4919ec6..7423ff269 100644 --- a/core/touch_gesture.js +++ b/core/touch_gesture.js @@ -13,6 +13,7 @@ goog.provide('Blockly.TouchGesture'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.Gesture'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); @@ -123,13 +124,13 @@ Blockly.TouchGesture.prototype.doStart = function(e) { * @package */ Blockly.TouchGesture.prototype.bindMouseEvents = function(e) { - this.onStartWrapper_ = Blockly.bindEventWithChecks_( + this.onStartWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousedown', null, this.handleStart.bind(this), /* opt_noCaptureIdentifier */ true); - this.onMoveWrapper_ = Blockly.bindEventWithChecks_( + this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this), /* opt_noCaptureIdentifier */ true); - this.onUpWrapper_ = Blockly.bindEventWithChecks_( + this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mouseup', null, this.handleUp.bind(this), /* opt_noCaptureIdentifier */ true); @@ -218,7 +219,7 @@ Blockly.TouchGesture.prototype.dispose = function() { Blockly.TouchGesture.superClass_.dispose.call(this); if (this.onStartWrapper_) { - Blockly.unbindEvent_(this.onStartWrapper_); + Blockly.browserEvents.unbind(this.onStartWrapper_); } }; diff --git a/core/trashcan.js b/core/trashcan.js index e258794ab..9231eab52 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -12,6 +12,7 @@ goog.provide('Blockly.Trashcan'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.constants'); goog.require('Blockly.Events.TrashcanOpen'); goog.require('Blockly.Scrollbar'); @@ -319,12 +320,12 @@ Blockly.Trashcan.prototype.createDom = function() { // https://groups.google.com/forum/#!topic/blockly/QF4yB9Wx00s // Using bindEventWithChecks_ for blocking mousedown causes issue in mobile. // See #4303 - Blockly.bindEvent_( + Blockly.browserEvents.bind( this.svgGroup_, 'mousedown', this, this.blockMouseDownWhenOpenable_); - Blockly.bindEvent_(this.svgGroup_, 'mouseup', this, this.click); + Blockly.browserEvents.bind(this.svgGroup_, 'mouseup', this, this.click); // Bind to body instead of this.svgGroup_ so that we don't get lid jitters - Blockly.bindEvent_(body, 'mouseover', this, this.mouseOver_); - Blockly.bindEvent_(body, 'mouseout', this, this.mouseOut_); + Blockly.browserEvents.bind(body, 'mouseover', this, this.mouseOver_); + Blockly.browserEvents.bind(body, 'mouseout', this, this.mouseOut_); this.animateLid_(); return this.svgGroup_; }; diff --git a/core/workspace_comment_render_svg.js b/core/workspace_comment_render_svg.js index 9e6aea698..5097f0c92 100644 --- a/core/workspace_comment_render_svg.js +++ b/core/workspace_comment_render_svg.js @@ -109,16 +109,16 @@ Blockly.WorkspaceCommentSvg.prototype.render = function() { this.rendered_ = true; if (this.resizeGroup_) { - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); } if (this.isDeletable()) { - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( this.deleteGroup_, 'mousedown', this, this.deleteMouseDown_); - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( this.deleteGroup_, 'mouseout', this, this.deleteMouseOut_); - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( this.deleteGroup_, 'mouseup', this, this.deleteMouseUp_); } }; @@ -157,14 +157,16 @@ Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() { this.textarea_ = textarea; this.foreignObject_.appendChild(body); // Don't zoom with mousewheel. - Blockly.bindEventWithChecks_(textarea, 'wheel', this, function(e) { + Blockly.browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - Blockly.bindEventWithChecks_(textarea, 'change', this, function( - /* eslint-disable no-unused-vars */ e - /* eslint-enable no-unused-vars */) { - this.setContent(textarea.value); - }); + Blockly.browserEvents.conditionalBind( + textarea, 'change', this, + function( + /* eslint-disable no-unused-vars */ e + /* eslint-enable no-unused-vars */) { + this.setContent(textarea.value); + }); return this.foreignObject_; }; @@ -257,9 +259,9 @@ Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_ = function(e) { this.workspace.startDrag(e, new Blockly.utils.Coordinate( this.workspace.RTL ? -this.width_ : this.width_, this.height_)); - this.onMouseUpWrapper_ = Blockly.bindEventWithChecks_( + this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mouseup', this, this.resizeMouseUp_); - this.onMouseMoveWrapper_ = Blockly.bindEventWithChecks_( + this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousemove', this, this.resizeMouseMove_); Blockly.hideChaff(); // This event has been handled. No need to bubble up to the document. @@ -310,11 +312,11 @@ Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_ = function(e) { */ Blockly.WorkspaceCommentSvg.prototype.unbindDragEvents_ = function() { if (this.onMouseUpWrapper_) { - Blockly.unbindEvent_(this.onMouseUpWrapper_); + Blockly.browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onMouseMoveWrapper_) { - Blockly.unbindEvent_(this.onMouseMoveWrapper_); + Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); this.onMouseMoveWrapper_ = null; } }; diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index fdba3ade5..68e100fc8 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -155,9 +155,9 @@ Blockly.WorkspaceCommentSvg.prototype.initSvg = function(opt_noSelect) { throw TypeError('Workspace is headless.'); } if (!this.workspace.options.readOnly && !this.eventsInit_) { - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( this.svgRectTarget_, 'mousedown', this, this.pathMouseDown_); - Blockly.bindEventWithChecks_( + Blockly.browserEvents.conditionalBind( this.svgHandleTarget_, 'mousedown', this, this.pathMouseDown_); } this.eventsInit_ = true; diff --git a/core/zoom_controls.js b/core/zoom_controls.js index ae26380c9..f7e829e12 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -12,6 +12,7 @@ goog.provide('Blockly.ZoomControls'); +goog.require('Blockly.browserEvents'); goog.require('Blockly.constants'); goog.require('Blockly.Css'); goog.require('Blockly.Scrollbar'); @@ -180,13 +181,13 @@ Blockly.ZoomControls.prototype.dispose = function() { Blockly.utils.dom.removeNode(this.svgGroup_); } if (this.onZoomResetWrapper_) { - Blockly.unbindEvent_(this.onZoomResetWrapper_); + Blockly.browserEvents.unbind(this.onZoomResetWrapper_); } if (this.onZoomInWrapper_) { - Blockly.unbindEvent_(this.onZoomInWrapper_); + Blockly.browserEvents.unbind(this.onZoomInWrapper_); } if (this.onZoomOutWrapper_) { - Blockly.unbindEvent_(this.onZoomOutWrapper_); + Blockly.browserEvents.unbind(this.onZoomOutWrapper_); } }; @@ -279,7 +280,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.workspace_.options.pathToMedia + Blockly.SPRITE.url); // Attach listener. - this.onZoomOutWrapper_ = Blockly.bindEventWithChecks_( + this.onZoomOutWrapper_ = Blockly.browserEvents.conditionalBind( this.zoomOutGroup_, 'mousedown', null, this.zoom_.bind(this, -1)); }; @@ -330,7 +331,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.workspace_.options.pathToMedia + Blockly.SPRITE.url); // Attach listener. - this.onZoomInWrapper_ = Blockly.bindEventWithChecks_( + this.onZoomInWrapper_ = Blockly.browserEvents.conditionalBind( this.zoomInGroup_, 'mousedown', null, this.zoom_.bind(this, 1)); }; @@ -397,7 +398,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.workspace_.options.pathToMedia + Blockly.SPRITE.url); // Attach event listeners. - this.onZoomResetWrapper_ = Blockly.bindEventWithChecks_( + this.onZoomResetWrapper_ = Blockly.browserEvents.conditionalBind( this.zoomResetGroup_, 'mousedown', null, this.resetZoom_.bind(this)); }; diff --git a/demos/custom-fields/pitch/field_pitch.js b/demos/custom-fields/pitch/field_pitch.js index df718c03e..d36bc3ee8 100644 --- a/demos/custom-fields/pitch/field_pitch.js +++ b/demos/custom-fields/pitch/field_pitch.js @@ -88,11 +88,9 @@ CustomFields.FieldPitch.prototype.showEditor_ = function() { // change this behaviour. For now, using bindEvent_ instead of // bindEventWithChecks_ allows it to work without a mousedown/touchstart. this.clickWrapper_ = - Blockly.bindEvent_(this.imageElement_, 'click', this, - this.hide_); - this.moveWrapper_ = - Blockly.bindEvent_(this.imageElement_, 'mousemove', this, - this.onMouseMove); + Blockly.browserEvents.bind(this.imageElement_, 'click', this, this.hide_); + this.moveWrapper_ = Blockly.browserEvents.bind( + this.imageElement_, 'mousemove', this, this.onMouseMove); this.updateGraph_(); }; @@ -115,11 +113,11 @@ CustomFields.FieldPitch.prototype.dropdownCreate_ = function() { */ CustomFields.FieldPitch.prototype.dropdownDispose_ = function() { if (this.clickWrapper_) { - Blockly.unbindEvent_(this.clickWrapper_); + Blockly.browserEvents.unbind(this.clickWrapper_); this.clickWrapper_ = null; } if (this.moveWrapper_) { - Blockly.unbindEvent_(this.moveWrapper_); + Blockly.browserEvents.unbind(this.moveWrapper_); this.moveWrapper_ = null; } this.imageElement_ = null; diff --git a/demos/custom-fields/turtle/field_turtle.js b/demos/custom-fields/turtle/field_turtle.js index f790b1d1b..bb555001a 100644 --- a/demos/custom-fields/turtle/field_turtle.js +++ b/demos/custom-fields/turtle/field_turtle.js @@ -404,47 +404,53 @@ CustomFields.FieldTurtle.prototype.dropdownCreate_ = function() { var leftArrow = createLeftArrow(row); widget.patternText = createTextNode(row, this.displayValue_.pattern); var rightArrow = createRightArrow(row); - this.editorListeners_.push(Blockly.bindEvent_(leftArrow, 'mouseup', this, + this.editorListeners_.push(Blockly.browserEvents.bind( + leftArrow, 'mouseup', this, createArrowListener('pattern', CustomFields.FieldTurtle.PATTERNS, -1))); - this.editorListeners_.push(Blockly.bindEvent_(rightArrow, 'mouseup', this, + this.editorListeners_.push(Blockly.browserEvents.bind( + rightArrow, 'mouseup', this, createArrowListener('pattern', CustomFields.FieldTurtle.PATTERNS, 1))); row = createRow(table); leftArrow = createLeftArrow(row); widget.hatText = createTextNode(row, this.displayValue_.hat); rightArrow = createRightArrow(row); - this.editorListeners_.push(Blockly.bindEvent_(leftArrow, 'mouseup', this, + this.editorListeners_.push(Blockly.browserEvents.bind( + leftArrow, 'mouseup', this, createArrowListener('hat', CustomFields.FieldTurtle.HATS, -1))); - this.editorListeners_.push(Blockly.bindEvent_(rightArrow, 'mouseup', this, + this.editorListeners_.push(Blockly.browserEvents.bind( + rightArrow, 'mouseup', this, createArrowListener('hat', CustomFields.FieldTurtle.HATS, 1))); row = createRow(table); leftArrow = createLeftArrow(row); widget.turtleNameText = createTextNode(row, this.displayValue_.turtleName); rightArrow = createRightArrow(row); - this.editorListeners_.push(Blockly.bindEvent_(leftArrow, 'mouseup', this, + this.editorListeners_.push(Blockly.browserEvents.bind( + leftArrow, 'mouseup', this, createArrowListener('turtleName', CustomFields.FieldTurtle.NAMES, -1))); - this.editorListeners_.push(Blockly.bindEvent_(rightArrow, 'mouseup', this, + this.editorListeners_.push(Blockly.browserEvents.bind( + rightArrow, 'mouseup', this, createArrowListener('turtleName', CustomFields.FieldTurtle.NAMES, 1))); var randomizeButton = document.createElement('button'); randomizeButton.className = 'randomize'; randomizeButton.setAttribute('type', 'button'); randomizeButton.textContent = 'randomize turtle'; - this.editorListeners_.push(Blockly.bindEvent_(randomizeButton, 'mouseup', this, - function() { - var value = {}; - value.pattern = CustomFields.FieldTurtle.PATTERNS[ - Math.floor(Math.random() * CustomFields.FieldTurtle.PATTERNS.length)]; + this.editorListeners_.push( + Blockly.browserEvents.bind(randomizeButton, 'mouseup', this, function() { + var value = {}; + value.pattern = CustomFields.FieldTurtle.PATTERNS[Math.floor( + Math.random() * CustomFields.FieldTurtle.PATTERNS.length)]; - value.hat = CustomFields.FieldTurtle.HATS[ - Math.floor(Math.random() * CustomFields.FieldTurtle.HATS.length)]; + value.hat = CustomFields.FieldTurtle.HATS[Math.floor( + Math.random() * CustomFields.FieldTurtle.HATS.length)]; - value.turtleName = CustomFields.FieldTurtle.NAMES[ - Math.floor(Math.random() * CustomFields.FieldTurtle.NAMES.length)]; + value.turtleName = CustomFields.FieldTurtle.NAMES[Math.floor( + Math.random() * CustomFields.FieldTurtle.NAMES.length)]; - this.setValue(value); - })); + this.setValue(value); + })); widget.appendChild(randomizeButton); return widget; @@ -454,7 +460,7 @@ CustomFields.FieldTurtle.prototype.dropdownCreate_ = function() { CustomFields.FieldTurtle.prototype.dropdownDispose_ = function() { for (var i = this.editorListeners_.length, listener; listener = this.editorListeners_[i]; i--) { - Blockly.unbindEvent_(listener); + Blockly.browserEvents.unbind(listener); this.editorListeners_.pop(); } }; diff --git a/demos/minimap/minimap.js b/demos/minimap/minimap.js index 6217b4df3..29ccf8ea7 100644 --- a/demos/minimap/minimap.js +++ b/demos/minimap/minimap.js @@ -91,8 +91,9 @@ Minimap.init = function(workspace, minimap) { this.mapDragger = this.svg.childNodes[0]; // Adding mouse events to the rectangle, to make it Draggable. - // Using Blockly.bindEvent_ to attach mouse/touch listeners. - Blockly.bindEvent_(this.mapDragger, 'mousedown', null, Minimap.mousedown); + // Using Blockly.browserEvents.bind to attach mouse/touch listeners. + Blockly.browserEvents.bind( + this.mapDragger, 'mousedown', null, Minimap.mousedown); //When the window change, we need to resize the minimap window. window.addEventListener('resize', Minimap.repositionMinimap); @@ -105,11 +106,11 @@ Minimap.init = function(workspace, minimap) { }; Minimap.mousedown = function(e) { - // Using Blockly.bindEvent_ to attach mouse/touch listeners. - Minimap.mouseMoveBindData = - Blockly.bindEvent_(document, 'mousemove', null, Minimap.mousemove); + // Using Blockly.browserEvents.bind to attach mouse/touch listeners. + Minimap.mouseMoveBindData = Blockly.browserEvents.bind( + document, 'mousemove', null, Minimap.mousemove); Minimap.mouseUpBindData = - Blockly.bindEvent_(document, 'mouseup', null, Minimap.mouseup); + Blockly.browserEvents.bind(document, 'mouseup', null, Minimap.mouseup); Minimap.isDragging = true; e.stopPropagation(); @@ -118,8 +119,8 @@ Minimap.mousedown = function(e) { Minimap.mouseup = function(e) { Minimap.isDragging = false; // Removing listeners. - Blockly.unbindEvent_(Minimap.mouseUpBindData); - Blockly.unbindEvent_(Minimap.mouseMoveBindData); + Blockly.browserEvents.unbind(Minimap.mouseUpBindData); + Blockly.browserEvents.unbind(Minimap.mouseMoveBindData); Minimap.updateMapDragger(e); e.stopPropagation(); };