Merge pull request #4642 from rachel-fenichel/event_data_type

Move bind/unbind events functions to new file, with example usage.
This commit is contained in:
Rachel Fenichel
2021-02-25 12:00:22 -08:00
committed by GitHub
28 changed files with 467 additions and 397 deletions

View File

@@ -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;

View File

@@ -17,6 +17,7 @@
goog.provide('Blockly');
goog.require('Blockly.constants');
goog.require('Blockly.browserEvents');
goog.require('Blockly.Events');
goog.require('Blockly.Events.Ui');
goog.require('Blockly.Events.UiBase');
@@ -104,13 +105,6 @@ Blockly.cache3dSupported_ = null;
*/
Blockly.parentContainer = null;
/**
* Blockly opaque event data used to unbind events when using
* `Blockly.bindEvent_` and `Blockly.bindEventWithChecks_`.
* @typedef {!Array.<!Array>}
*/
Blockly.EventData;
/**
* Returns the dimensions of the specified SVG image.
* @param {!SVGElement} svg SVG image.
@@ -388,149 +382,6 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) {
}
};
/**
* Bind an event to a function call. When calling the function, verifies that
* it belongs to the touch stream that is currently being processed, and splits
* multitouch events into multiple events as needed.
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
* @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. False by default.
* @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 {!Blockly.EventData} Opaque data that can be passed to unbindEvent_.
*/
Blockly.bindEventWithChecks_ = function(node, name, thisObject, func,
opt_noCaptureIdentifier, opt_noPreventDefault) {
var handled = false;
var wrapFunc = function(e) {
var captureIdentifier = !opt_noCaptureIdentifier;
// Handle each touch point separately. If the event was a mouse event, this
// will hand back an array with one element, which we're fine handling.
var events = Blockly.Touch.splitEventByTouches(e);
for (var i = 0, event; (event = events[i]); i++) {
if (captureIdentifier && !Blockly.Touch.shouldHandleEvent(event)) {
continue;
}
Blockly.Touch.setClientFromTouch(event);
if (thisObject) {
func.call(thisObject, event);
} else {
func(event);
}
handled = true;
}
};
var bindData = [];
if (Blockly.utils.global['PointerEvent'] &&
(name in Blockly.Touch.TOUCH_MAP)) {
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, wrapFunc, false);
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
bindData.push([node, name, wrapFunc]);
// Add equivalent touch event.
if (name in Blockly.Touch.TOUCH_MAP) {
var touchWrapFunc = function(e) {
wrapFunc(e);
// Calling preventDefault stops the browser from scrolling/zooming the
// page.
var preventDef = !opt_noPreventDefault;
if (handled && preventDef) {
e.preventDefault();
}
};
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, touchWrapFunc, false);
bindData.push([node, type, touchWrapFunc]);
}
}
}
return bindData;
};
/**
* Bind an event to a function call. Handles multitouch events by using the
* coordinates of the first changed touch, and doesn't do any safety checks for
* simultaneous event processing. In most cases prefer is to use
* `Blockly.bindEventWithChecks_`.
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
* @return {!Blockly.EventData} Opaque data that can be passed to unbindEvent_.
*/
Blockly.bindEvent_ = function(node, name, thisObject, func) {
var wrapFunc = function(e) {
if (thisObject) {
func.call(thisObject, e);
} else {
func(e);
}
};
var bindData = [];
if (Blockly.utils.global['PointerEvent'] &&
(name in Blockly.Touch.TOUCH_MAP)) {
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, wrapFunc, false);
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
bindData.push([node, name, wrapFunc]);
// Add equivalent touch event.
if (name in Blockly.Touch.TOUCH_MAP) {
var touchWrapFunc = function(e) {
// Punt on multitouch events.
if (e.changedTouches && e.changedTouches.length == 1) {
// Map the touch event's properties to the event.
var touchPoint = e.changedTouches[0];
e.clientX = touchPoint.clientX;
e.clientY = touchPoint.clientY;
}
wrapFunc(e);
// Stop the browser from scrolling/zooming the page.
e.preventDefault();
};
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, touchWrapFunc, false);
bindData.push([node, type, touchWrapFunc]);
}
}
}
return bindData;
};
/**
* Unbind one or more events event from a function call.
* @param {!Array.<!Array>} bindData Opaque data from bindEvent_.
* This list is emptied during the course of calling this function.
* @return {!Function} The function call.
*/
Blockly.unbindEvent_ = function(bindData) {
while (bindData.length) {
var bindDatum = bindData.pop();
var node = bindDatum[0];
var name = bindDatum[1];
var func = bindDatum[2];
node.removeEventListener(name, func, false);
}
return func;
};
/**
* Is the given string a number (includes negative and decimals).
* @param {string} str Input string.
@@ -632,3 +483,20 @@ Blockly.checkBlockColourConstant_ = function(
Blockly.setParentContainer = function(container) {
Blockly.parentContainer = container;
};
/** Aliases. */
/**
* @see Blockly.browserEvents.bind
*/
Blockly.bindEvent_ = Blockly.browserEvents.bind;
/**
* @see Blockly.browserEvents.unbind
*/
Blockly.unbindEvent_ = Blockly.browserEvents.unbind;
/**
* @see Blockly.browserEvents.conditionalBind
*/
Blockly.bindEventWithChecks_ = Blockly.browserEvents.conditionalBind;

