hugo-theme-zzo/assets/js/swipe.js

9 lines
7.5 KiB
JavaScript
Raw Permalink Normal View History

/*!
* Swipe 2.2.14
*
* Brad Birdsall
* Copyright 2013, MIT License
*
*/
!function(t,e){"function"==typeof define&&define.amd?define([],function(){return t.Swipe=e(),t.Swipe}):"object"==typeof module&&module.exports?module.exports=e():t.Swipe=e()}(this,function(){var t,e="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this,n=e.document;function i(t,i){"use strict";var o,s,r={},a={},u=(i=i||{}).auto||0,l=!1,c=function(){},v=function(t){setTimeout(t||c,0)};var d=function(t){return!!t&&("boolean"!=typeof t.cancelable||t.cancelable)},f={addEventListener:!!e.addEventListener,passiveEvents:function(){var t=!1;try{var n=Object.defineProperty({},"passive",{get:function(){t=!0}});e.addEventListener("testEvent",null,n),e.removeEventListener("testEvent",null,n)}catch(e){t=!1}return t}(),touch:"ontouchstart"in e||e.DocumentTouch&&n instanceof DocumentTouch,transitions:function(t){var e=["transitionProperty","WebkitTransition","MozTransition","OTransition","msTransition"];for(var n in e)if(void 0!==t.style[e[n]])return!0;return!1}(n.createElement("swipe"))};if(t){var m,h,p,E,y=t.children[0],b=parseInt(i.startSlide,10)||0,g=i.speed||300;i.continuous=void 0===i.continuous||i.continuous;var T,x,L=((T=t).currentStyle?x=T.currentStyle.direction:e.getComputedStyle&&(x=e.getComputedStyle(T,null).getPropertyValue("direction")),"rtl"===x?"right":"left");i.autoRestart=void 0!==i.autoRestart&&i.autoRestart;var w=function(t,e){e=e||100;var n=null;function i(){n&&clearTimeout(n)}function o(){var o=this,s=arguments;i(),n=setTimeout(function(){n=null,t.apply(o,s)},e)}return o.cancel=i,o}(S),D={handleEvent:function(t){if(!l){switch(t.type){case"mousedown":case"touchstart":this.start(t);break;case"mousemove":case"touchmove":this.move(t);break;case"mouseup":case"mouseleave":case"touchend":this.end(t);break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"otransitionend":case"transitionend":this.transitionEnd(t);break;case"resize":w()}i.stopPropagation&&t.stopPropagation()}},start:function(t){var e;Q(t)?(e=t,t.preventDefault()):e=t.touches[0],r={x:e.pageX,y:e.pageY,time:+new Date},o=void 0,a={},Q(t)?(y.addEventListener("mousemove",this,!1),y.addEventListener("mouseup",this,!1),y.addEventListener("mouseleave",this,!1)):(y.addEventListener("touchmove",this,!!f.passiveEvents&&{passive:!1}),y.addEventListener("touchend",this,!1))},move:function(t){var e;if(Q(t))e=t;else{if(t.touches.length>1||t.scale&&1!==t.scale)return;i.disableScroll&&d(t)&&t.preventDefault(),e=t.touches[0]}a={x:e.pageX-r.x,y:e.pageY-r.y},void 0===o&&(o=!!(o||Math.abs(a.x)<Math.abs(a.y))),o||(d(t)&&t.preventDefault(),N(),i.continuous?(C(O(b-1),a.x+h[O(b-1)],0),C(b,a.x+h[b],0),C(O(b+1),a.x+h[O(b+1)],0)):(a.x=a.x/(!b&&a.x>0||b===m.length-1&&a.x<0?Math.abs(a.x)/p+1:1),C(b-1,a.x+h[b-1],0),C(b,a.x+h[b],0),C(b+1,a.x+h[b+1],0)))},end:function(t){var e=+new Date-r.time,n=Number(e)<250&&Math.abs(a.x)>20||Math.abs(a.x)>p/2,s=!b&&a.x>0||b===m.length-1&&a.x<0;i.continuous&&(s=!1);var u=Math.abs(a.x)/a.x;o||(n&&!s?(u<0?(i.continuous?(R(O(b-1),-p,0),R(O(b+2),p,0)):R(b-1,-p,0),R(b,h[b]-p,g),R(O(b+1),h[O(b+1)]-p,g),b=O(b+1)):(i.continuous?(R(O(b+1),p,0),R(O(b-2),-p,0)):R(b+1,p,0),R(b,h[b]+p,g),R(O(b-1),h[O(b-1)]+p,g),b=O(b-1)),A(P(),m[b],u)):i.continuous?(R(O(b-1),-p,g),R(b,0,g),R(O(b+1),p,g)):(R(b-1,-p,g),R(b,0,g),R(b+1,p,g))),Q(t)?(y.removeEventListener("mousemove",D,!1),y.removeEventListener("mouseup",D,!1),y.removeEventListener("mouseleave",D,!1)):(y.removeEventListener("touchmove",D,!!f.passiveEvents&&{passive:!1}),y.removeEventListener("touchend",D,!1))},transitionEnd:function(t){parseInt(t.target.getAttribute("data-index"),10)===b&&((u||i.autoRestart)&&X(),j(P(),m[b]))}};return S(),W(),{setup:S,slide:function(t,e){N(),I(t,e)},prev:function(){N(),function(){if(l)return;i.continuous?I(b-1):b&&I(b-1)}()},next:function(){N(),z()},restart:X,stop:N,getPos:P,disable:function(){N(),l=!0},enable:function(){l=!1,X()},getNumSlides:function(){return E},kill:function(){N(),t.style.visibility="",y.style.width="",y.style[L]="";var e=m.length;for(;e--;){f.transitions&&C(e,0,0);var n=m[e];if(n.getAttribu