/*
Copyright 2013, KISSY UI Library v1.31
MIT Licensed
build time: Apr 2 18:05
*/
KISSY.add("event/dom/touch/double-tap",function(e,b,g,a){function d(){}e.extend(d,a,{onTouchStart:function(a){if(!1===d.superclass.onTouchStart.apply(this,arguments))return!1;this.startTime=a.timeStamp;this.singleTapTimer&&(clearTimeout(this.singleTapTimer),this.singleTapTimer=0)},onTouchMove:function(){return!1},onTouchEnd:function(a){var d=this.lastEndTime,b=a.timeStamp,e=a.target,c=a.changedTouches[0],f=b-this.startTime;this.lastEndTime=b;if(d&&(f=b-d,300>f)){this.lastEndTime=0;g.fire(e,"doubleTap",
{touch:c,duration:f/1E3});return}f=b-this.startTime;300<f?g.fire(e,"singleTap",{touch:c,duration:f/1E3}):this.singleTapTimer=setTimeout(function(){g.fire(e,"singleTap",{touch:c,duration:f/1E3})},300)}});b.singleTap=b.doubleTap={handle:new d};return d},{requires:["./handle-map","event/dom/base","./single-touch"]});
KISSY.add("event/dom/touch/gesture",function(e,b){var g=b.Gesture,a,d,h;e.Features.isTouchSupported()&&(a="touchstart",d="touchmove",h="touchend");a&&(g.start=a,g.move=d,g.end=h,g.tap="tap",g.doubleTap="doubleTap");return g},{requires:["event/dom/base"]});KISSY.add("event/dom/touch/handle-map",function(){return{}});
KISSY.add("event/dom/touch/handle",function(e,b,g,a,d){function h(f){this.doc=f;this.eventHandle={};this.init()}var i=e.guid("touch-handle"),j=e.Features,k={};k[d.start]="onTouchStart";k[d.move]="onTouchMove";k[d.end]="onTouchEnd";"mousedown"!==d.start&&(k.touchcancel="onTouchEnd");var c=e.throttle(function(f){this.callEventHandle("onTouchMove",f)},30);h.prototype={init:function(){var f=this.doc,l,c;for(l in k){c=k[l];a.on(f,l,this[c],this)}},normalize:function(f){var l=f.type,c;if(!j.isTouchSupported()){if(l.indexOf("mouse")!=
-1&&f.which!=1)return;c=[f];l=!l.match(/up$/i);f.touches=l?c:[];f.targetTouches=l?c:[];f.changedTouches=c}return f},onTouchMove:function(f){c.call(this,f)},onTouchStart:function(f){var l,c,a=this.eventHandle;for(l in a){c=a[l].handle;c.isActive=1}this.callEventHandle("onTouchStart",f)},onTouchEnd:function(f){this.callEventHandle("onTouchEnd",f)},callEventHandle:function(f,c){var a=this.eventHandle,d,b;if(c=this.normalize(c)){for(d in a){b=a[d].handle;if(!b.processed){b.processed=1;if(b.isActive&&
b[f](c)===false)b.isActive=0}}for(d in a){b=a[d].handle;b.processed=0}}},addEventHandle:function(f){var c=this.eventHandle,a=g[f].handle;c[f]?c[f].count++:c[f]={count:1,handle:a}},removeEventHandle:function(f){var c=this.eventHandle;if(c[f]){c[f].count--;c[f].count||delete c[f]}},destroy:function(){var c=this.doc,d,b;for(d in k){b=k[d];a.detach(c,d,this[b],this)}}};return{addDocumentHandle:function(c,a){var d=b.getWindow(c.ownerDocument||c).document,e=g[a].setup,j=b.data(d,i);j||b.data(d,i,j=new h(d));
e&&e.call(c,a);j.addEventHandle(a)},removeDocumentHandle:function(c,a){var d=b.getWindow(c.ownerDocument||c).document,h=g[a].tearDown,j=b.data(d,i);h&&h.call(c,a);if(j){j.removeEventHandle(a);if(e.isEmptyObject(j.eventHandle)){j.destroy();b.removeData(d,i)}}}}},{requires:"dom,./handle-map,event/dom/base,./gesture,./tap,./swipe,./double-tap,./pinch,./tap-hold,./rotate".split(",")});
KISSY.add("event/dom/touch/multi-touch",function(e,b){function g(){}g.prototype={requiredTouchCount:2,onTouchStart:function(a){var d=this.requiredTouchCount,b=a.touches.length;b===d?this.start():b>d&&this.end(a)},onTouchEnd:function(a){this.end(a)},start:function(){this.isTracking||(this.isTracking=!0,this.isStarted=!1)},fireEnd:e.noop,getCommonTarget:function(a){var d=a.touches,a=d[0].target,d=d[1].target;if(a==d||b.contains(a,d))return a;for(;;){if(b.contains(d,a))return d;d=d.parentNode}},end:function(a){this.isTracking&&
(this.isTracking=!1,this.isStarted&&(this.isStarted=!1,this.fireEnd(a)))}};return g},{requires:["dom"]});
KISSY.add("event/dom/touch/pinch",function(e,b,g,a,d){function h(){}function i(a){(!a.touches||2==a.touches.length)&&a.preventDefault()}e.extend(h,a,{onTouchMove:function(a){if(this.isTracking){var d=a.touches,c,f=d[0],b=d[1];c=f.pageX-b.pageX;f=f.pageY-b.pageY;c=Math.sqrt(c*c+f*f);this.lastTouches=d;this.isStarted?g.fire(this.target,"pinch",e.mix(a,{distance:c,scale:c/this.startDistance})):(this.isStarted=!0,this.startDistance=c,d=this.target=this.getCommonTarget(a),g.fire(d,"pinchStart",e.mix(a,
{distance:c,scale:1})))}},fireEnd:function(a){g.fire(this.target,"pinchEnd",e.mix(a,{touches:this.lastTouches}))}});a=new h;b.pinchStart=b.pinchEnd={handle:a};b.pinch={handle:a,setup:function(){g.on(this,d.move,i)},tearDown:function(){g.detach(this,d.move,i)}};return h},{requires:["./handle-map","event/dom/base","./multi-touch","./gesture"]});
KISSY.add("event/dom/touch/rotate",function(e,b,g,a,d,h){function i(){}function j(c){(!c.touches||2==c.touches.length)&&c.preventDefault()}var k=180/Math.PI;e.extend(i,g,{onTouchMove:function(c){if(this.isTracking){var d=c.touches,b=d[0],g=d[1],j=this.lastAngle,b=Math.atan2(g.pageY-b.pageY,g.pageX-b.pageX)*k;if(j!==h){var g=Math.abs(b-j),i=(b+360)%360,m=(b-360)%360;Math.abs(i-j)<g?b=i:Math.abs(m-j)<g&&(b=m)}this.lastTouches=d;this.lastAngle=b;this.isStarted?a.fire(this.target,"rotate",e.mix(c,{angle:b,
rotation:b-this.startAngle})):(this.isStarted=!0,this.startAngle=b,this.target=this.getCommonTarget(c),a.fire(this.target,"rotateStart",e.mix(c,{angle:b,rotation:0})))}},end:function(){this.lastAngle=h;i.superclass.end.apply(this,arguments)},fireEnd:function(c){a.fire(this.target,"rotateEnd",e.mix(c,{touches:this.lastTouches}))}});g=new i;b.rotateEnd=b.rotateStart={handle:g};b.rotate={handle:g,setup:function(){a.on(this,d.move,j)},tearDown:function(){a.detach(this,d.move,j)}};return i},{requires:["./handle-map",
"./multi-touch","event/dom/base","./gesture"]});KISSY.add("event/dom/touch/single-touch",function(e){function b(){}b.prototype={requiredTouchCount:1,onTouchStart:function(b){if(b.touches.length!=this.requiredTouchCount)return!1;this.lastTouches=b.touches},onTouchMove:e.noop,onTouchEnd:e.noop};return b});
KISSY.add("event/dom/touch/swipe",function(e,b,g,a){function d(c,a,b){var d=a.changedTouches[0],e=d.pageX-c.startX,h=d.pageY-c.startY,m=Math.abs(e),n=Math.abs(h);if(b)c.isVertical&&c.isHorizontal&&(n>m?c.isHorizontal=0:c.isVertical=0);else if(c.isVertical&&n<k&&(c.isVertical=0),c.isHorizontal&&m<k)c.isHorizontal=0;if(c.isHorizontal)e=0>e?"left":"right";else if(c.isVertical)e=0>h?"up":"down",m=n;else return!1;g.fire(a.target,b?j:i,{originalEvent:a.originalEvent,touch:d,direction:e,distance:m,duration:(a.timeStamp-
c.startTime)/1E3})}function h(){}var i="swipe",j="swiping",k=50;e.extend(h,a,{onTouchStart:function(c){if(!1===h.superclass.onTouchStart.apply(this,arguments))return!1;var a=c.touches[0];this.startTime=c.timeStamp;this.isVertical=this.isHorizontal=1;this.startX=a.pageX;this.startY=a.pageY;-1!=c.type.indexOf("mouse")&&c.preventDefault()},onTouchMove:function(a){var b=a.changedTouches[0],e=b.pageY-this.startY,b=Math.abs(b.pageX-this.startX),e=Math.abs(e);if(1E3<a.timeStamp-this.startTime)return!1;this.isVertical&&
35<b&&(this.isVertical=0);this.isHorizontal&&35<e&&(this.isHorizontal=0);return d(this,a,1)},onTouchEnd:function(a){return!1===this.onTouchMove(a)?!1:d(this,a,0)}});b[i]=b[j]={handle:new h};return h},{requires:["./handle-map","event/dom/base","./single-touch"]});
KISSY.add("event/dom/touch/tap-hold",function(e,b,g,a,d){function h(){}function i(a){(!a.touches||1==a.touches.length)&&a.preventDefault()}e.extend(h,g,{onTouchStart:function(b){if(!1===h.superclass.onTouchStart.call(this,b))return!1;this.timer=setTimeout(function(){a.fire(b.target,"tapHold",{touch:b.touches[0],duration:(e.now()-b.timeStamp)/1E3})},1E3)},onTouchMove:function(){clearTimeout(this.timer);return!1},onTouchEnd:function(){clearTimeout(this.timer)}});b.tapHold={setup:function(){a.on(this,
d.start,i)},tearDown:function(){a.detach(this,d.start,i)},handle:new h};return h},{requires:["./handle-map","./single-touch","event/dom/base","./gesture"]});KISSY.add("event/dom/touch/tap",function(e,b,g,a){function d(){}e.extend(d,a,{onTouchMove:function(){return!1},onTouchEnd:function(a){g.fire(a.target,"tap",{touch:a.changedTouches[0]})}});b.tap={handle:new d};return d},{requires:["./handle-map","event/dom/base","./single-touch"]});
KISSY.add("event/dom/touch",function(e,b,g,a){var e=b._Special,b={setup:function(b){a.addDocumentHandle(this,b)},tearDown:function(b){a.removeDocumentHandle(this,b)}},d;for(d in g)e[d]=b},{requires:["event/dom/base","./touch/handle-map","./touch/handle"]});