174
core/browser_events.js Normal file
View File

@@ -0,0 +1,174 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Browser event handling.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.browserEvents');
goog.require('Blockly.Touch');
/**
* Blockly opaque event data used to unbind events when using
* `Blockly.browserEvents.bind` and
* `Blockly.browserEvents.conditionalBind`.
* @typedef {!Array.<!Array>}
*/
Blockly.browserEvents.Data;
/**
* Bind an event handler that can be ignored if it is not part of the active
* touch stream.
* Use this for events that either start or continue a multi-part gesture (e.g.
* mousedown or mousemove, which may be part of a drag or click).
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
* @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. False by default.
* @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 {!Blockly.browserEvents.Data} Opaque data that can be passed to
* unbindEvent_.
* @public
*/
Blockly.browserEvents.conditionalBind = function(
node, name, thisObject, func, opt_noCaptureIdentifier,
opt_noPreventDefault) {
var handled = false;
var wrapFunc = function(e) {
var captureIdentifier = !opt_noCaptureIdentifier;
// Handle each touch point separately. If the event was a mouse event, this
// will hand back an array with one element, which we're fine handling.
var events = Blockly.Touch.splitEventByTouches(e);
for (var i = 0, event; (event = events[i]); i++) {
if (captureIdentifier && !Blockly.Touch.shouldHandleEvent(event)) {
continue;
}
Blockly.Touch.setClientFromTouch(event);
if (thisObject) {
func.call(thisObject, event);
} else {
func(event);
}
handled = true;
}
};
var bindData = [];
if (Blockly.utils.global['PointerEvent'] &&
(name in Blockly.Touch.TOUCH_MAP)) {
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, wrapFunc, false);
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
bindData.push([node, name, wrapFunc]);
// Add equivalent touch event.
if (name in Blockly.Touch.TOUCH_MAP) {
var touchWrapFunc = function(e) {
wrapFunc(e);
// Calling preventDefault stops the browser from scrolling/zooming the
// page.
var preventDef = !opt_noPreventDefault;
if (handled && preventDef) {
e.preventDefault();
}
};
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, touchWrapFunc, false);
bindData.push([node, type, touchWrapFunc]);
}
}
}
return bindData;
};
/**
* Bind an event handler that should be called regardless of whether it is part
* of the active touch stream.
* Use this for events that are not part of a multi-part gesture (e.g.
* mouseover for tooltips).
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
* @return {!Blockly.browserEvents.Data} Opaque data that can be passed to
* unbindEvent_.
* @public
*/
Blockly.browserEvents.bind = function(node, name, thisObject, func) {
var wrapFunc = function(e) {
if (thisObject) {
func.call(thisObject, e);
} else {
func(e);
}
};
var bindData = [];
if (Blockly.utils.global['PointerEvent'] &&
(name in Blockly.Touch.TOUCH_MAP)) {
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, wrapFunc, false);
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
bindData.push([node, name, wrapFunc]);
// Add equivalent touch event.
if (name in Blockly.Touch.TOUCH_MAP) {
var touchWrapFunc = function(e) {
// Punt on multitouch events.
if (e.changedTouches && e.changedTouches.length == 1) {
// Map the touch event's properties to the event.
var touchPoint = e.changedTouches[0];
e.clientX = touchPoint.clientX;
e.clientY = touchPoint.clientY;
}
wrapFunc(e);
// Stop the browser from scrolling/zooming the page.
e.preventDefault();
};
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, touchWrapFunc, false);
bindData.push([node, type, touchWrapFunc]);
}
}
}
return bindData;
};
/**
* Unbind one or more events event from a function call.
* @param {!Blockly.browserEvents.Data} bindData Opaque data from bindEvent_.
* This list is emptied during the course of calling this function.
* @return {!Function} The function call.
* @public
*/
Blockly.browserEvents.unbind = function(bindData) {
while (bindData.length) {
var bindDatum = bindData.pop();
var node = bindDatum[0];
var name = bindDatum[1];
var func = bindDatum[2];
node.removeEventListener(name, func, false);
}
return func;
};

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.Bubble');
goog.require('Blockly.browserEvents');
goog.require('Blockly.Scrollbar');
goog.require('Blockly.Touch');
goog.require('Blockly.utils');
@@ -66,14 +67,14 @@ Blockly.Bubble = function(
/**
* Mouse down on bubbleBack_ event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseDownBubbleWrapper_ = null;
/**
* Mouse down on resizeGroup_ event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseDownResizeWrapper_ = null;
@@ -137,14 +138,14 @@ Blockly.Bubble.ANCHOR_RADIUS = 8;
/**
* Mouse up event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
Blockly.Bubble.onMouseUpWrapper_ = null;
/**
* Mouse move event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
Blockly.Bubble.onMouseMoveWrapper_ = null;
@@ -155,11 +156,11 @@ Blockly.Bubble.onMouseMoveWrapper_ = null;
*/
Blockly.Bubble.unbindDragEvents_ = function() {
if (Blockly.Bubble.onMouseUpWrapper_) {
Blockly.unbindEvent_(Blockly.Bubble.onMouseUpWrapper_);
Blockly.browserEvents.unbind(Blockly.Bubble.onMouseUpWrapper_);
Blockly.Bubble.onMouseUpWrapper_ = null;
}
if (Blockly.Bubble.onMouseMoveWrapper_) {
Blockly.unbindEvent_(Blockly.Bubble.onMouseMoveWrapper_);
Blockly.browserEvents.unbind(Blockly.Bubble.onMouseMoveWrapper_);
Blockly.Bubble.onMouseMoveWrapper_ = null;
}
};
@@ -299,10 +300,10 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) {
}
if (!this.workspace_.options.readOnly) {
this.onMouseDownBubbleWrapper_ = Blockly.bindEventWithChecks_(
this.onMouseDownBubbleWrapper_ = Blockly.browserEvents.conditionalBind(
this.bubbleBack_, 'mousedown', this, this.bubbleMouseDown_);
if (this.resizeGroup_) {
this.onMouseDownResizeWrapper_ = Blockly.bindEventWithChecks_(
this.onMouseDownResizeWrapper_ = Blockly.browserEvents.conditionalBind(
this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_);
}
}
@@ -387,9 +388,9 @@ Blockly.Bubble.prototype.resizeMouseDown_ = function(e) {
new Blockly.utils.Coordinate(
this.workspace_.RTL ? -this.width_ : this.width_, this.height_));
Blockly.Bubble.onMouseUpWrapper_ = Blockly.bindEventWithChecks_(
Blockly.Bubble.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind(
document, 'mouseup', this, Blockly.Bubble.bubbleMouseUp_);
Blockly.Bubble.onMouseMoveWrapper_ = Blockly.bindEventWithChecks_(
Blockly.Bubble.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind(
document, 'mousemove', this, this.resizeMouseMove_);
Blockly.hideChaff();
// This event has been handled. No need to bubble up to the document.
@@ -821,10 +822,10 @@ Blockly.Bubble.prototype.setColour = function(hexColour) {
*/
Blockly.Bubble.prototype.dispose = function() {
if (this.onMouseDownBubbleWrapper_) {
Blockly.unbindEvent_(this.onMouseDownBubbleWrapper_);
Blockly.browserEvents.unbind(this.onMouseDownBubbleWrapper_);
}
if (this.onMouseDownResizeWrapper_) {
Blockly.unbindEvent_(this.onMouseDownResizeWrapper_);
Blockly.browserEvents.unbind(this.onMouseDownResizeWrapper_);
}
Blockly.Bubble.unbindDragEvents_();
Blockly.utils.dom.removeNode(this.bubbleGroup_);

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.Comment');
goog.require('Blockly.browserEvents');
goog.require('Blockly.Bubble');
goog.require('Blockly.Css');
goog.require('Blockly.Events');
@@ -61,28 +62,28 @@ Blockly.Comment = function(block) {
/**
* Mouse up event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseUpWrapper_ = null;
/**
* Wheel event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onWheelWrapper_ = null;
/**
* Change event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onChangeWrapper_ = null;
/**
* Input event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onInputWrapper_ = null;
@@ -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();

View File

@@ -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();
};

View File

@@ -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');
@@ -131,7 +132,7 @@ Blockly.Field = function(value, opt_validator, opt_config) {
/**
* Mouse down event listener data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.mouseDownWrapper_ = null;
@@ -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_);

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.FieldAngle');
goog.require('Blockly.browserEvents');
goog.require('Blockly.Css');
goog.require('Blockly.DropDownDiv');
goog.require('Blockly.fieldRegistry');
@@ -88,21 +89,21 @@ Blockly.FieldAngle = function(opt_value, opt_validator, opt_config) {
/**
* Wrapper click event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.clickWrapper_ = null;
/**
* Surface click event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.clickSurfaceWrapper_ = null;
/**
* Surface mouse move event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.moveSurfaceWrapper_ = null;
@@ -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;

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.FieldColour');
goog.require('Blockly.browserEvents');
goog.require('Blockly.Css');
goog.require('Blockly.DropDownDiv');
goog.require('Blockly.Events');
@@ -61,35 +62,35 @@ Blockly.FieldColour = function(opt_value, opt_validator, opt_config) {
/**
* Mouse click event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onClickWrapper_ = null;
/**
* Mouse move event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseMoveWrapper_ = null;
/**
* Mouse enter event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseEnterWrapper_ = null;
/**
* Mouse leave event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseLeaveWrapper_ = null;
/**
* Key down event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onKeyDownWrapper_ = null;
@@ -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;

View File

@@ -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');
@@ -62,14 +63,14 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) {
/**
* Key down event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onKeyDownWrapper_ = null;
/**
* Key input event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onKeyInputWrapper_ = null;
@@ -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;
}
};

View File

@@ -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);
};

View File

@@ -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');
@@ -85,7 +86,7 @@ Blockly.FlyoutButton = function(workspace, targetWorkspace, json, isLabel) {
/**
* Mouse up event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseUpWrapper_ = null;
@@ -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_);

View File

@@ -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');
@@ -156,7 +157,7 @@ Blockly.Gesture = function(e, creatorWorkspace) {
/**
* A handle to use to unbind a mouse move listener at the end of a drag.
* Opaque data returned from Blockly.bindEventWithChecks_.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @protected
*/
this.onMoveWrapper_ = null;
@@ -164,7 +165,7 @@ Blockly.Gesture = function(e, creatorWorkspace) {
/**
* A handle to use to unbind a mouse up listener at the end of a drag.
* Opaque data returned from Blockly.bindEventWithChecks_.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @protected
*/
this.onUpWrapper_ = null;
@@ -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();

View File

@@ -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();
};

View File

@@ -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));
};

View File

@@ -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');
@@ -55,35 +56,35 @@ Blockly.Menu = function() {
/**
* Mouse over event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.mouseOverHandler_ = null;
/**
* Click event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.clickHandler_ = null;
/**
* Mouse enter event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.mouseEnterHandler_ = null;
/**
* Mouse leave event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.mouseLeaveHandler_ = null;
/**
* Key down event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onKeyDownHandler_ = null;
@@ -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;
}

View File

@@ -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');
@@ -399,10 +400,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_);
};
/**
@@ -516,9 +517,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_);
@@ -1013,10 +1014,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();
};
@@ -1054,11 +1055,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;
}
};

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.Toolbox');
goog.require('Blockly.browserEvents');
goog.require('Blockly.CollapsibleToolboxCategory');
goog.require('Blockly.constants');
goog.require('Blockly.Css');
@@ -148,7 +149,7 @@ Blockly.Toolbox = function(workspace) {
* Array holding info needed to unbind event handlers.
* Used for disposing.
* Ex: [[node, name, func], [node, name, func]].
* @type {!Array<!Blockly.EventData>}
* @type {!Array<!Blockly.browserEvents.Data>}
* @protected
*/
this.boundEvents_ = [];
@@ -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_ = [];

View File

@@ -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_);
};

View File

@@ -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');
@@ -72,7 +73,7 @@ Blockly.TouchGesture = function(e, creatorWorkspace) {
* A handle to use to unbind the second touch start or pointer down listener
* at the end of a drag.
* Opaque data returned from Blockly.bindEventWithChecks_.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onStartWrapper_ = null;
@@ -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_);
}
};

View File

@@ -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_;
};

