You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
9.3 KiB
Plaintext

(function(a,c,b){if(typeof define==="function"&&define.amd){define(["jquery"],function(d){b(d,a,c);return d.mobile})}else{b(a.jQuery,a,c)}}(this,document,function(c,b,a,d){(function(e,f){e.extend(e.support,{orientation:"orientation" in b&&"onorientationchange" in b})}(c));(function(i){i.event.special.throttledresize={setup:function(){i(this).bind("resize",g)},teardown:function(){i(this).unbind("resize",g)}};var h=250,g=function(){k=(new Date()).getTime();j=k-f;if(j>=h){f=k;i(this).trigger("throttledresize")}else{if(e){clearTimeout(e)}e=setTimeout(g,h-j)}},f=0,e,k,j})(c);(function(j,o){var m=j(o),l="orientationchange",f,k,g,p,n={"0":true,"180":true},i,e,h;if(j.support.orientation){i=o.innerWidth||m.width();e=o.innerHeight||m.height();h=50;g=i>e&&(i-e)>h;p=n[o.orientation];if((g&&p)||(!g&&!p)){n={"-90":true,"90":true}}}j.event.special.orientationchange=j.extend({},j.event.special.orientationchange,{setup:function(){if(j.support.orientation&&!j.event.special.orientationchange.disabled){return false}k=f();m.bind("throttledresize",q)},teardown:function(){if(j.support.orientation&&!j.event.special.orientationchange.disabled){return false}m.unbind("throttledresize",q)},add:function(r){var s=r.handler;r.handler=function(t){t.orientation=f();return s.apply(this,arguments)}}});function q(){var r=f();if(r!==k){k=r;m.trigger(l)}}j.event.special.orientationchange.orientation=f=function(){var s=true,r=a.documentElement;if(j.support.orientation){s=n[o.orientation]}else{s=r&&r.clientWidth/r.clientHeight<1.1}return s?"portrait":"landscape"};j.fn[l]=function(r){return r?this.bind(l,r):this.trigger(l)};if(j.attrFn){j.attrFn[l]=true}}(c,this));(function(B,K,j,q){var J="virtualMouseBindings",f="virtualTouchID",e="vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "),A="clientX clientY pageX pageY screenX screenY".split(" "),G=B.event.mouseHooks?B.event.mouseHooks.props:[],C=B.event.props.concat(G),E={},L=0,w=0,v=0,t=false,O=[],l=false,V=false,y="addEventListener" in j,x=B(j),I=1,R=0,g,P;B.vmouse={moveDistanceThreshold:10,clickDistanceThreshold:10,resetTimerDuration:1500};function u(i){while(i&&typeof i.originalEvent!=="undefined"){i=i.originalEvent}return i}function m(X,Y){var ag=X.type,ah,af,Z,W,ad,ac,ab,aa,ae;X=B.Event(X);X.type=Y;ah=X.originalEvent;af=B.event.props;if(ag.search(/^(mouse|click)/)>-1){af=C}if(ah){for(ab=af.length,W;ab;){W=af[--ab];X[W]=ah[W]}}if(ag.search(/mouse(down|up)|click/)>-1&&!X.which){X.which=1}if(ag.search(/^touch/)!==-1){Z=u(ah);ag=Z.touches;ad=Z.changedTouches;ac=(ag&&ag.length)?ag[0]:((ad&&ad.length)?ad[0]:q);if(ac){for(aa=0,ae=A.length;aa<ae;aa++){W=A[aa];X[W]=ac[W]}}}return X}function T(Y){var W={},i,X;while(Y){i=B.data(Y,J);for(X in i){if(i[X]){W[X]=W.hasVirtualBinding=true}}Y=Y.parentNode}return W}function F(X,W){var i;while(X){i=B.data(X,J);if(i&&(!W||i[W])){return X}X=X.parentNode}return null}function N(){V=false}function o(){V=true}function U(){R=0;O.length=0;l=false;o()}function s(){N()}function z(){D();L=setTimeout(function(){L=0;U()},B.vmouse.resetTimerDuration)}function D(){if(L){clearTimeout(L);L=0}}function r(X,Y,i){var W;if((i&&i[X])||(!i&&F(Y.target,X))){W=m(Y,X);B(Y.target).trigger(W)}return W}function n(W){var X=B.data(W.target,f),i;if(!l&&(!R||R!==X)){i=r("v"+W.type,W);if(i){if(i.isDefaultPrevented()){W.preventDefault()}if(i.isPropagationStopped()){W.stopPropagation()}if(i.isImmediatePropagationStopped()){W.stopImmediatePropagation()}}}}function S(X){var Z=u(X).touches,Y,i,W;if(Z&&Z.length===1){Y=X.target;i=T(Y);if(i.hasVirtualBinding){R=I++;B.data(Y,f,R);D();s();t=false;W=u(X).touches[0];w=W.pageX;v=W.pageY;r("vmouseover",X,i);r("vmousedown",X,i)}}}function M(i){if(V){return}if(!t){r("vmousecancel",i,T(i.target))}t=true;z()}function h(Z){if(V){return}var X=u(Z).touches[0],W=t,Y=B.vmouse.moveDistanceThreshold,i=T(Z.target);t=t||(Math.abs(X.pageX-w)>Y||Math.abs(X.pageY-v)>Y);if(t&&!W){r("vmousecancel",Z,i)}r("vmousemove",Z,i);z()}function k(Y){if(V){return}o();var i=T(Y.target),W,X;r("vmouseup",Y,i);if(!t){W=r("vclick",Y,i);if(W&&W.isDefaultPrevented()){X=u(Y).changedTouches[0];O.push({touchID:R,x:X.clientX,y:X.clientY});l=true}}r("vmouseout",Y,i);t=false;z()}function H(W){var X=B.data(W,J),i;if(X){for(i in X){if(X[i]){return true}}}return false}function Q(){}function p(i){var W=i.substr(1);return{setup:function(){if(!H(this)){B.data(this,J,{})}var X=B.data(this,J);X[i]=true;E[i]=(E[i]||0)+1;if(E[i]===1){x.bind(W,n)}B(this).bind(W,Q);if(y){E.touchstart=(E.touchstart||0)+1;if(E.touchstart===1){x.bind("touchstart",S).bind("touchend",k).bind("touchmove",h).bind("scroll",M)}}},teardown:function(){--E[i];if(!E[i]){x.unbind(W,n)}if(y){--E.touchstart;if(!E.touchstart){x.unbind("touchstart",S).unbind("touchmove",h).unbind("touchend",k).unbind("scroll",M)}}var X=B(this),Y=B.data(this,J);if(Y){Y[i]=false}X.unbind(W,Q);if(!H(this)){X.removeData(J)}}}}for(P=0;P<e.length;P++){B.event.special[e[P]]=p(e[P])}if(y){j.addEventListener("click",function(aa){var X=O.length,ab=aa.target,ad,ac,ae,Z,W,Y;if(X){ad=aa.clientX;ac=aa.clientY;g=B.vmouse.clickDistanceThreshold;ae=ab;while(ae){for(Z=0;Z<X;Z++){W=O[Z];Y=0;if((ae===ab&&Math.abs(W.x-ad)<g&&Math.abs(W.y-ac)<g)||B.data(ae,f)===W.touchID){aa.preventDefault();aa.stopPropagation();return}}ae=ae.parentNode}}},true)}})(c,b,a);(function(e){e.mobile={}}(c));(function(f,g){var e={touch:"ontouchend" in a};f.mobile.support=f.mobile.support||{};f.extend(f.support,e);f.extend(f.mobile.support,e)}(c));(function(h,m,e){var f=h(a),i=h.mobile.support.touch,j="touchmove scroll",n=i?"touchstart":"mousedown",l=i?"touchend":"mouseup",g=i?"touchmove":"mousemove";h.each(("touchstart touchmove touchend tap taphold swipe swipeleft swiperight scrollstart scrollstop").split(" "),function(p,o){h.fn[o]=function(q){return q?this.bind(o,q):this.trigger(o)};if(h.attrFn){h.attrFn[o]=true}});function k(s,p,r,o){var q=r.type;r.type=p;if(o){h.event.trigger(r,e,s)}else{h.event.dispatch.call(s,r)}r.type=q}h.event.special.scrollstart={enabled:true,setup:function(){var o=this,r=h(o),q,s;function p(t,u){q=u;k(o,q?"scrollstart":"scrollstop",t)}r.bind(j,function(t){if(!h.event.special.scrollstart.enabled){return}if(!q){p(t,true)}clearTimeout(s);s=setTimeout(function(){p(t,false)},50)})},teardown:function(){h(this).unbind(j)}};h.event.special.tap={tapholdThreshold:750,emitTapOnTaphold:true,setup:function(){var o=this,q=h(o),p=false;q.bind("vmousedown",function(t){p=false;if(t.which&&t.which!==1){return false}var s=t.target,w;function r(){clearTimeout(w)}function v(){r();q.unbind("vclick",u).unbind("vmouseup",r);f.unbind("vmousecancel",v)}function u(x){v();if(!p&&s===x.target){k(o,"tap",x)}else{if(p){x.preventDefault()}}}q.bind("vmouseup",r).bind("vclick",u);f.bind("vmousecancel",v);w=setTimeout(function(){if(!h.event.special.tap.emitTapOnTaphold){p=true}k(o,"taphold",h.Event("taphold",{target:s}))},h.event.special.tap.tapholdThreshold)})},teardown:function(){h(this).unbind("vmousedown").unbind("vclick").unbind("vmouseup");f.unbind("vmousecancel")}};h.event.special.swipe={scrollSupressionThreshold:30,durationThreshold:1000,horizontalDistanceThreshold:30,verticalDistanceThreshold:30,getLocation:function(r){var q=m.pageXOffset,p=m.pageYOffset,o=r.clientX,s=r.clientY;if(r.pageY===0&&Math.floor(s)>Math.floor(r.pageY)||r.pageX===0&&Math.floor(o)>Math.floor(r.pageX)){o=o-q;s=s-p}else{if(s<(r.pageY-p)||o<(r.pageX-q)){o=r.pageX-q;s=r.pageY-p}}return{x:o,y:s}},start:function(p){var q=p.originalEvent.touches?p.originalEvent.touches[0]:p,o=h.event.special.swipe.getLocation(q);return{time:(new Date()).getTime(),coords:[o.x,o.y],origin:h(p.target)}},stop:function(p){var q=p.originalEvent.touches?p.originalEvent.touches[0]:p,o=h.event.special.swipe.getLocation(q);return{time:(new Date()).getTime(),coords:[o.x,o.y]}},handleSwipe:function(s,p,o,q){if(p.time-s.time<h.event.special.swipe.durationThreshold&&Math.abs(s.coords[0]-p.coords[0])>h.event.special.swipe.horizontalDistanceThreshold&&Math.abs(s.coords[1]-p.coords[1])<h.event.special.swipe.verticalDistanceThreshold){var r=s.coords[0]>p.coords[0]?"swipeleft":"swiperight";k(o,"swipe",h.Event("swipe",{target:q,swipestart:s,swipestop:p}),true);k(o,r,h.Event(r,{target:q,swipestart:s,swipestop:p}),true);return true}return false},eventInProgress:false,setup:function(){var q,o=this,r=h(o),p={};q=h.data(this,"mobile-events");if(!q){q={length:0};h.data(this,"mobile-events",q)}q.length++;q.swipe=p;p.start=function(u){if(h.event.special.swipe.eventInProgress){return}h.event.special.swipe.eventInProgress=true;var s,w=h.event.special.swipe.start(u),t=u.target,v=false;p.move=function(x){if(!w||x.isDefaultPrevented()){return}s=h.event.special.swipe.stop(x);if(!v){v=h.event.special.swipe.handleSwipe(w,s,o,t);if(v){h.event.special.swipe.eventInProgress=false}}if(Math.abs(w.coords[0]-s.coords[0])>h.event.special.swipe.scrollSupressionThreshold){x.preventDefault()}};p.stop=function(){v=true;h.event.special.swipe.eventInProgress=false;f.off(g,p.move);p.move=null};f.on(g,p.move).one(l,p.stop)};r.on(n,p.start)},teardown:function(){var p,o;p=h.data(this,"mobile-events");if(p){o=p.swipe;delete p.swipe;p.length--;if(p.length===0){h.removeData(this,"mobile-events")}}if(o){if(o.start){h(this).off(n,o.start)}if(o.move){f.off(g,o.move)}if(o.stop){f.off(l,o.stop)}}}};h.each({scrollstop:"scrollstart",taphold:"tap",swipeleft:"swipe.left",swiperight:"swipe.right"},function(p,o){h.event.special[p]={setup:function(){h(this).bind(o,h.noop)},teardown:function(){h(this).unbind(o)}}})})(c,this)}));