/** * flipsnap.js * * @version 0.6.2 * @url http://pxgrid.github.com/js-flipsnap/ * * Copyright 2011 PixelGrid, Inc. * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ (function(e,t,n){function h(e,t){return this instanceof h?this.init(e,t):new h(e,t)}function p(e,t){return e.changedTouches?e.changedTouches[0][t]:e[t]}function d(e){return y(e,function(e){return r.style[e]!==n})}function v(e,t,r){var o=s[t];o?e[o]=r:e[t]!==n?(s[t]=t,e[t]=r):y(i,function(i){var o=g(i)+g(t);if(e[o]!==n)return s[t]=o,e[o]=r,!0})}function m(e){if(r.style[e]!==n)return e;var t;return y(i,function(i){var s=g(i)+g(e);if(r.style[s]!==n)return t="-"+i+"-"+e,!0}),t}function g(e){return e.charAt(0).toUpperCase()+e.substr(1)}function y(e,t){for(var n=0,r=e.length;n0},h.prototype.toNext=function(e){var t=this;if(!t.hasNext())return;t.moveToPoint(t.currentPoint+1,e)},h.prototype.toPrev=function(e){var t=this;if(!t.hasPrev())return;t.moveToPoint(t.currentPoint-1,e)},h.prototype.moveToPoint=function(e,t){var r=this;t=t===n?r.transitionDuration:t+"ms";var i=r.currentPoint;e===n&&(e=r.currentPoint),e<0?r.currentPoint=0:e>r._maxPoint?r.currentPoint=r._maxPoint:r.currentPoint=parseInt(e,10),o.cssAnimation?r._setStyle({transitionDuration:t}):r.animation=!0,r._setX(-r.currentPoint*r._distance,t),i!==r.currentPoint&&(r._triggerEvent("fsmoveend",!0,!1),r._triggerEvent("fspointmove",!0,!1))},h.prototype._setX=function(e,t){var n=this;n.currentX=e,o.cssAnimation?n.element.style[s.transform]=n._getTranslate(e):n.animation?n._animate(e,t||n.transitionDuration):n.element.style.left=e+"px"},h.prototype._touchStart=function(e,n){var r=this;if(r.disableTouch||r.scrolling||u)return;r.element.addEventListener(c.move[n],r,!1),t.addEventListener(c.end[n],r,!1);var i=e.target.tagName;n==="mouse"&&i!=="SELECT"&&i!=="INPUT"&&i!=="TEXTAREA"&&i!=="BUTTON"&&e.preventDefault(),o.cssAnimation?r._setStyle({transitionDuration:"0ms"}):r.animation=!1,r.scrolling=!0,r.moveReady=!1,r.startPageX=p(e,"pageX"),r.startPageY=p(e,"pageY"),r.basePageX=r.startPageX,r.directionX=0,r.startTime=e.timeStamp,r._triggerEvent("fstouchstart",!0,!1)},h.prototype._touchMove=function(e,t){var n=this;if(!n.scrolling||u)return;var r=p(e,"pageX"),i=p(e,"pageY"),s,o;if(n.moveReady){e.preventDefault(),s=r-n.basePageX,o=n.currentX+s;if(o>=0||o0?-1:1;var l=!n._triggerEvent("fstouchmove",!0,!0,{delta:s,direction:n.directionX});l?n._touchAfter({moved:!1,originalPoint:n.currentPoint,newPoint:n.currentPoint,cancelled:!0}):n._setX(o)}else{var c=b(n.startPageX,n.startPageY,r,i);c.z>a&&(w(c)>f?(e.preventDefault(),n.moveReady=!0,n.element.addEventListener("click",n,!0)):n.scrolling=!1)}n.basePageX=r},h.prototype._touchEnd=function(e,n){var r=this;r.element.removeEventListener(c.move[n],r,!1),t.removeEventListener(c.end[n],r,!1);if(!r.scrolling)return;var i=-r.currentX/r._distance;i=r.directionX>0?Math.ceil(i):r.directionX<0?Math.floor(i):Math.round(i),i<0?i=0:i>r._maxPoint&&(i=r._maxPoint),r._touchAfter({moved:i!==r.currentPoint,originalPoint:r.currentPoint,newPoint:i,cancelled:!1}),r.moveToPoint(i)},h.prototype._click=function(e){var t=this;e.stopPropagation(),e.preventDefault()},h.prototype._touchAfter=function(e){var t=this;t.scrolling=!1,t.moveReady=!1,setTimeout(function(){t.element.removeEventListener("click",t,!0)},200),t._triggerEvent("fstouchend",!0,!1,e)},h.prototype._setStyle=function(e){var t=this,n=t.element.style;for(var r in e)v(n,r,e[r])},h.prototype._animate=function(e,t){var n=this,r=n.element,i=+(new Date),s=parseInt(r.style.left,10),o=e,u=parseInt(t,10),a=function(e,t){return-(e/=t)*(e-2)},f=setInterval(function(){var e=new Date-i,t,n;e>u?(clearInterval(f),n=o):(t=a(e,u),n=t*(o-s)+s),r.style.left=n+"px"},10)},h.prototype.destroy=function(){var e=this;l.forEach(function(t){e.element.removeEventListener(c.start[t],e,!1)})},h.prototype._getTranslate=function(e){var t=this;return t.use3d?"translate3d("+e+"px, 0, 0)":"translate("+e+"px, 0)"},h.prototype._triggerEvent=function(e,n,r,i){var s=this,o=t.createEvent("Event");o.initEvent(e,n,r);if(i)for(var u in i)i.hasOwnProperty(u)&&(o[u]=i[u]);return s.element.dispatchEvent(o)},typeof exports=="object"?module.exports=h:typeof define=="function"&&define.amd?define(function(){return h}):e.Flipsnap=h})(window,window.document);