This repository has been archived by the owner on Oct 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjquery.simplebanner.min.js
1 lines (1 loc) · 3.29 KB
/
jquery.simplebanner.min.js
1
!function(a,b){"use strict";var c=function(b,c){this.element=b,this._paused=!1,this._timer={},this._currentBanner={},this._newBanner={},this._bannerWidth=0,this._bannerCount=0,this.options=a.extend({arrows:!0,indicators:!0,pauseOnHover:!0,autoRotate:!0,maxRotations:null,rotateTimeout:5e3,animTime:300,onChange:null},c),this.init()};c.prototype.init=function(){var a=this.element.find(".bannerList li");this._bannerCount=a.length,this._bannerWidth=a.outerWidth(),this._rotationCount=0,this._bannerWidth||(this._bannerWidth=this.element.width()),this._currentBanner=a.first().addClass("current"),this.options.indicators?this.buildIndicators():this.element.addClass("hiddenIndicators"),this.options.arrows||this.element.addClass("hiddenArrows"),this._bannerCount>1&&this.options.autoRotate&&this.toggleTimer(),this.bindEvents()},c.prototype.bindEvents=function(){var b=this;b.options.indicators&&b.element.find(".bannerIndicator").on({click:function(){var c=a(this);if(!c.hasClass("active")){var d=c.index();b._newBanner=b.element.find(".bannerList li:eq("+d+")"),b.goToBanner(d)}}}),b.options.arrows&&b.element.find(".bannerControlsWpr").on({click:function(){a(this).hasClass("bannerControlsPrev")?b.previousBanner():b.nextBanner()}}),b.options.pauseOnHover&&b.options.autoRotate&&b.element.on({mouseenter:function(){b.toggleTimer(!0)},mouseleave:function(){b.toggleTimer(!1)}})},c.prototype.nextBanner=function(){this._currentBanner.next().length?this._newBanner=this._currentBanner.next():(this._newBanner=this.element.find(".bannerList li:first"),this._rotationCount++),this.goToBanner(this._newBanner.index())},c.prototype.previousBanner=function(){this._currentBanner.prev().length?this._newBanner=this._currentBanner.prev():this._newBanner=this.element.find(".bannerList li:last"),this.goToBanner(this._newBanner.index())},c.prototype.goToBanner=function(a){var b=this;b._currentBanner.removeClass("current"),b.element.find(".bannerIndicators .current").removeClass("current"),b._currentBanner=b._newBanner,b._currentBanner.addClass("current"),b.element.find(".bannerIndicators li:eq("+a+")").addClass("current"),b.element.find(".bannerList").stop(!1,!0).animate({marginLeft:-a*b._bannerWidth},b.options.animTime),"function"==typeof b.options.onChange&&b.options.onChange(a)},c.prototype.buildIndicators=function(){var a=this,b=a.element.find(".bannerIndicators ul");a.element.find(".bannerList li").each(function(){b.append('<li class="bannerIndicator"></li>')}),b.find("li:first").addClass("current")},c.prototype.toggleTimer=function(a){var b=this;clearTimeout(b._timer),!a&&(null===this.options.maxRotations||this._rotationCount<this.options.maxRotations)&&(b._timer=setTimeout(function(){b.nextBanner(),b.toggleTimer(!1)},b.options.rotateTimeout))},a.fn.simplebanner=function(b){var d=!1,e=!1,f=[];return"string"==typeof b&&(f=[].slice.call(arguments,0)),this.each(function(){var g=a(this),h=g.data("bannerInstance");if(g.attr("id")||g.attr("id","simpleBanner-"+(a.fn.simplebanner._instances.length+1)),h&&b)if("object"==typeof b)e=a.extend(h.options,b);else if("options"===b)e=h.options;else{if("function"!=typeof h[b])throw new Error('Simple Banner has no option/method named "'+d+'"');e=h[b].apply(h,f.slice(1))}else h=new c(g,b||{}),g.data("bannerInstance",h),a.fn.simplebanner._instances.push(h)}),e||this},a.fn.simplebanner._instances=[]}(jQuery,window);