From 2a00055e5743b8a334aec67586bec5e3e0ae296d Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 14 Feb 2018 10:42:27 -0800 Subject: [PATCH 1/3] Don't register mouse events if pointer events are supported --- core/blockly.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 427d45199..892ee152e 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -450,10 +450,14 @@ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func, } }; - node.addEventListener(name, wrapFunc, false); - var bindData = [[node, name, wrapFunc]]; + var bindData = []; + // Don't register the mouse event if an equivalent pointer event is supported. + if (!window.PointerEvent || !(name in Blockly.Touch.TOUCH_MAP)) { + node.addEventListener(name, wrapFunc, false); + bindData.push([node, name, wrapFunc]); + } - // Add equivalent touch event. + // Add equivalent touch or pointer event. if (name in Blockly.Touch.TOUCH_MAP) { var touchWrapFunc = function(e) { wrapFunc(e); @@ -495,10 +499,13 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) { } }; - node.addEventListener(name, wrapFunc, false); - var bindData = [[node, name, wrapFunc]]; - - // Add equivalent touch event. + var bindData = []; + // Don't register the mouse event if an equivalent pointer event is supported. + if (!window.PointerEvent || !(name in Blockly.Touch.TOUCH_MAP)) { + node.addEventListener(name, wrapFunc, false); + bindData.push([node, name, wrapFunc]); + } + // Add equivalent touch or pointer event. if (name in Blockly.Touch.TOUCH_MAP) { var touchWrapFunc = function(e) { // Punt on multitouch events. From e5a2ef30f2bf06833b3b336a3a1919aa54ba49d5 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 15 Feb 2018 11:26:06 -0800 Subject: [PATCH 2/3] Switch to goog.events.BrowserFeature.POINTER_EVENTS --- core/blockly.js | 8 ++++++-- core/touch.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 892ee152e..d4a7a094b 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -53,7 +53,9 @@ goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.constants'); goog.require('Blockly.inject'); goog.require('Blockly.utils'); + goog.require('goog.color'); +goog.require('goog.events.BrowserFeature'); goog.require('goog.userAgent'); @@ -452,7 +454,8 @@ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func, var bindData = []; // Don't register the mouse event if an equivalent pointer event is supported. - if (!window.PointerEvent || !(name in Blockly.Touch.TOUCH_MAP)) { + if (!goog.events.BrowserFeature.POINTER_EVENTS || + !(name in Blockly.Touch.TOUCH_MAP)) { node.addEventListener(name, wrapFunc, false); bindData.push([node, name, wrapFunc]); } @@ -501,7 +504,8 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) { var bindData = []; // Don't register the mouse event if an equivalent pointer event is supported. - if (!window.PointerEvent || !(name in Blockly.Touch.TOUCH_MAP)) { + if (!goog.events.BrowserFeature.POINTER_EVENTS || + !(name in Blockly.Touch.TOUCH_MAP)) { node.addEventListener(name, wrapFunc, false); bindData.push([node, name, wrapFunc]); } diff --git a/core/touch.js b/core/touch.js index 8aad46b08..7a883c241 100644 --- a/core/touch.js +++ b/core/touch.js @@ -48,7 +48,7 @@ Blockly.Touch.touchIdentifier_ = null; * @type {Object} */ Blockly.Touch.TOUCH_MAP = {}; -if (window.PointerEvent) { +if (goog.events.BrowserFeature.POINTER_EVENTS) { Blockly.Touch.TOUCH_MAP = { 'mousedown': ['pointerdown'], 'mousemove': ['pointermove'], From 8c8412af74025bd1a9d86e16bde264d9911afe20 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Feb 2018 15:01:13 -0800 Subject: [PATCH 3/3] Just check whether the window exists, instead of using goog.events.BroswerFeature --- core/blockly.js | 7 ++----- core/touch.js | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index d4a7a094b..3aa2cf908 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -55,7 +55,6 @@ goog.require('Blockly.inject'); goog.require('Blockly.utils'); goog.require('goog.color'); -goog.require('goog.events.BrowserFeature'); goog.require('goog.userAgent'); @@ -454,8 +453,7 @@ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func, var bindData = []; // Don't register the mouse event if an equivalent pointer event is supported. - if (!goog.events.BrowserFeature.POINTER_EVENTS || - !(name in Blockly.Touch.TOUCH_MAP)) { + if ((window && !window.PointerEvent) || !(name in Blockly.Touch.TOUCH_MAP)) { node.addEventListener(name, wrapFunc, false); bindData.push([node, name, wrapFunc]); } @@ -504,8 +502,7 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) { var bindData = []; // Don't register the mouse event if an equivalent pointer event is supported. - if (!goog.events.BrowserFeature.POINTER_EVENTS || - !(name in Blockly.Touch.TOUCH_MAP)) { + if ((window && !window.PointerEvent) || !(name in Blockly.Touch.TOUCH_MAP)) { node.addEventListener(name, wrapFunc, false); bindData.push([node, name, wrapFunc]); } diff --git a/core/touch.js b/core/touch.js index 7a883c241..78e6f5e72 100644 --- a/core/touch.js +++ b/core/touch.js @@ -48,7 +48,7 @@ Blockly.Touch.touchIdentifier_ = null; * @type {Object} */ Blockly.Touch.TOUCH_MAP = {}; -if (goog.events.BrowserFeature.POINTER_EVENTS) { +if (window && window.PointerEvent) { Blockly.Touch.TOUCH_MAP = { 'mousedown': ['pointerdown'], 'mousemove': ['pointermove'],