diff --git a/libraries/jquery.touchevent.js b/libraries/jquery.touchevent.js new file mode 100644 index 00000000..a2ed0692 --- /dev/null +++ b/libraries/jquery.touchevent.js @@ -0,0 +1,15 @@ +// Passive event listeners +function regiterTouchHandler(jQuery) { + + jQuery.event.special.touchstart = { + setup: function (_, ns, handle) { + this.addEventListener("touchstart", handle, { passive: true }); + } + }; + jQuery.event.special.touchmove = { + setup: function (_, ns, handle) { + this.addEventListener("touchmove", handle, { passive: true }); + } + }; +} +export default regiterTouchHandler; \ No newline at end of file diff --git a/packages/mindplot/src/components/ScreenManager.ts b/packages/mindplot/src/components/ScreenManager.ts index f1f4cce6..5ce9ce8d 100644 --- a/packages/mindplot/src/components/ScreenManager.ts +++ b/packages/mindplot/src/components/ScreenManager.ts @@ -17,6 +17,12 @@ */ import { $assert } from '@wisemapping/core-js'; import { Point } from '@wisemapping/web2d'; +// https://stackoverflow.com/questions/60357083/does-not-use-passive-listeners-to-improve-scrolling-performance-lighthouse-repo +// https://web.dev/uses-passive-event-listeners/?utm_source=lighthouse&utm_medium=lr +// eslint-disable-next-line import/extensions +import regiterTouchHandler from '../../../../libraries/jquery.touchevent'; + +regiterTouchHandler($); class ScreenManager { private _divContainer: JQuery; @@ -63,8 +69,11 @@ class ScreenManager { } addEvent(eventType: string, listener) { - if (eventType === 'click') this._clickEvents.push(listener); - else this._divContainer.bind(eventType, listener); + if (eventType === 'click') { + this._clickEvents.push(listener); + } else { + this._divContainer.bind(eventType, listener); + } } removeEvent(event: string, listener) {