-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.easyfader.min.js
20 lines (19 loc) · 5.1 KB
/
jquery.easyfader.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
* EASYFADER - An Ultralight Fading Slideshow For Responsive Layouts
* Version: 2.0.5
* License: Creative Commons Attribution 3.0 Unported - CC BY 3.0
* http://creativecommons.org/licenses/by/3.0/
* This software may be used freely on commercial and non-commercial projects with attribution to the author/copyright holder.
* Author: Patrick Kunka
* Copyright 2013 Patrick Kunka, All Rights Reserved
*/
(function(d){d.fn.removeStyle=function(a){return this.each(function(){var c=d(this);a=a.replace(/\s+/g,"");var b=a.split(",");d.each(b,function(){var a=RegExp(this.toString()+"[^;]+;?","g");c.attr("style",function(c,b){if(b)return b.replace(a,"")})});"undefined"!==typeof c.attr("style")&&(b=d.trim(c.attr("style").replace(/\s{2,}/g," ")),c.attr("style",b),""==b&&c.removeAttr("style"))})};EasyFader=function(){this.slideDur=7E3;this.effectDur=800;this.onChangeEnd=this.onChangeStart=null;this.slideSelector=
".slide";this.changing=!1;this.effect="fade";this.pagerListClass="pager-list";this.autoCycle=this.firstLoad=this.fadeOnLoad=!0;this.$pagers=this.$pagerList=this.totalSlides=this.$slides=this.newSlide=this.activeIndex=this.slideTimer=null};EasyFader.prototype={constructor:EasyFader,instances:{},init:function(a,c){c&&d.extend(this,c);this.$container=d(a);this.$slides=this.$container.find(this.slideSelector);this.totalSlides=this.$slides.length;this.$pagerList=this.$container.find("."+this.pagerListClass);
var b;if(d.support.leadingWhitespace)a:{b=this.$container[0];for(var e=["Webkit","Moz","O","ms"],f=0;f<e.length;f++)if(e[f]+"Transition"in b.style){b="-"+e[f].toLowerCase()+"-";break a}b="transition"in b.style?"":!1}else b=!1;this.prefix=b;if(1<this.totalSlides){for(b=0;b<this.totalSlides;b++)this.$pagerList.append('<li class="pager" data-target="'+b+'">'+(b+1)+"</li>");this.bindHandlers()}if("undefined"!==typeof this[this.effect+"Init"])this[this.effect+"Init"]();this.activeIndex||(this.activeIndex=
0);this.updateInfo();this.$pagers=this.$pagerList.find(".pager");this.$pagers.eq(this.activeIndex).addClass("active");this.fadeOnLoad?this.fadeSlides(this.activeIndex+1,0):this.autoCycle&&1<this.totalSlides&&this.waitForNext()},updateInfo:function(){this.info={$container:this.$container,effect:this.effect,activeIndex:this.activeIndex,$activeSlide:this.$slides.eq(this.activeIndex),totalSlides:this.$slides.length}},bindHandlers:function(){for(key in this.handlers)this.handlers[key].apply(this)},handlers:{"default":function(){var a=
this;a.$container.find(".pager").on("click",function(){var c=d(this).attr("data-target");clearTimeout(a.slideTimer);a._changeSlides(c)});d(window).on("keydown",function(c){c=c.keyCode;if(39==c||37==c)c=39==c?"next":"prev",clearTimeout(a.slideTimer),a._changeSlides(c)})}},cleanUp:function(a,c){if(this.firstLoad&&this.fadeOnLoad)this.fadeCleanUp(a,c);else this[this.effect+"CleanUp"](a,c);this.activeIndex=c;this.changing=!1;this.updateInfo();"function"==typeof this.callback&&(this.callback.call(this,
this.info),delete this.callback);"function"==typeof this.onChangeEnd&&this.onChangeEnd.call(this,this.info);this.firstLoad=!1;this.autoCycle&&this.waitForNext()},fadeCleanUp:function(a,c){var b=this.$slides.eq(a);d.support.opacity?b.removeStyle("opacity, z-index"):b.removeAttr("style");this.$slides.eq(c).removeStyle(this.prefix+"transition, transition")},animateSlides:function(a,c){if(this.changing)return!1;this.changing=!0;this.$pagers.removeClass("active").eq(this.newSlide).addClass("active");"function"!=
typeof this.onChangeStart||this.firstLoad||this.onChangeStart.call(this,this.info);this[this.effect+"Slides"](a,c)},fadeSlides:function(a,c){var b=this;b.$slides.eq(a).css("z-index",2);b.$slides.eq(c).css("z-index",3);if(b.prefix){var e={};e[b.prefix+"transition"]="opacity "+b.effectDur+"ms";e.opacity=1;b.$slides.eq(c).css(e);setTimeout(function(){b.cleanUp(a,c)},b.effectDur)}else b.$slides.eq(c).animate({opacity:1},b.effectDur,function(){b.cleanUp(a,c)})},_changeSlides:function(a){"next"==a?(this.newSlide=
1*this.activeIndex+1,this.newSlide>this.totalSlides-1&&(this.newSlide=0)):"prev"==a?(this.newSlide=1*this.activeIndex-1,0>this.newSlide&&(this.newSlide=this.totalSlides-1)):this.newSlide=a;this.animateSlides(this.activeIndex,this.newSlide)},waitForNext:function(){var a=this;a.slideTimer=setTimeout(function(){a._changeSlides("next")},a.slideDur)},getPrefixedCSS:function(a,c,b){var e={};for(i=0;2>i;i++){var d=0==i?this.prefix:"";b?e[d+a]=d+c:e[d+a]=c}return e},pause:function(){clearTimeout(this.slideTimer)},
play:function(a){this.autoCycle&&(a?this.waitForNext():this._changeSlides("next"))},changeSlides:function(a,c){this.callback=c;a="undefined"!==typeof a?a:"next";clearTimeout(this.slideTimer);this._changeSlides(a)},getOption:function(a){return this[a]},setOptions:function(a){d.extend(this,a)}};d.fn.easyFader=function(){var a=arguments,c=[],b;b=this.each(function(){if(a&&"string"===typeof a[0]){var b=EasyFader.prototype.instances[this.id][a[0]](a[1],a[2]);b&&c.push(b)}else this.id=this.id?this.id:"EasyFader"+
("00000"+(16777216*Math.random()<<0).toString(16)).substr(-6).toUpperCase(),b=new EasyFader,b.instances[this.id]||(b.instances[this.id]=b,b.init(this,a[0]))});return c.length?1<c.length?c:c[0]:b}})(jQuery);