astro-mail/public/assets/js/jquery.imageslider.js

2 lines
2.4 KiB
JavaScript
Executable File

!function(e,i,t,n){var s="imageslider",l={slideItems:".is-item",slideContainer:".is-container",slideDistance:1,slideDuration:1,slideEasing:"linear",resizable:!1,reverse:!1,pause:!1};function d(t,n){var d=this;d.element=t,d.settings=e.extend({},l,n),d._defaults=l,d._name=s,e(i).on("load",function(){d.init()})}function a(i,t){i.width();var n=0;return t.each(function(){n+=e(this).width()}),n}d.prototype.init=function(){var t=this;t.$element=e(t.element),t.$slideContainer=t.$element.find(t.settings.slideContainer),t.$slideItems=t.$element.find(t.settings.slideItems),t.elementW=t.$element.width(),t.slideContainerW=a(t.$slideContainer,t.$slideItems),t.slideItemsLength=t.$slideItems.length,t.$slideContainer.width(t.slideContainerW),t.$element.css("overflow","hidden"),t.settings.resizable&&e(i).on("resize",function(){t.resizeContainer()}),t.settings.pause&&t.$slideContainer.hover(function(){t.stopSlide()},function(){t.startSlide()}),t.resizeContainer()},d.prototype.startSlide=function(){var e=this,i=e.$slideContainer.find(e.settings.slideItems).eq(0),t=e.$slideContainer.find(e.settings.slideItems).eq(e.slideItemsLength-1),n=i.width(),s=t.width();if(i.is(":animated"))return!1;if(e.settings.reverse){if(parseInt(i.css("margin-left"),10)>=0)return t.prependTo(e.$slideContainer).css("margin-left",-s),e.startSlide(),!1;i.animate({marginLeft:parseInt(i.css("margin-left"),10)+e.settings.slideDistance},e.settings.slideDuration,e.settings.slideEasing,function(){e.startSlide()})}else i.animate({marginLeft:parseInt(i.css("margin-left"),10)-e.settings.slideDistance},e.settings.slideDuration,e.settings.slideEasing,function(){Math.abs(parseInt(i.css("margin-left"),10))>n&&i.appendTo(e.$slideContainer).css("margin-left",0),e.startSlide()})},d.prototype.stopSlide=function(){this.$slideItems.stop()},d.prototype.resizeContainer=function(){var i=this,t=i.$element.width(),n=i.slideContainerW;i.stopSlide(),function i(t,n,s,l){n.each(function(){if(l>2*s)return!1;var i=e(this).clone().css("margin-left",0);i.appendTo(t),l+=i.width()})}(i.$slideContainer,i.$slideItems,t,n),i.$slideItems=i.$element.find(i.settings.slideItems),i.slideContainerW=a(i.$slideContainer,i.$slideItems),i.elementW=t,i.$slideContainer.width(i.slideContainerW),i.slideItemsLength=i.$slideItems.length,i.startSlide()},e.fn[s]=function(i){return this.each(function(){e.data(this,"plugin_"+s)||e.data(this,"plugin_"+s,new d(this,i))}),this}}(jQuery,window,document,void 0);