forked from t413/SinglePaged
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ideal-image-slider.min.js
2 lines (2 loc) · 17.6 KB
/
ideal-image-slider.min.js
1
2
/*! Ideal Image Slider v1.5.1 */
var IdealImageSlider=function(){"use strict";var a=function(a,b){return a["r"+b]||a["webkitR"+b]||a["mozR"+b]||a["msR"+b]||function(a){setTimeout(a,1e3/60)}}(window,"equestAnimationFrame"),b=function(b,c){function d(){var g=(new Date).getTime(),h=g-e;h>=c?b.call():f.value=a(d)}var e=(new Date).getTime(),f={};return f.value=a(d),f},c=function(a,b){var c=Object.prototype.toString.call(b).slice(8,-1);return void 0!==b&&null!==b&&c===a},d=function(a){return Math.round(a)===a},e=function(a){a=a||{};for(var b=1;b<arguments.length;b++){var d=arguments[b];if(d)for(var f in d)d.hasOwnProperty(f)&&(c("Object",d[f])&&null!==d[f]?e(a[f],d[f]):a[f]=d[f])}return a},f=function(a,b){return b?a.classList?a.classList.contains(b):new RegExp("(^| )"+b+"( |$)","gi").test(a.className):!1},g=function(a,b){b&&(a.classList?a.classList.add(b):a.className+=" "+b)},h=function(a,b){b&&(a.classList?a.classList.remove(b):a.className=a.className.replace(new RegExp("(^|\\b)"+b.split(" ").join("|")+"(\\b|$)","gi")," "))},i=function(a){return Array.prototype.slice.call(a)},j=function(a,b,c){null!==a&&"undefined"!=typeof a&&(a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent?a.attachEvent("on"+b,c):a["on"+b]=c)},k=function(a,b){if(!a.style.backgroundImage){var c=new Image;c.setAttribute("src",a.getAttribute("data-src")),c.onload=function(){a.style.backgroundImage="url("+a.getAttribute("data-src")+")",a.setAttribute("data-actual-width",this.naturalWidth),a.setAttribute("data-actual-height",this.naturalHeight),"function"==typeof b&&b(this)}}},l=function(){var a="(-webkit-min-device-pixel-ratio: 1.5),(min--moz-device-pixel-ratio: 1.5),(-o-min-device-pixel-ratio: 3/2),(min-resolution: 1.5dppx)";return window.devicePixelRatio>1?!0:window.matchMedia&&window.matchMedia(a).matches?!0:!1},m=function(a,b,c){a.style.webkitTransitionDuration=a.style.MozTransitionDuration=a.style.msTransitionDuration=a.style.OTransitionDuration=a.style.transitionDuration=c+"ms",a.style.webkitTransform=a.style.MozTransform=a.style.msTransform=a.style.OTransform="translateX("+b+"px)"},n=function(a){a.style.removeProperty("-webkit-transition-duration"),a.style.removeProperty("transition-duration"),a.style.removeProperty("-webkit-transform"),a.style.removeProperty("-ms-transform"),a.style.removeProperty("transform")},o=function(b){var c=b.time,d=+new Date+c,e=function(){var f=+new Date,g=d-f;if(60>g)return void b.run(1);var h=1-g/c;b.run(h),a(e)};e()},p=function(a,b){if("undefined"==typeof b&&(b=!0),!d(a.settings.height)){var c=Math.round(a._attributes.container.offsetHeight),e=c;if(a._attributes.aspectWidth&&a._attributes.aspectHeight)e=a._attributes.aspectHeight/a._attributes.aspectWidth*a._attributes.container.offsetWidth;else{var f=a._attributes.currentSlide.getAttribute("data-actual-width"),g=a._attributes.currentSlide.getAttribute("data-actual-height");f&&g&&(e=g/f*a._attributes.container.offsetWidth)}var h=parseInt(a.settings.maxHeight,10);h&&e>h&&(e=h),e=Math.round(e),e!==c&&(b?o({time:a.settings.transitionDuration,run:function(b){a._attributes.container.style.height=Math.round(b*(e-c)+c)+"px"}}):a._attributes.container.style.height=e+"px")}},q={vars:{start:{},delta:{},isScrolling:void 0,direction:null},start:function(a){if(!f(this._attributes.container,this.settings.classes.animating)){var b=a.touches[0];q.vars.start={x:b.pageX,y:b.pageY,time:+new Date},q.vars.delta={},q.vars.isScrolling=void 0,q.vars.direction=null,this.stop(),this.settings.beforeChange.apply(this),g(this._attributes.container,this.settings.classes.touching)}},move:function(a){if(!f(this._attributes.container,this.settings.classes.animating)&&!(a.touches.length>1||a.scale&&1!==a.scale)){var b=a.touches[0];q.vars.delta={x:b.pageX-q.vars.start.x,y:b.pageY-q.vars.start.y},"undefined"==typeof q.vars.isScrolling&&(q.vars.isScrolling=!!(q.vars.isScrolling||Math.abs(q.vars.delta.x)<Math.abs(q.vars.delta.y))),q.vars.isScrolling||(a.preventDefault(),m(this._attributes.previousSlide,q.vars.delta.x-this._attributes.previousSlide.offsetWidth,0),m(this._attributes.currentSlide,q.vars.delta.x,0),m(this._attributes.nextSlide,q.vars.delta.x+this._attributes.currentSlide.offsetWidth,0))}},end:function(a){if(!f(this._attributes.container,this.settings.classes.animating)){var c=+new Date-q.vars.start.time,d=Number(c)<250&&Math.abs(q.vars.delta.x)>20||Math.abs(q.vars.delta.x)>this._attributes.currentSlide.offsetWidth/2,e=q.vars.delta.x<0?"next":"previous",i=this.settings.transitionDuration?this.settings.transitionDuration/2:0;q.vars.isScrolling||(d?(q.vars.direction=e,"next"==q.vars.direction?(m(this._attributes.currentSlide,-this._attributes.currentSlide.offsetWidth,i),m(this._attributes.nextSlide,0,i)):(m(this._attributes.previousSlide,0,i),m(this._attributes.currentSlide,this._attributes.currentSlide.offsetWidth,i)),b(q.transitionEnd.bind(this),i)):"next"==e?(m(this._attributes.currentSlide,0,i),m(this._attributes.nextSlide,this._attributes.currentSlide.offsetWidth,i)):(m(this._attributes.previousSlide,-this._attributes.previousSlide.offsetWidth,i),m(this._attributes.currentSlide,0,i)),i&&(g(this._attributes.container,this.settings.classes.animating),b(function(){h(this._attributes.container,this.settings.classes.animating)}.bind(this),i)))}},transitionEnd:function(a){if(q.vars.direction){n(this._attributes.previousSlide),n(this._attributes.currentSlide),n(this._attributes.nextSlide),h(this._attributes.container,this.settings.classes.touching),h(this._attributes.previousSlide,this.settings.classes.previousSlide),h(this._attributes.currentSlide,this.settings.classes.currentSlide),h(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","true");var b=this._attributes.slides,c=b.indexOf(this._attributes.currentSlide);"next"==q.vars.direction?(this._attributes.previousSlide=this._attributes.currentSlide,this._attributes.currentSlide=b[c+1],this._attributes.nextSlide=b[c+2],"undefined"==typeof this._attributes.currentSlide&&"undefined"==typeof this._attributes.nextSlide?(this._attributes.currentSlide=b[0],this._attributes.nextSlide=b[1]):"undefined"==typeof this._attributes.nextSlide&&(this._attributes.nextSlide=b[0]),k(this._attributes.nextSlide)):(this._attributes.nextSlide=this._attributes.currentSlide,this._attributes.previousSlide=b[c-2],this._attributes.currentSlide=b[c-1],"undefined"==typeof this._attributes.currentSlide&&"undefined"==typeof this._attributes.previousSlide?(this._attributes.currentSlide=b[b.length-1],this._attributes.previousSlide=b[b.length-2]):"undefined"==typeof this._attributes.previousSlide&&(this._attributes.previousSlide=b[b.length-1]),k(this._attributes.previousSlide)),g(this._attributes.previousSlide,this.settings.classes.previousSlide),g(this._attributes.currentSlide,this.settings.classes.currentSlide),g(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","false"),p(this),this.settings.afterChange.apply(this)}}},r=function(a){this.settings={selector:"",height:"auto",initialHeight:400,maxHeight:null,interval:4e3,transitionDuration:700,effect:"slide",disableNav:!1,keyboardNav:!0,previousNavSelector:"",nextNavSelector:"",classes:{container:"ideal-image-slider",slide:"iis-slide",previousSlide:"iis-previous-slide",currentSlide:"iis-current-slide",nextSlide:"iis-next-slide",previousNav:"iis-previous-nav",nextNav:"iis-next-nav",animating:"iis-is-animating",touchEnabled:"iis-touch-enabled",touching:"iis-is-touching",directionPrevious:"iis-direction-previous",directionNext:"iis-direction-next"},onInit:function(){},onStart:function(){},onStop:function(){},onDestroy:function(){},beforeChange:function(){},afterChange:function(){}},"string"==typeof a?this.settings.selector=a:"object"==typeof a&&e(this.settings,a);var b=document.querySelector(this.settings.selector);if(!b)return null;var c=i(b.children),h=[];b.innerHTML="",Array.prototype.forEach.call(c,function(a,c){if(a instanceof HTMLImageElement||a instanceof HTMLAnchorElement){var d=document.createElement("a"),f="",i="";if(a instanceof HTMLAnchorElement){f=a.getAttribute("href"),i=a.getAttribute("target");var j=a.querySelector("img");if(null===j)return;a=j}"undefined"!=typeof a.dataset?(e(d.dataset,a.dataset),a.dataset.src?d.dataset.src=a.dataset.src:d.dataset.src=a.src,l()&&a.dataset["src-2x"]&&(d.dataset.src=a.dataset["src-2x"])):a.getAttribute("data-src")?d.setAttribute("data-src",a.getAttribute("data-src")):d.setAttribute("data-src",a.getAttribute("src")),f&&d.setAttribute("href",f),i&&d.setAttribute("target",i),a.getAttribute("className")&&g(d,a.getAttribute("className")),a.getAttribute("id")&&d.setAttribute("id",a.getAttribute("id")),a.getAttribute("title")&&d.setAttribute("title",a.getAttribute("title")),a.getAttribute("alt")&&(d.innerHTML=a.getAttribute("alt")),d.setAttribute("role","tabpanel"),d.setAttribute("aria-hidden","true"),d.style.cssText+="-webkit-transition-duration:"+this.settings.transitionDuration+"ms;-moz-transition-duration:"+this.settings.transitionDuration+"ms;-o-transition-duration:"+this.settings.transitionDuration+"ms;transition-duration:"+this.settings.transitionDuration+"ms;",b.appendChild(d),h.push(d)}}.bind(this));var m=h;if(m.length<=1)return b.innerHTML="",Array.prototype.forEach.call(c,function(a,c){b.appendChild(a)}),null;if(!this.settings.disableNav){var n,o;this.settings.previousNavSelector?n=document.querySelector(this.settings.previousNavSelector):(n=document.createElement("a"),b.appendChild(n)),this.settings.nextNavSelector?o=document.querySelector(this.settings.nextNavSelector):(o=document.createElement("a"),b.appendChild(o)),g(n,this.settings.classes.previousNav),g(o,this.settings.classes.nextNav),j(n,"click",function(){return f(this._attributes.container,this.settings.classes.animating)?!1:(this.stop(),void this.previousSlide())}.bind(this)),j(o,"click",function(){return f(this._attributes.container,this.settings.classes.animating)?!1:(this.stop(),void this.nextSlide())}.bind(this)),("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)&&(this.settings.effect="slide",n.style.display="none",o.style.display="none",g(b,this.settings.classes.touchEnabled),j(b,"touchstart",q.start.bind(this),!1),j(b,"touchmove",q.move.bind(this),!1),j(b,"touchend",q.end.bind(this),!1)),this.settings.keyboardNav&&j(document,"keyup",function(a){a=a||window.event;var b="number"==typeof a.which?a.which:a.keyCode;if(37==b){if(f(this._attributes.container,this.settings.classes.animating))return!1;this.stop(),this.previousSlide()}else if(39==b){if(f(this._attributes.container,this.settings.classes.animating))return!1;this.stop(),this.nextSlide()}}.bind(this))}if(this._attributes={container:b,slides:m,previousSlide:"undefined"!=typeof m[m.length-1]?m[m.length-1]:m[0],currentSlide:m[0],nextSlide:"undefined"!=typeof m[1]?m[1]:m[0],timerId:0,origChildren:c,aspectWidth:0,aspectHeight:0},d(this.settings.height))this._attributes.container.style.height=this.settings.height+"px";else{if(d(this.settings.initialHeight)&&(this._attributes.container.style.height=this.settings.initialHeight+"px"),this.settings.height.indexOf(":")>-1){var r=this.settings.height.split(":");2==r.length&&d(parseInt(r[0],10))&&d(parseInt(r[1],10))&&(this._attributes.aspectWidth=parseInt(r[0],10),this._attributes.aspectHeight=parseInt(r[1],10))}j(window,"resize",function(){p(this,!1)}.bind(this))}g(b,this.settings.classes.container),g(b,"iis-effect-"+this.settings.effect),Array.prototype.forEach.call(this._attributes.slides,function(a,b){g(a,this.settings.classes.slide)}.bind(this)),g(this._attributes.previousSlide,this.settings.classes.previousSlide),g(this._attributes.currentSlide,this.settings.classes.currentSlide),g(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","false"),k(this._attributes.currentSlide,function(){this.settings.onInit.apply(this),p(this,!1)}.bind(this)),k(this._attributes.previousSlide),k(this._attributes.nextSlide)};return r.prototype.get=function(a){return this._attributes?this._attributes.hasOwnProperty(a)?this._attributes[a]:void 0:null},r.prototype.set=function(a,b){return this._attributes?this._attributes[a]=b:null},r.prototype.start=function(){this._attributes&&(this._attributes.timerId=setInterval(this.nextSlide.bind(this),this.settings.interval),this.settings.onStart.apply(this),window.onblur=function(){this.stop()}.bind(this))},r.prototype.stop=function(){this._attributes&&(clearInterval(this._attributes.timerId),this._attributes.timerId=0,this.settings.onStop.apply(this))},r.prototype.previousSlide=function(){this.settings.beforeChange.apply(this),h(this._attributes.previousSlide,this.settings.classes.previousSlide),h(this._attributes.currentSlide,this.settings.classes.currentSlide),h(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","true");var a=this._attributes.slides,c=a.indexOf(this._attributes.currentSlide);this._attributes.nextSlide=this._attributes.currentSlide,this._attributes.previousSlide=a[c-2],this._attributes.currentSlide=a[c-1],"undefined"==typeof this._attributes.currentSlide&&"undefined"==typeof this._attributes.previousSlide?(this._attributes.currentSlide=a[a.length-1],this._attributes.previousSlide=a[a.length-2]):"undefined"==typeof this._attributes.previousSlide&&(this._attributes.previousSlide=a[a.length-1]),k(this._attributes.previousSlide),g(this._attributes.previousSlide,this.settings.classes.previousSlide),g(this._attributes.currentSlide,this.settings.classes.currentSlide),g(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","false"),g(this._attributes.container,this.settings.classes.directionPrevious),b(function(){h(this._attributes.container,this.settings.classes.directionPrevious)}.bind(this),this.settings.transitionDuration),this.settings.transitionDuration&&(g(this._attributes.container,this.settings.classes.animating),b(function(){h(this._attributes.container,this.settings.classes.animating)}.bind(this),this.settings.transitionDuration)),p(this),this.settings.afterChange.apply(this)},r.prototype.nextSlide=function(){this.settings.beforeChange.apply(this),h(this._attributes.previousSlide,this.settings.classes.previousSlide),h(this._attributes.currentSlide,this.settings.classes.currentSlide),h(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","true");var a=this._attributes.slides,c=a.indexOf(this._attributes.currentSlide);this._attributes.previousSlide=this._attributes.currentSlide,this._attributes.currentSlide=a[c+1],this._attributes.nextSlide=a[c+2],"undefined"==typeof this._attributes.currentSlide&&"undefined"==typeof this._attributes.nextSlide?(this._attributes.currentSlide=a[0],this._attributes.nextSlide=a[1]):"undefined"==typeof this._attributes.nextSlide&&(this._attributes.nextSlide=a[0]),k(this._attributes.nextSlide),g(this._attributes.previousSlide,this.settings.classes.previousSlide),g(this._attributes.currentSlide,this.settings.classes.currentSlide),g(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","false"),g(this._attributes.container,this.settings.classes.directionNext),b(function(){h(this._attributes.container,this.settings.classes.directionNext)}.bind(this),this.settings.transitionDuration),this.settings.transitionDuration&&(g(this._attributes.container,this.settings.classes.animating),b(function(){h(this._attributes.container,this.settings.classes.animating)}.bind(this),this.settings.transitionDuration)),p(this),this.settings.afterChange.apply(this)},r.prototype.gotoSlide=function(a){this.settings.beforeChange.apply(this),this.stop(),h(this._attributes.previousSlide,this.settings.classes.previousSlide),h(this._attributes.currentSlide,this.settings.classes.currentSlide),h(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","true"),a--;var c=this._attributes.slides,d=c.indexOf(this._attributes.currentSlide);this._attributes.previousSlide=c[a-1],this._attributes.currentSlide=c[a],this._attributes.nextSlide=c[a+1],"undefined"==typeof this._attributes.previousSlide&&(this._attributes.previousSlide=c[c.length-1]),"undefined"==typeof this._attributes.nextSlide&&(this._attributes.nextSlide=c[0]),k(this._attributes.previousSlide),k(this._attributes.currentSlide),k(this._attributes.nextSlide),g(this._attributes.previousSlide,this.settings.classes.previousSlide),g(this._attributes.currentSlide,this.settings.classes.currentSlide),g(this._attributes.nextSlide,this.settings.classes.nextSlide),this._attributes.currentSlide.setAttribute("aria-hidden","false"),d>a?(g(this._attributes.container,this.settings.classes.directionPrevious),b(function(){h(this._attributes.container,this.settings.classes.directionPrevious)}.bind(this),this.settings.transitionDuration)):(g(this._attributes.container,this.settings.classes.directionNext),b(function(){h(this._attributes.container,this.settings.classes.directionNext)}.bind(this),this.settings.transitionDuration)),this.settings.transitionDuration&&(g(this._attributes.container,this.settings.classes.animating),b(function(){h(this._attributes.container,this.settings.classes.animating)}.bind(this),this.settings.transitionDuration)),p(this),this.settings.afterChange.apply(this)},r.prototype.destroy=function(){clearInterval(this._attributes.timerId),this._attributes.timerId=0,this._attributes.container.innerHTML="",Array.prototype.forEach.call(this._attributes.origChildren,function(a,b){this._attributes.container.appendChild(a)}.bind(this)),h(this._attributes.container,this.settings.classes.container),h(this._attributes.container,"iis-effect-"+this.settings.effect),this._attributes.container.style.height="",this.settings.onDestroy.apply(this)},{_hasClass:f,_addClass:g,_removeClass:h,Slider:r}}();