0;e=e.parentNode}return!1},getCenter:function(t){var n=[],r=[];for(var i=0,s=t.length;i<s;i++)n.push(t[i].pageX),r.push(t[i].pageY);return{pageX:(Math.min.apply(Math,n)+Math.max.apply(Math,n))/2,pageY:(Math.min.apply(Math,r)+Math.max.apply(Math,r))/2}},getVelocity:function(t,n,r){return{x:Math.abs(n/t)||0,y:Math.abs(r/t)||0}},getAngle:function(t,n){var r=n.pageY-t.pageY,i=n.pageX-t.pageX;return Math.atan2(r,i)*180/Math.PI},getDirection:function(t,r){var i=Math.abs(t.pageX-r.pageX),s=Math.abs(t.pageY-r.pageY);return i>=s?t.pageX-r.pageX>0?n.DIRECTION_LEFT:n.DIRECTION_RIGHT:t.pageY-r.pageY>0?n.DIRECTION_UP:n.DIRECTION_DOWN},getDistance:function(t,n){var r=n.pageX-t.pageX,i=n.pageY-t.pageY;return Math.sqrt(r*r+i*i)},getScale:function(t,n){return t.length>=2&&n.length>=2?this.getDistance(n[0],n[1])/this.getDistance(t[0],t[1]):1},getRotation:function(t,n){return t.length>=2&&n.length>=2?this.getAngle(n[1],n[0])-this.getAngle(t[1],t[0]):0},isVertical:function(t){return t==n.DIRECTION_UP||t==n.DIRECTION_DOWN},stopDefaultBrowserBehavior:function(t,n){var r,i=["webkit","khtml","moz","ms","o",""];if(!n||!t.style)return;for(var s=0;s<i.length;s++)for(var o in n)n.hasOwnProperty(o)&&(r=o,i[s]&&(r=i[s]+r.substring(0,1).toUpperCase()+r.substring(1)),t.style[r]=n[o]);n.userSelect=="none"&&(t.onselectstart=function(){return!1})}},n.detection={gestures:[],current:null,previous:null,stopped:!1,startDetect:function(t,r){if(this.current)return;this.stopped=!1,this.current={inst:t,startEvent:n.utils.extend({},r),lastEvent:!1,name:""},this.detect(r)},detect:function(t){if(!this.current||this.stopped)return;t=this.extendEventData(t);var r=this.current.inst.options;for(var i=0,s=this.gestures.length;i<s;i++){var o=this.gestures[i];if(!this.stopped&&r[o.name]!==!1&&o.handler.call(o,t,this.current.inst)===!1){this.stopDetect();break}}return this.current&&(this.current.lastEvent=t),t.eventType==n.EVENT_END&&!t.touches.length-1&&this.stopDetect(),t},stopDetect:function(){this.previous=n.utils.extend({},this.current),this.current=null,this.stopped=!0},extendEventData:function(t){var r=this.current.startEvent;if(r&&(t.touches.length!=r.touches.length||t.touches===r.touches)){r.touches=[];for(var i=0,s=t.touches.length;i<s;i++)r.touches.push(n.utils.extend({},t.touches[i]))}var o=t.timeStamp-r.timeStamp,u=t.center.pageX-r.center.pageX,a=t.center.pageY-r.center.pageY,f=n.utils.getVelocity(o,u,a);return n.utils.extend(t,{deltaTime:o,deltaX:u,deltaY:a,velocityX:f.x,velocityY:f.y,distance:n.utils.getDistance(r.center,t.center),angle:n.utils.getAngle(r.center,t.center),direction:n.utils.getDirection(r.center,t.center),scale:n.utils.getScale(r.touches,t.touches),rotation:n.utils.getRotation(r.touches,t.touches),startEvent:r}),t},register:function(r){var i=r.defaults||{};return i[r.name]===t&&(i[r.name]=!0),n.utils.extend(n.defaults,i,!0),r.index=r.index||1e3,this.gestures.push(r),this.gestures.sort(function(e,t){return e.index<t.index?-1:e.index>t.index?1:0}),this.gestures}},n.gestures=n.gestures||{},n.gestures.Hold={name:"hold",index:10,defaults:{hold_timeout:500,hold_threshold:1},timer:null,handler:function(t,r){switch(t.eventType){case n.EVENT_START:clearTimeout(this.timer),n.detection.current.name=this.name,this.timer=setTimeout(function(){n.detection.current.name=="hold"&&r.trigger("hold",t)},r.options.hold_timeout);break;case n.EVENT_MOVE:t.distance>r.options.hold_threshold&&clearTimeout(this.timer);break;case n.EVENT_END:clearTimeout(this.timer)}}},n.gestures.Tap={name:"tap",index:100,defaults:{tap_max_touchtime:250,tap_max_distance:10,tap_always:!0,doubletap_distance:20,doubletap_interval:300},handler:function(t,r){if(t.eventType==n.EVENT_END){var i=n.detection.previous,s=!1;if(t.deltaTime>r.options.tap_max_touchtime||t.distance>r.options.tap_max_distance)return;i&&i.name=="tap"&&t.timeStamp-i.lastEvent.timeStamp<r.options.doubletap_interval&&t.distance<r.options.doubletap_distance&&(r.trigger("doubletap",t),s=!0);if(!s||r.options.tap_always)n.detection.current.name="tap",r.trigger(n.detection.current.name,t)}}},n.gestures.Swipe={name:"swipe",index:40,defaults:{swipe_max_touches:1,swipe_velocity:.7},handler:function(t,r){if(t.eventType==n.EVENT_END){if(r.options.swipe_max_touches>0&&t.touches.length>r.options.swipe_max_touches)return;if(t.velocityX>r.options.swipe_velocity||t.velocityY>r.options.swipe_velocity)r.trigger(this.name,t),r.trigger(this.name+t.direction,t)}}},n.gestures.Drag={name:"drag",index:50,defaults:{drag_min_distance:10,drag_max_touches:1,drag_block_horizontal:!1,drag_block_vertical:!1,drag_lock_to_axis:!1,drag_lock_min_distance:25},triggered:!1,handler:function(t,r){if(n.detection.current.name!=this.name&&this.triggered){r.trigger(this.name+"end",t),this.triggered=!1;return}if(r.options.drag_max_touches>0&&t.touches.length>r.options.drag_max_touches)return;switch(t.eventType){case n.EVENT_START:this.triggered=!1;break;case n.EVENT_MOVE:if(t.distance<r.options.drag_min_distance&&n.detection.current.name!=this.name)return;n.detection.current.name=this.name;if(n.detection.current.lastEvent.drag_locked_to_axis||r.options.drag_lock_to_axis&&r.options.drag_lock_min_distance<=t.distance)t.drag_locked_to_axis=!0;var i=n.detection.current.lastEvent.direction;t.drag_locked_to_axis&&i!==t.direction&&(n.utils.isVertical(i)?t.direction=t.deltaY<0?n.DIRECTION_UP:n.DIRECTION_DOWN:t.direction=t.deltaX<0?n.DIRECTION_LEFT:n.DIRECTION_RIGHT),this.triggered||(r.trigger(this.name+"start",t),this.triggered=!0),r.trigger(this.name,t),r.trigger(this.name+t.direction,t),(r.options.drag_block_vertical&&n.utils.isVertical(t.direction)||r.options.drag_block_horizontal&&!n.utils.isVertical(t.direction))&&t.preventDefault();break;case n.EVENT_END:this.triggered&&r.trigger(this.name+"end",t),this.triggered=!1}}},n.gestures.Transform={name:"transform",index:45,defaults:{transform_min_scale:.01,transform_min_rotation:1,transform_always_block:!1},triggered:!1,handler:function(t,r){if(n.detection.current.name!=this.name&&this.triggered){r.trigger(this.name+"end",t),this.triggered=!1;return}if(t.touches.length<2)return;r.options.transform_always_block&&t.preventDefault();switch(t.

Prev | Next
Pg.: 1 ... 24 25 26 27 28 29 30 31 32 33 34 ... 41


Back to home | File page

Subscribe | Register | Login | N