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

9 lines
7.5 KiB
JavaScript
Raw Normal View History

/*!
* Swipe 2.2.15
*
* 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,c=!1,l=function(){},v=function(t){setTimeout(t||l,0)},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 h,m,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(!c){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;W(t)?(e=t,t.preventDefault()):e=t.touches[0],r={x:e.pageX,y:e.pageY,time:+new Date},o=void 0,a={},W(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)),function(t,e){i.dragStart&&i.dragStart(t,e)}(P(),h[b])},move:function(t){var e;if(W(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(),X(),i.continuous?(I(O(b-1),a.x+m[O(b-1)],0),I(b,a.x+m[b],0),I(O(b+1),a.x+m[O(b+1)],0)):(a.x=a.x/(!b&&a.x>0||b===h.length-1&&a.x<0?Math.abs(a.x)/p+1:1),I(b-1,a.x+m[b-1],0),I(b,a.x+m[b],0),I(b+1,a.x+m[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===h.length-1&&a.x<0;i.continuous&&(s=!1);var u=Math.abs(a.x)/a.x;o||(n&&!s?(u<0?(i.continuous?(C(O(b-1),-p,0),C(O(b+2),p,0)):C(b-1,-p,0),C(b,m[b]-p,g),C(O(b+1),m[O(b+1)]-p,g),b=O(b+1)):(i.continuous?(C(O(b+1),p,0),C(O(b-2),-p,0)):C(b+1,p,0),C(b,m[b]+p,g),C(O(b-1),m[O(b-1)]+p,g),b=O(b-1)),A(P(),h[b],u)):i.continuous?(C(O(b-1),-p,g),C(b,0,g),C(O(b+1),p,g)):(C(b-1,-p,g),C(b,0,g),C(b+1,p,g))),W(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)),function(t,e){i.dragEnd&&i.dragEnd(t,e)}(P(),h[b])},transitionEnd:function(t){parseInt(t.target.getAttribute("data-index"),10)===b&&((u||i.autoRestart)&&Q(),j(P(),h[b]))}};return S(),N(),{setup:S,slide:function(t,e){X(),R(t,e)},prev:function(){X(),function(){if(c)return;i.continuous?R(b-1):b&&R(b-1)}()},next:function(){X(),z()},restart:Q,stop:X,getPos:P,disable:function(){X(),c=!0},enable:function(){c=!1,Q()},getNumSlides:function(){return E},kill:function(){X(),t.style.visibility="",y.sty