mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
1 line
No EOL
1.5 KiB
JavaScript
1 line
No EOL
1.5 KiB
JavaScript
define(["dom","events"],function(dom,events){"use strict";function getTouches(e){return e.changedTouches||e.targetTouches||e.touches}function TouchHelper(elem){var touchTarget,touchStartX,touchStartY,self=this,swipeXThreshold=50,swipeXMaxY=30,touchStart=function(e){var touch=getTouches(e)[0];touchTarget=null,touchStartX=0,touchStartY=0,touch&&(touchStartX=touch.clientX,touchStartY=touch.clientY,touchTarget=touch.target)},touchEnd=function(e){if(touchTarget){var deltaX,deltaY,touch=getTouches(e)[0];if(touch){var touchEndX=touch.clientX||0,touchEndY=touch.clientY||0;deltaX=touchEndX-(touchStartX||0),deltaY=touchEndY-(touchStartY||0)}else deltaX=0,deltaY=0;deltaX>swipeXThreshold&&Math.abs(deltaY)<swipeXMaxY?events.trigger(self,"swiperight",[touchTarget]):deltaX<0-swipeXThreshold&&Math.abs(deltaY)<swipeXMaxY&&events.trigger(self,"swipeleft",[touchTarget])}touchTarget=null,touchStartX=0,touchStartY=0};this.touchStart=touchStart,this.touchEnd=touchEnd,dom.addEventListener(elem,"touchstart",touchStart,{passive:!0}),dom.addEventListener(elem,"touchend",touchEnd,{passive:!0}),dom.addEventListener(elem,"touchcancel",touchEnd,{passive:!0})}return TouchHelper.prototype.destroy=function(){var elem=this.elem,touchStart=this.touchStart,touchEnd=this.touchEnd;dom.removeEventListener(elem,"touchstart",touchStart,{passive:!0}),dom.removeEventListener(elem,"touchend",touchEnd,{passive:!0}),dom.removeEventListener(elem,"touchcancel",touchEnd,{passive:!0}),this.touchStart=null,this.touchEnd=null,this.elem=null},TouchHelper}); |