From 0a9c30d1dc2a952c1875802b68d0c795455ca635 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 6 Nov 2017 07:42:51 +0200 Subject: [PATCH] use passive for touch events if possible, fixes #3059 --- source/UI/jquery/jquery.mousewheel.js | 14 ++++++++++++-- source/UI/js/Core/Element.js | 20 +++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/source/UI/jquery/jquery.mousewheel.js b/source/UI/jquery/jquery.mousewheel.js index 38b60951..9ebb9b3e 100644 --- a/source/UI/jquery/jquery.mousewheel.js +++ b/source/UI/jquery/jquery.mousewheel.js @@ -20,11 +20,21 @@ if ($.event.fixHooks) { } } +var supportsPassive = false; +try { + var opts = Object.defineProperty({}, 'passive', { + get: function() { + supportsPassive = true; + } + }); + window.addEventListener("test", null, opts); +} catch (e) {} + $.event.special.mousewheel = { setup: function() { if ( this.addEventListener ) { for ( var i=types.length; i; ) { - this.addEventListener( types[--i], handler, false ); + this.addEventListener( types[--i], handler, supportsPassive ? { passive: true } : false ); } } else { this.onmousewheel = handler; @@ -34,7 +44,7 @@ $.event.special.mousewheel = { teardown: function() { if ( this.removeEventListener ) { for ( var i=types.length; i; ) { - this.removeEventListener( types[--i], handler, false ); + this.removeEventListener( types[--i], handler, supportsPassive ? { passive: true } : false ); } } else { this.onmousewheel = null; diff --git a/source/UI/js/Core/Element.js b/source/UI/js/Core/Element.js index f7f8446e..9c75bbc1 100644 --- a/source/UI/js/Core/Element.js +++ b/source/UI/js/Core/Element.js @@ -2,6 +2,15 @@ (function(_) { var noTooltipEvents = {}; + var supportsPassive = false; + try { + var opts = Object.defineProperty({}, 'passive', { + get: function() { + supportsPassive = true; + } + }); + window.addEventListener("test", null, opts); + } catch (e) {} /*@ Ox.Element Basic UI element object @@ -128,10 +137,15 @@ .on({ mousedown: onMousedown, mousewheel: onMousewheel, - touchend: onTouchend, - touchmove: onTouchmove, - touchstart: onTouchstart + //touchend: onTouchend, + //touchmove: onTouchmove, + //touchstart: onTouchstart }); + + that.$element[0].addEventListener('touchend', onTouchend, supportsPassive ? { passive: true } : false ); + that.$element[0].addEventListener('touchmove', onTouchmove, supportsPassive ? { passive: true } : false ); + that.$element[0].addEventListener('touchstart', onTouchstart, supportsPassive ? { passive: true } : false ); + that[0] = that.$element[0]; that.length = 1; that.self = function _self() {