1 line
No EOL
1.8 KiB
JavaScript
1 line
No EOL
1.8 KiB
JavaScript
(function($){$.fn.longclick=function longclick(){var handler=arguments[0],duration=arguments[1],$this=$(this).data(_duration_,duration||null);return handler?$this.on(type,handler):$this.trigger(type)};$.longclick={duration:600};$.event.special.longclick={setup:function(data,namespaces){if(!/iphone|ipad|ipod/i.test(navigator.userAgent)){$(this).on(_mousedown_,schedule).on([_mouseup_,_mouseout_,_contextmenu_].join(" "),cancel).on(_click_,click)}else{touch_enabled(this).on(_touchstart_,schedule).on([_touchend_,_touchcancel_].join(" "),cancel).on(_click_,click).css({WebkitUserSelect:"none"})}},teardown:function(namespaces){$(this).off(namespace)}};function touch_enabled(element){$.each("touchstart touchend touchcancel".split(/ /),function bind(ix,it){element.addEventListener(it,function trigger_jquery_event(event){$(element).trigger(it)},false)});return $(element)}function schedule(event){if($(this).data(_timer_))return;var element=this;var args=arguments;function scheduled(){$(element).data(_fired_,true).data(_timer_,null);event.type=type;var f=jQuery.event.dispatch||jQuery.event.handle;f.apply(element,args)}$(this).data(_fired_,false).data(_timer_,setTimeout(scheduled,$(this).data(_duration_)||$.longclick.duration))}function cancel(event){var timer=$(this).data(_timer_);if(timer){$(this).data(_timer_,clearTimeout(timer)||null)}}function click(event){if($(this).data(_fired_))return event.stopImmediatePropagation()||false}var type="longclick",namespace="."+type,_mousedown_="mousedown"+namespace,_click_="click"+namespace,_mouseup_="mouseup"+namespace,_mouseout_="mouseout"+namespace,_contextmenu_="contextmenu"+namespace,_touchstart_="touchstart"+namespace,_touchend_="touchend"+namespace,_touchcancel_="touchcancel"+namespace,_duration_="duration"+namespace,_timer_="timer"+namespace,_fired_="fired"+namespace})(jQuery); |