balsamine.www
clone your own copy | download snapshot

Snapshots | iceberg

Inside this repository

jquery.mobile-events.min.js
application/javascript

Download raw (16.0 KB)

/*!
 * jQuery Mobile Events
 * by Ben Major
 *
 * Copyright 2011-2017, Ben Major
 * Licensed under the MIT License:
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 */

'use strict';(function(a){function b(){var x=j();x!==k&&(k=x,g.trigger('orientationchange'))}function c(x,y,z,A){var B=z.type;z.type=y,a.event.dispatch.call(x,z,A),z.type=B}a.attrFn=a.attrFn||{};var d='ontouchstart'in window,f={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:d,orientation_support:'orientation'in window&&'onorientationchange'in window,startevent:d?'touchstart':'mousedown',endevent:d?'touchend':'mouseup',moveevent:d?'touchmove':'mousemove',tapevent:d?'tap':'click',scrollevent:d?'touchmove':'scroll',hold_timer:null,tap_timer:null};a.isTouchCapable=function(){return f.touch_capable},a.getStartEvent=function(){return f.startevent},a.getEndEvent=function(){return f.endevent},a.getMoveEvent=function(){return f.moveevent},a.getTapEvent=function(){return f.tapevent},a.getScrollEvent=function(){return f.scrollevent},a.each(['tapstart','tapend','tapmove','tap','tap2','tap3','tap4','singletap','doubletap','taphold','swipe','swipeup','swiperight','swipedown','swipeleft','swipeend','scrollstart','scrollend','orientationchange'],function(x,y){a.fn[y]=function(z){return z?this.on(y,z):this.trigger(y)},a.attrFn[y]=!0}),a.event.special.tapstart={setup:function(){var x=this,y=a(x);y.on(f.startevent,function z(A){if(y.data('callee',z),A.which&&1!==A.which)return!1;var B=A.originalEvent,C={position:{x:f.touch_capable?B.touches[0].screenX:A.screenX,y:f.touch_capable?B.touches[0].screenY:A.screenY},offset:{x:f.touch_capable?Math.round(B.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(A.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(B.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(A.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:A.target};return c(x,'tapstart',A,C),!0})},remove:function(){a(this).off(f.startevent,a(this).data.callee)}},a.event.special.tapmove={setup:function(){var x=this,y=a(x);y.on(f.moveevent,function z(A){y.data('callee',z);var B=A.originalEvent,C={position:{x:f.touch_capable?B.touches[0].screenX:A.screenX,y:f.touch_capable?B.touches[0].screenY:A.screenY},offset:{x:f.touch_capable?Math.round(B.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(A.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(B.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(A.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:A.target};return c(x,'tapmove',A,C),!0})},remove:function(){a(this).off(f.moveevent,a(this).data.callee)}},a.event.special.tapend={setup:function(){var x=this,y=a(x);y.on(f.endevent,function z(A){y.data('callee',z);var B=A.originalEvent,C={position:{x:f.touch_capable?B.changedTouches[0].screenX:A.screenX,y:f.touch_capable?B.changedTouches[0].screenY:A.screenY},offset:{x:f.touch_capable?Math.round(B.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(A.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(B.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(A.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:A.target};return c(x,'tapend',A,C),!0})},remove:function(){a(this).off(f.endevent,a(this).data.callee)}},a.event.special.taphold={setup:function(){var z,x=this,y=a(x),A={x:0,y:0},B=0,C=0;y.on(f.startevent,function D(E){if(E.which&&1!==E.which)return!1;y.data('tapheld',!1),z=E.target;var F=E.originalEvent,G=Date.now(),H={x:f.touch_capable?F.touches[0].screenX:E.screenX,y:f.touch_capable?F.touches[0].screenY:E.screenY},I={x:f.touch_capable?F.touches[0].pageX-F.touches[0].target.offsetLeft:E.offsetX,y:f.touch_capable?F.touches[0].pageY-F.touches[0].target.offsetTop:E.offsetY};A.x=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageX:E.pageX,A.y=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageY:E.pageY,B=A.x,C=A.y;var J=y.parent().data('threshold')?y.parent().data('threshold'):y.data('threshold'),K='undefined'!=typeof J&&!1!==J&&parseInt(J)?parseInt(J):f.taphold_threshold;return f.hold_timer=window.setTimeout(function(){var L=A.x-B,M=A.y-C;if(E.target==z&&(A.x==B&&A.y==C||L>=-f.tap_pixel_range&&L<=f.tap_pixel_range&&M>=-f.tap_pixel_range&&M<=f.tap_pixel_range)){y.data('tapheld',!0);var N=Date.now(),O={x:f.touch_capable?F.touches[0].screenX:E.screenX,y:f.touch_capable?F.touches[0].screenY:E.screenY},P={x:f.touch_capable?Math.round(F.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(E.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(F.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(E.pageY-(y.offset()?y.offset().top:0))},R={startTime:G,endTime:N,startPosition:H,startOffset:I,endPosition:O,endOffset:P,duration:N-G,target:E.target};y.data('callee1',D),c(x,'taphold',E,R)}},K),!0}).on(f.endevent,function D(){y.data('callee2',D),y.data('tapheld',!1),window.clearTimeout(f.hold_timer)}).on(f.moveevent,function D(E){y.data('callee3',D),B=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageX:E.pageX,C=E.originalEvent.targetTouches?E.originalEvent.targetTouches[0].pageY:E.pageY})},remove:function(){a(this).off(f.startevent,a(this).data.callee1).off(f.endevent,a(this).data.callee2).off(f.moveevent,a(this).data.callee3)}},a.event.special.doubletap={setup:function(){var z,A,C,D,x=this,y=a(x),B=null,E=!1;y.on(f.startevent,function F(G){return G.which&&1!==G.which?!1:(y.data('doubletapped',!1),z=G.target,y.data('callee1',F),C=G.originalEvent,B||(B={position:{x:f.touch_capable?C.touches[0].screenX:G.screenX,y:f.touch_capable?C.touches[0].screenY:G.screenY},offset:{x:f.touch_capable?Math.round(C.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(G.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(C.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(G.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:G.target,element:G.originalEvent.srcElement,index:a(G.target).index()}),!0)}).on(f.endevent,function F(G){var H=Date.now(),I=y.data('lastTouch')||H+1,J=H-I;if(window.clearTimeout(A),y.data('callee2',F),J<f.doubletap_int&&a(G.target).index()==B.index&&100<J){y.data('doubletapped',!0),window.clearTimeout(f.tap_timer);var K={position:{x:f.touch_capable?G.originalEvent.changedTouches[0].screenX:G.screenX,y:f.touch_capable?G.originalEvent.changedTouches[0].screenY:G.screenY},offset:{x:f.touch_capable?Math.round(C.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(G.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(C.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(G.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:G.target,element:G.originalEvent.srcElement,index:a(G.target).index()},L={firstTap:B,secondTap:K,interval:K.time-B.time};E||(c(x,'doubletap',G,L),B=null),E=!0,D=window.setTimeout(function(){E=!1},f.doubletap_int)}else y.data('lastTouch',H),A=window.setTimeout(function(){B=null,window.clearTimeout(A)},f.doubletap_int,[G]);y.data('lastTouch',H)})},remove:function(){a(this).off(f.startevent,a(this).data.callee1).off(f.endevent,a(this).data.callee2)}},a.event.special.singletap={setup:function(){var x=this,y=a(x),z=null,A=null,B={x:0,y:0};y.on(f.startevent,function C(D){return D.which&&1!==D.which?!1:(A=Date.now(),z=D.target,y.data('callee1',C),B.x=D.originalEvent.targetTouches?D.originalEvent.targetTouches[0].pageX:D.pageX,B.y=D.originalEvent.targetTouches?D.originalEvent.targetTouches[0].pageY:D.pageY,!0)}).on(f.endevent,function C(D){if(y.data('callee2',C),D.target==z){var E=D.originalEvent.changedTouches?D.originalEvent.changedTouches[0].pageX:D.pageX,F=D.originalEvent.changedTouches?D.originalEvent.changedTouches[0].pageY:D.pageY;f.tap_timer=window.setTimeout(function(){var G=B.x-E,H=B.y-F;if(!y.data('doubletapped')&&!y.data('tapheld')&&(B.x==E&&B.y==F||G>=-f.tap_pixel_range&&G<=f.tap_pixel_range&&H>=-f.tap_pixel_range&&H<=f.tap_pixel_range)){var I=D.originalEvent,J={position:{x:f.touch_capable?I.changedTouches[0].screenX:D.screenX,y:f.touch_capable?I.changedTouches[0].screenY:D.screenY},offset:{x:f.touch_capable?Math.round(I.changedTouches[0].pageX-(y.offset()?y.offset().left:0)):Math.round(D.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(I.changedTouches[0].pageY-(y.offset()?y.offset().top:0)):Math.round(D.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:D.target};J.time-A<f.taphold_threshold&&c(x,'singletap',D,J)}},f.doubletap_int)}})},remove:function(){a(this).off(f.startevent,a(this).data.callee1).off(f.endevent,a(this).data.callee2)}},a.event.special.tap={setup:function(){var B,D,x=this,y=a(x),z=!1,A=null,C={x:0,y:0};y.on(f.startevent,function E(F){return y.data('callee1',E),F.which&&1!==F.which?!1:(z=!0,C.x=F.originalEvent.targetTouches?F.originalEvent.targetTouches[0].pageX:F.pageX,C.y=F.originalEvent.targetTouches?F.originalEvent.targetTouches[0].pageY:F.pageY,B=Date.now(),A=F.target,D=F.originalEvent.targetTouches?F.originalEvent.targetTouches:[F],!0)}).on(f.endevent,function E(F){y.data('callee2',E);var G=F.originalEvent.targetTouches?F.originalEvent.changedTouches[0].pageX:F.pageX,H=F.originalEvent.targetTouches?F.originalEvent.changedTouches[0].pageY:F.pageY,I=C.x-G,J=C.y-H;if(A==F.target&&z&&Date.now()-B<f.taphold_threshold&&(C.x==G&&C.y==H||I>=-f.tap_pixel_range&&I<=f.tap_pixel_range&&J>=-f.tap_pixel_range&&J<=f.tap_pixel_range)){for(var O,L=F.originalEvent,M=[],N=0;N<D.length;N++)O={position:{x:f.touch_capable?L.changedTouches[N].screenX:F.screenX,y:f.touch_capable?L.changedTouches[N].screenY:F.screenY},offset:{x:f.touch_capable?Math.round(L.changedTouches[N].pageX-(y.offset()?y.offset().left:0)):Math.round(F.pageX-(y.offset()?y.offset().left:0)),y:f.touch_capable?Math.round(L.changedTouches[N].pageY-(y.offset()?y.offset().top:0)):Math.round(F.pageY-(y.offset()?y.offset().top:0))},time:Date.now(),target:F.target},M.push(O);c(x,'tap',F,M)}})},remove:function(){a(this).off(f.startevent,a(this).data.callee1).off(f.endevent,a(this).data.callee2)}},a.event.special.swipe={setup:function(){function x(H){B=a(H.currentTarget),B.data('callee1',x),E.x=H.originalEvent.targetTouches?H.originalEvent.targetTouches[0].pageX:H.pageX,E.y=H.originalEvent.targetTouches?H.originalEvent.targetTouches[0].pageY:H.pageY,F.x=E.x,F.y=E.y,C=!0;var I=H.originalEvent;G={position:{x:f.touch_capable?I.touches[0].screenX:H.screenX,y:f.touch_capable?I.touches[0].screenY:H.screenY},offset:{x:f.touch_capable?Math.round(I.changedTouches[0].pageX-(B.offset()?B.offset().left:0)):Math.round(H.pageX-(B.offset()?B.offset().left:0)),y:f.touch_capable?Math.round(I.changedTouches[0].pageY-(B.offset()?B.offset().top:0)):Math.round(H.pageY-(B.offset()?B.offset().top:0))},time:Date.now(),target:H.target}}function y(H){B=a(H.currentTarget),B.data('callee2',y),F.x=H.originalEvent.targetTouches?H.originalEvent.targetTouches[0].pageX:H.pageX,F.y=H.originalEvent.targetTouches?H.originalEvent.targetTouches[0].pageY:H.pageY;var I,J=B.parent().data('xthreshold')?B.parent().data('xthreshold'):B.data('xthreshold'),K=B.parent().data('ythreshold')?B.parent().data('ythreshold'):B.data('ythreshold'),L='undefined'!=typeof J&&!1!==J&&parseInt(J)?parseInt(J):f.swipe_h_threshold,M='undefined'!=typeof K&&!1!==K&&parseInt(K)?parseInt(K):f.swipe_v_threshold;if(E.y>F.y&&E.y-F.y>M&&(I='swipeup'),E.x<F.x&&F.x-E.x>L&&(I='swiperight'),E.y<F.y&&F.y-E.y>M&&(I='swipedown'),E.x>F.x&&E.x-F.x>L&&(I='swipeleft'),void 0!=I&&C){E.x=0,E.y=0,F.x=0,F.y=0,C=!1;var N=H.originalEvent,O={position:{x:f.touch_capable?N.touches[0].screenX:H.screenX,y:f.touch_capable?N.touches[0].screenY:H.screenY},offset:{x:f.touch_capable?Math.round(N.changedTouches[0].pageX-(B.offset()?B.offset().left:0)):Math.round(H.pageX-(B.offset()?B.offset().left:0)),y:f.touch_capable?Math.round(N.changedTouches[0].pageY-(B.offset()?B.offset().top:0)):Math.round(H.pageY-(B.offset()?B.offset().top:0))},time:Date.now(),target:H.target},P=Math.abs(G.position.x-O.position.x),Q=Math.abs(G.position.y-O.position.y),R={startEvnt:G,endEvnt:O,direction:I.replace('swipe',''),xAmount:P,yAmount:Q,duration:O.time-G.time};D=!0,B.trigger('swipe',R).trigger(I,R)}}function z(H){B=a(H.currentTarget);var I='';if(B.data('callee3',z),D){var J=B.data('xthreshold'),K=B.data('ythreshold'),L='undefined'!=typeof J&&!1!==J&&parseInt(J)?parseInt(J):f.swipe_h_threshold,M='undefined'!=typeof K&&!1!==K&&parseInt(K)?parseInt(K):f.swipe_v_threshold,N=H.originalEvent,O={position:{x:f.touch_capable?N.changedTouches[0].screenX:H.screenX,y:f.touch_capable?N.changedTouches[0].screenY:H.screenY},offset:{x:f.touch_capable?Math.round(N.changedTouches[0].pageX-(B.offset()?B.offset().left:0)):Math.round(H.pageX-(B.offset()?B.offset().left:0)),y:f.touch_capable?Math.round(N.changedTouches[0].pageY-(B.offset()?B.offset().top:0)):Math.round(H.pageY-(B.offset()?B.offset().top:0))},time:Date.now(),target:H.target};G.position.y>O.position.y&&G.position.y-O.position.y>M&&(I='swipeup'),G.position.x<O.position.x&&O.position.x-G.position.x>L&&(I='swiperight'),G.position.y<O.position.y&&O.position.y-G.position.y>M&&(I='swipedown'),G.position.x>O.position.x&&G.position.x-O.position.x>L&&(I='swipeleft');var P=Math.abs(G.position.x-O.position.x),Q=Math.abs(G.position.y-O.position.y),R={startEvnt:G,endEvnt:O,direction:I.replace('swipe',''),xAmount:P,yAmount:Q,duration:O.time-G.time};B.trigger('swipeend',R)}C=!1,D=!1}var G,A=this,B=a(A),C=!1,D=!1,E={x:0,y:0},F={x:0,y:0};B.on(f.startevent,x),B.on(f.moveevent,y),B.on(f.endevent,z)},remove:function(){a(this).off(f.startevent,a(this).data.callee1).off(f.moveevent,a(this).data.callee2).off(f.endevent,a(this).data.callee3)}},a.event.special.scrollstart={setup:function(){function x(C,D){A=D,c(y,A?'scrollstart':'scrollend',C)}var A,B,y=this,z=a(y);z.on(f.scrollevent,function C(D){z.data('callee',C),A||x(D,!0),clearTimeout(B),B=setTimeout(function(){x(D,!1)},50)})},remove:function(){a(this).off(f.scrollevent,a(this).data.callee)}};var h,j,k,l,m,g=a(window),n={0:!0,180:!0};if(f.orientation_support){var o=window.innerWidth||g.width(),p=window.innerHeight||g.height();l=o>p&&o-p>50,m=n[window.orientation],(l&&m||!l&&!m)&&(n={90:!0,'-90':!0})}a.event.special.orientationchange=h={setup:function(){return!f.orientation_support&&(k=j(),g.on('throttledresize',b),!0)},teardown:function(){return!f.orientation_support&&(g.off('throttledresize',b),!0)},add:function(x){var y=x.handler;x.handler=function(z){return z.orientation=j(),y.apply(this,arguments)}}},a.event.special.orientationchange.orientation=j=function(){var x=!0,y=document.documentElement;return x=f.orientation_support?n[window.orientation]:y&&1.1>y.clientWidth/y.clientHeight,x?'portrait':'landscape'},a.event.special.throttledresize={setup:function(){a(this).on('resize',s)},teardown:function(){a(this).off('resize',s)}};var u,v,w,r=250,s=function(){v=Date.now(),w=v-t,w>=r?(t=v,a(this).trigger('throttledresize')):(u&&window.clearTimeout(u),u=window.setTimeout(b,r-w))},t=0;a.each({scrollend:'scrollstart',swipeup:'swipe',swiperight:'swipe',swipedown:'swipe',swipeleft:'swipe',swipeend:'swipe',tap2:'tap'},function(x,y){a.event.special[x]={setup:function(){a(this).on(y,a.noop)}}})})(jQuery);