View File

@@ -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;
}
};

View File

@@ -48,14 +48,14 @@ Blockly.WorkspaceCommentSvg = function(
workspace, content, height, width, opt_id) {
/**
* Mouse up event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseUpWrapper_ = null;
/**
* Mouse move event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onMouseMoveWrapper_ = null;
@@ -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;

View File

@@ -17,6 +17,7 @@ goog.require('Blockly.blockRendering');
goog.require('Blockly.ConnectionDB');
goog.require('Blockly.constants');
goog.require('Blockly.ContextMenuRegistry');
goog.require('Blockly.browserEvents');
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockCreate');
goog.require('Blockly.Events.ThemeChange');
@@ -221,8 +222,8 @@ Blockly.utils.object.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);
/**
* A wrapper function called when a resize event occurs.
* You can pass the result to `unbindEvent_`.
* @type {Array.<!Array>}
* You can pass the result to `eventHandling.unbind`.
* @type {?Blockly.browserEvents.Data}
* @private
*/
Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null;
@@ -753,7 +754,8 @@ Blockly.WorkspaceSvg.prototype.getBlockCanvas = function() {
/**
* Save resize handler data so we can delete it later in dispose.
* @param {!Array.<!Array>} handler Data that can be passed to unbindEvent_.
* @param {!Blockly.browserEvents.Data} handler Data that can be passed to
* eventHandling.unbind.
*/
Blockly.WorkspaceSvg.prototype.setResizeHandlerWrapper = function(handler) {
this.resizeHandlerWrapper_ = handler;
@@ -807,10 +809,10 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
{'class': 'blocklyBubbleCanvas'}, this.svgGroup_);
if (!this.isFlyout) {
Blockly.bindEventWithChecks_(this.svgGroup_, 'mousedown', this,
this.onMouseDown_, false, true);
Blockly.bindEventWithChecks_(this.svgGroup_, 'wheel', this,
this.onMouseWheel_);
Blockly.browserEvents.conditionalBind(
this.svgGroup_, 'mousedown', this, this.onMouseDown_, false, true);
Blockly.browserEvents.conditionalBind(
this.svgGroup_, 'wheel', this, this.onMouseWheel_);
}
// Determine if there needs to be a category tree, or a simple list of
@@ -917,7 +919,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
}
}
if (this.resizeHandlerWrapper_) {
Blockly.unbindEvent_(this.resizeHandlerWrapper_);
Blockly.browserEvents.unbind(this.resizeHandlerWrapper_);
this.resizeHandlerWrapper_ = null;
}
};

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.ZoomControls');
goog.require('Blockly.browserEvents');
goog.require('Blockly.constants');
goog.require('Blockly.Css');
goog.require('Blockly.Scrollbar');
@@ -36,7 +37,7 @@ Blockly.ZoomControls = function(workspace) {
/**
* A handle to use to unbind the mouse down event handler for zoom reset
* button. Opaque data returned from Blockly.bindEventWithChecks_.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onZoomResetWrapper_ = null;
@@ -44,7 +45,7 @@ Blockly.ZoomControls = function(workspace) {
/**
* A handle to use to unbind the mouse down event handler for zoom in button.
* Opaque data returned from Blockly.bindEventWithChecks_.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onZoomInWrapper_ = null;
@@ -52,7 +53,7 @@ Blockly.ZoomControls = function(workspace) {
/**
* A handle to use to unbind the mouse down event handler for zoom out button.
* Opaque data returned from Blockly.bindEventWithChecks_.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.onZoomOutWrapper_ = null;
@@ -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));
};

View File

@@ -31,14 +31,14 @@ CustomFields.FieldPitch = function(text) {
/**
* Click event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.clickWrapper_ = null;
/**
* Move event data.
* @type {?Blockly.EventData}
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.moveWrapper_ = null;
@@ -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;

View File

@@ -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();
}
};

View File

@@ -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();
};