From 8ab7562a52eeed264d83e7c61933370f91de2188 Mon Sep 17 00:00:00 2001 From: micpob Date: Sun, 26 Nov 2017 12:42:55 +0100 Subject: [PATCH 1/2] Removed onmousemove and ontouchmove detection for a better UX. --- jquery.longclick-min.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jquery.longclick-min.js b/jquery.longclick-min.js index aeaf5fc..193f4fa 100644 --- a/jquery.longclick-min.js +++ b/jquery.longclick-min.js @@ -8,5 +8,4 @@ Updated: 2010-06-22 */ (function(a){function n(b){a.each("touchstart touchmove touchend touchcancel".split(/ /),function(d,e){b.addEventListener(e,function(){a(b).trigger(e)},false)});return a(b)}function j(b){function d(){a(e).data(h,true);b.type=f;jQuery.event.handle.apply(e,o)}if(!a(this).data(g)){var e=this,o=arguments;a(this).data(h,false).data(g,setTimeout(d,a(this).data(i)||a.longclick.duration))}}function k(){a(this).data(g,clearTimeout(a(this).data(g))||null)}function l(b){if(a(this).data(h))return b.stopImmediatePropagation()|| -false}var p=a.fn.click;a.fn.click=function(b,d){if(!d)return p.apply(this,arguments);return a(this).data(i,b||null).bind(f,d)};a.fn.longclick=function(){var b=[].splice.call(arguments,0),d=b.pop();b=b.pop();var e=a(this).data(i,b||null);return d?e.click(b,d):e.trigger(f)};a.longclick={duration:500};a.event.special.longclick={setup:function(){/iphone|ipad|ipod/i.test(navigator.userAgent)?n(this).bind(q,j).bind([r,s,t].join(" "),k).bind(m,l).css({WebkitUserSelect:"none"}):a(this).bind(u,j).bind([v, -w,x,y].join(" "),k).bind(m,l)},teardown:function(){a(this).unbind(c)}};var f="longclick",c="."+f,u="mousedown"+c,m="click"+c,v="mousemove"+c,w="mouseup"+c,x="mouseout"+c,y="contextmenu"+c,q="touchstart"+c,r="touchend"+c,s="touchmove"+c,t="touchcancel"+c,i="duration"+c,g="timer"+c,h="fired"+c})(jQuery); +false}var p=a.fn.click;a.fn.click=function(b,d){if(!d)return p.apply(this,arguments);return a(this).data(i,b||null).bind(f,d)};a.fn.longclick=function(){var b=[].splice.call(arguments,0),d=b.pop();b=b.pop();var e=a(this).data(i,b||null);return d?e.click(b,d):e.trigger(f)};a.longclick={duration:500};a.event.special.longclick={setup:function(){/iphone|ipad|ipod/i.test(navigator.userAgent)?n(this).bind(q,j).bind([r,t].join(" "),k).bind(m,l).css({WebkitUserSelect:"none"}):a(this).bind(u,j).bind([w,x,y].join(" "),k).bind(m,l)},teardown:function(){a(this).unbind(c)}};var f="longclick",c="."+f,u="mousedown"+c,m="click"+c,w="mouseup"+c,x="mouseout"+c,y="contextmenu"+c,q="touchstart"+c,r="touchend"+c,t="touchcancel"+c,i="duration"+c,g="timer"+c,h="fired"+c})(jQuery); From 73f0aea6679014c7ddca796e5fb8ed009cf22695 Mon Sep 17 00:00:00 2001 From: micpob Date: Sun, 26 Nov 2017 12:58:19 +0100 Subject: [PATCH 2/2] Updated event.handle to event.dispatch, removed onmousemove and ontouchmove detection --- jquery.longclick.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jquery.longclick.js b/jquery.longclick.js index 0cdb4af..114a17c 100644 --- a/jquery.longclick.js +++ b/jquery.longclick.js @@ -69,13 +69,13 @@ /* normal technique for standard mouse-based interaction */ $(this) .bind(_mousedown_, schedule) - .bind([_mousemove_, _mouseup_, _mouseout_, _contextmenu_].join(' '), annul) + .bind([_mouseup_, _mouseout_, _contextmenu_].join(' '), annul) .bind(_click_, click) }else{ /* and special handling for touch-based interaction on iPhone-compatibile devices */ touch_enabled(this) .bind(_touchstart_, schedule) - .bind([_touchend_, _touchmove_, _touchcancel_].join(' '), annul) + .bind([_touchend_, _touchcancel_].join(' '), annul) .bind(_click_, click) .css({ WebkitUserSelect: 'none' }) } @@ -89,7 +89,7 @@ Commit subset of touch events to trigger jQuery events of same names */ function touch_enabled(element){ - $.each('touchstart touchmove touchend touchcancel'.split(/ /), function bind(ix, it){ + $.each('touchstart touchend touchcancel'.split(/ /), function bind(ix, it){ element.addEventListener(it, function trigger_jquery_event(event){ $(element).trigger(it) }, false); }); return $(element); @@ -114,7 +114,7 @@ /* Flag as "fired" and rejoin the default event flow */ $(element).data(_fired_, true) event.type= type - jQuery.event.handle.apply(element, args) + jQuery.event.dispatch.apply(element, args) } } function annul(event){ @@ -135,12 +135,12 @@ /* Event strings */ _mousedown_= 'mousedown'+namespace, _click_= 'click'+namespace, - _mousemove_= 'mousemove'+namespace, _mouseup_= 'mouseup'+namespace, + _mouseup_= 'mouseup'+namespace, _mouseout_= 'mouseout'+namespace, _contextmenu_= 'contextmenu'+namespace, _touchstart_= 'touchstart'+namespace, _touchend_= 'touchend'+namespace, - _touchmove_= 'touchmove'+namespace, _touchcancel_= 'touchcancel'+namespace, + _touchcancel_= 'touchcancel'+namespace, /* Storage keys */ _duration_= 'duration'+namespace, _timer_= 'timer'+namespace, _fired_= 'fired'+namespace -})(jQuery); \ No newline at end of file +})(jQuery);