forked from woocommerce/FlexSlider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.flexslider-min.js
11 lines (11 loc) · 14 KB
/
jquery.flexslider-min.js
1
2
3
4
5
6
7
8
9
10
11
/*
* jQuery FlexSlider v1.8
* http://www.woothemes.com/flexslider/
*
* Copyright 2012 WooThemes
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Contributing Author: Tyler Smith
*/
;(function(a){a.flexslider=function(e,d){var f=a(e);a.data(e,"flexslider",f);f.init=function(){var q,g,x,y,l,k,D,s,A,v,r,B,z,p,w,t,C,u;f.vars=a.extend({},a.flexslider.defaults,d);a.data(e,"flexsliderInit",true);f.container=a(".slides",f).eq(0).attr({role:"presentation"});f.slides=a(".slides:first > li",f).attr({role:"tabpanel","aria-hidden":"true","aria-expanded":"false",tabindex:"-1"});f.count=f.slides.length;f.animating=false;f.currentSlide=f.vars.slideToStart;f.animatingTo=f.currentSlide;f.atEnd=(f.currentSlide==0)?true:false;f.eventType=("ontouchstart" in document.documentElement)?"touchstart":"click";f.cloneCount=0;f.cloneOffset=0;f.manualPause=false;f.vertical=(f.vars.slideDirection=="vertical");f.prop=(f.vertical)?"top":"marginLeft";f.args={};f.transitions="webkitTransition" in document.body.style&&f.vars.useCSS;if(f.transitions){f.prop="-webkit-transform"}if(f.vars.controlsContainer!=""){f.controlsContainer=a(f.vars.controlsContainer).eq(a(".slides").index(f.container));f.containerExists=f.controlsContainer.length>0}if(f.vars.manualControls!=""){f.manualControls=a(f.vars.manualControls,((f.containerExists)?f.controlsContainer:f));f.manualExists=f.manualControls.length>0}if(f.vars.randomize){f.slides.sort(function(){return(Math.round(Math.random())-0.5)});f.container.empty().append(f.slides)}if(f.vars.animation.toLowerCase()=="slide"){if(f.transitions){f.setTransition(0)}f.css({overflow:"hidden"});if(f.vars.animationLoop){f.cloneCount=2;f.cloneOffset=1;f.container.append(f.slides.filter(":first").clone().addClass("clone").attr({id:f.slides.filter(":first").attr("id")+"_clone",role:"presentation"})).prepend(f.slides.filter(":last").clone().addClass("clone").attr({id:f.slides.filter(":last").attr("id")+"_clone",role:"presentation"}))}f.newSlides=a(".slides:first > li",f);q=(-1*(f.currentSlide+f.cloneOffset));if(f.vertical){f.newSlides.css({display:"block",width:"100%","float":"left"});f.container.height((f.count+f.cloneCount)*200+"%").css("position","absolute").width("100%");setTimeout(function(){f.css({position:"relative"}).height(f.slides.filter(":first").height());f.args[f.prop]=(f.transitions)?"translate3d(0,"+q*f.height()+"px,0)":q*f.height()+"px";f.container.css(f.args);f.newSlides.filter(".clone").find(":tabbable").attr("tabindex","-1");f.fixTabOrder(f.currentSlide)},100)}else{f.args[f.prop]=(f.transitions)?"translate3d("+q*f.width()+"px,0,0)":q*f.width()+"px";f.container.width((f.count+f.cloneCount)*200+"%").css(f.args);setTimeout(function(){f.newSlides.width(f.width()).css({"float":"left",display:"block"});f.newSlides.filter(".clone").find(":tabbable").attr("tabindex","-1");f.fixTabOrder(f.currentSlide)},100)}}else{f.transitions=false;f.slides.css({width:"100%","float":"left",marginRight:"-100%"}).eq(f.currentSlide).fadeIn(f.vars.animationDuration,function(){f.fixTabOrder(f.currentSlide)})}if(f.vars.controlNav){if(f.manualExists){f.controlNav=f.manualControls}else{g=a('<ol role="tablist" class="flex-control-nav"></ol>');x=1;for(y=0;y<f.count;y++){l=f.slides.eq(y);k=l.attr("id")||"tabpanel_"+y+"_"+(new Date()).getTime();D=k+"_tab";s=(l.attr("aria-label")||l.attr("title")||x);g.append('<li role="presentation"><a id="'+D+'" tabindex="-1" role="tab" aria-controls="'+k+'" aria-selected="false">'+s+"</a></li>");l.attr({"aria-labelledby":D});x++}if(f.containerExists){a(f.controlsContainer).prepend(g);f.controlNav=a(".flex-control-nav li a",f.controlsContainer)}else{f.prepend(g);f.controlNav=a(".flex-control-nav li a",f)}}f.controlNav.eq(f.currentSlide).addClass("active").attr({tabindex:"0","aria-selected":"true"});f.controlNav.bind(f.eventType,function(j){j.preventDefault();var E=a(this),i;if(!E.hasClass("active")){i=f.controlNav.index(E);(i>f.currentSlide)?f.direction="next":f.direction="prev";f.flexAnimate(i,f.vars.pauseOnAction);f.controlNav.removeClass("active").attr({tabindex:"-1","aria-selected":"false"}).eq(i).addClass("active").attr({tabindex:"0","aria-selected":"true"}).focus()}})}f.setAriaHidden(f.currentSlide);if(f.vars.directionNav){A=a('<ul class="flex-direction-nav"><li><a class="prev" href="#">'+f.vars.prevText+'</a></li><li><a class="next" href="#">'+f.vars.nextText+"</a></li></ul>");if(f.containerExists){a(f.controlsContainer).append(A);f.directionNav=a(".flex-direction-nav li a",f.controlsContainer)}else{f.append(A);f.directionNav=a(".flex-direction-nav li a",f)}if(!f.vars.animationLoop){if(f.currentSlide==0){f.directionNav.filter(".prev").addClass("disabled")}else{if(f.currentSlide==f.count-1){f.directionNav.filter(".next").addClass("disabled")}}}f.directionNav.bind(f.eventType,function(i){i.preventDefault();var j=(a(this).hasClass("next"))?f.getTarget("next"):f.getTarget("prev");if(f.canAdvance(j)){f.flexAnimate(j,f.vars.pauseOnAction)}})}if(f.vars.keyboardNav&&a("ul.slides").length==1){function o(i){if(f.animating){return}else{if(i.keyCode!=39&&i.keyCode!=37&&i.keyCode!=38&&i.keyCode!=40){return}else{var j=-1;if(f.vertical){if(i.keyCode==40){j=f.getTarget("next")}else{if(i.keyCode==38){j=f.getTarget("prev")}}}else{if(i.keyCode==39){j=f.getTarget("next")}else{if(i.keyCode==37){j=f.getTarget("prev")}}}if(f.canAdvance(j)){f.flexAnimate(j,f.vars.pauseOnAction)}}}}a(document).bind("keyup",o)}if(f.vars.mousewheel){f.mousewheelEvent=(/Firefox/i.test(navigator.userAgent))?"DOMMouseScroll":"mousewheel";f.bind(f.mousewheelEvent,function(E){E.preventDefault();E=E?E:window.event;var i=E.detail?E.detail*-1:E.originalEvent.wheelDelta/40,j=(i<0)?f.getTarget("next"):f.getTarget("prev");if(f.canAdvance(j)){f.flexAnimate(j,f.vars.pauseOnAction)}})}if(f.vars.slideshow){if(f.vars.pauseOnHover&&f.vars.slideshow){f.hover(function(){f.pause()},function(){if(!f.manualPause){f.resume()}})}f.animatedSlides=setInterval(f.animateSlides,f.vars.slideshowSpeed)}if(f.vars.pausePlay){v=a('<div class="flex-pauseplay"><span></span></div>');if(f.containerExists){f.controlsContainer.append(v);f.pausePlay=a(".flex-pauseplay span",f.controlsContainer)}else{f.append(v);f.pausePlay=a(".flex-pauseplay span",f)}r=(f.vars.slideshow)?"pause":"play";f.pausePlay.addClass(r).text((r=="pause")?f.vars.pauseText:f.vars.playText);f.pausePlay.bind(f.eventType,function(i){i.preventDefault();if(a(this).hasClass("pause")){f.pause();f.manualPause=true}else{f.resume();f.manualPause=false}})}if("ontouchstart" in document.documentElement&&f.vars.touch){u=false;f.each(function(){if("ontouchstart" in document.documentElement){this.addEventListener("touchstart",m,false)}});function m(i){if(f.animating){i.preventDefault()}else{if(i.touches.length==1){f.pause();w=(f.vertical)?f.height():f.width();C=Number(new Date());p=(f.vertical)?(f.currentSlide+f.cloneOffset)*f.height():(f.currentSlide+f.cloneOffset)*f.width();B=(f.vertical)?i.touches[0].pageY:i.touches[0].pageX;z=(f.vertical)?i.touches[0].pageX:i.touches[0].pageY;f.setTransition(0);this.addEventListener("touchmove",n,false);this.addEventListener("touchend",h,false)}}}function n(i){t=(f.vertical)?B-i.touches[0].pageY:B-i.touches[0].pageX;u=(f.vertical)?(Math.abs(t)<Math.abs(i.touches[0].pageX-z)):(Math.abs(t)<Math.abs(i.touches[0].pageY-z));if(!u){i.preventDefault();if(f.vars.animation=="slide"&&f.transitions){if(!f.vars.animationLoop){t=t/((f.currentSlide==0&&t<0||f.currentSlide==f.count-1&&t>0)?(Math.abs(t)/w+2):1)}f.args[f.prop]=(f.vertical)?"translate3d(0,"+(-p-t)+"px,0)":"translate3d("+(-p-t)+"px,0,0)";f.container.css(f.args)}}}function h(j){f.animating=false;if(f.animatingTo==f.currentSlide&&!u&&!(t==null)){var i=(t>0)?f.getTarget("next"):f.getTarget("prev");if(f.canAdvance(i)&&Number(new Date())-C<550&&Math.abs(t)>20||Math.abs(t)>w/2){f.flexAnimate(i,f.vars.pauseOnAction)}else{if(f.vars.animation!=="fade"){f.flexAnimate(f.currentSlide,f.vars.pauseOnAction)}}}this.removeEventListener("touchmove",n,false);this.removeEventListener("touchend",h,false);B=null;z=null;t=null;p=null}}if(f.vars.animation.toLowerCase()=="slide"){a(window).resize(function(){if(!f.animating&&f.is(":visible")){if(f.vertical){f.height(f.slides.filter(":first").height());f.args[f.prop]=(-1*(f.currentSlide+f.cloneOffset))*f.slides.filter(":first").height()+"px";if(f.transitions){f.setTransition(0);f.args[f.prop]=(f.vertical)?"translate3d(0,"+f.args[f.prop]+",0)":"translate3d("+f.args[f.prop]+",0,0)"}f.container.css(f.args)}else{f.newSlides.width(f.width());f.args[f.prop]=(-1*(f.currentSlide+f.cloneOffset))*f.width()+"px";if(f.transitions){f.setTransition(0);f.args[f.prop]=(f.vertical)?"translate3d(0,"+f.args[f.prop]+",0)":"translate3d("+f.args[f.prop]+",0,0)"}f.container.css(f.args)}}})}f.vars.start(f)};f.flexAnimate=function(j,i){if(!f.animating&&f.is(":visible")){var h,g=a(document.activeElement);f.animating=true;f.animatingTo=j;f.vars.before(f);if(i){f.pause()}if(f.vars.controlNav){f.controlNav.removeClass("active").attr({tabindex:"-1","aria-selected":"false"}).eq(j).addClass("active").attr({tabindex:"0","aria-selected":"true"});if(g&&(f.controlNav.index(g)!=-1||(f.isFocusInSlider()&&f.slides.eq(j).find(g).length==0)&&!(f.directionNav&&f.directionNav.index(g)!=-1))){f.controlNav.eq(j).focus()}}f.atEnd=(j==0||j==f.count-1)?true:false;if(!f.vars.animationLoop&&f.vars.directionNav){if(j==0){f.directionNav.removeClass("disabled").filter(".prev").addClass("disabled")}else{if(j==f.count-1){f.directionNav.removeClass("disabled").filter(".next").addClass("disabled")}else{f.directionNav.removeClass("disabled")}}}if(!f.vars.animationLoop&&j==f.count-1){f.pause();f.vars.end(f)}if(f.vars.animation.toLowerCase()=="slide"){h=(f.vertical)?f.slides.filter(":first").height():f.slides.filter(":first").width();if(f.currentSlide==0&&j==f.count-1&&f.vars.animationLoop&&f.direction!="next"){f.slideString="0px"}else{if(f.currentSlide==f.count-1&&j==0&&f.vars.animationLoop&&f.direction!="prev"){f.slideString=(-1*(f.count+1))*h+"px"}else{f.slideString=(-1*(j+f.cloneOffset))*h+"px"}}f.args[f.prop]=f.slideString;if(f.transitions){f.setTransition(f.vars.animationDuration);f.args[f.prop]=(f.vertical)?"translate3d(0,"+f.slideString+",0)":"translate3d("+f.slideString+",0,0)";f.container.css(f.args).one("webkitTransitionEnd transitionend",function(){f.wrapup(h)})}else{f.container.animate(f.args,f.vars.animationDuration,function(){f.wrapup(h)})}}else{f.slides.eq(f.currentSlide).fadeOut(f.vars.animationDuration);f.slides.eq(j).fadeIn(f.vars.animationDuration,function(){f.wrapup()})}}};f.wrapup=function(g){if(f.vars.animation=="slide"){if(f.currentSlide==0&&f.animatingTo==f.count-1&&f.vars.animationLoop){f.args[f.prop]=(-1*f.count)*g+"px";if(f.transitions){f.setTransition(0);f.args[f.prop]=(f.vertical)?"translate3d(0,"+f.args[f.prop]+",0)":"translate3d("+f.args[f.prop]+",0,0)"}f.container.css(f.args)}else{if(f.currentSlide==f.count-1&&f.animatingTo==0&&f.vars.animationLoop){f.args[f.prop]=-1*g+"px";if(f.transitions){f.setTransition(0);f.args[f.prop]=(f.vertical)?"translate3d(0,"+f.args[f.prop]+",0)":"translate3d("+f.args[f.prop]+",0,0)"}f.container.css(f.args)}}}f.animating=false;f.currentSlide=f.animatingTo;f.setAriaHidden(f.currentSlide);f.fixTabOrder(f.currentSlide);f.vars.after(f)};f.animateSlides=function(){if(!f.animating&&!f.isFocusInSlider()){f.flexAnimate(f.getTarget("next"))}};f.pause=function(){clearInterval(f.animatedSlides);if(f.vars.pausePlay){f.pausePlay.removeClass("pause").addClass("play").text(f.vars.playText)}};f.resume=function(){f.animatedSlides=setInterval(f.animateSlides,f.vars.slideshowSpeed);if(f.vars.pausePlay){f.pausePlay.removeClass("play").addClass("pause").text(f.vars.pauseText)}};f.canAdvance=function(g){if(!f.vars.animationLoop&&f.atEnd){if(f.currentSlide==0&&g==f.count-1&&f.direction!="next"){return false}else{if(f.currentSlide==f.count-1&&g==0&&f.direction=="next"){return false}else{return true}}}else{return true}};f.getTarget=function(g){f.direction=g;if(g=="next"){return(f.currentSlide==f.count-1)?0:f.currentSlide+1}else{return(f.currentSlide==0)?f.count-1:f.currentSlide-1}};f.setTransition=function(g){f.container.css({"-webkit-transition-duration":(g/1000)+"s"})};f.setAriaHidden=function(g){f.slides.attr({"aria-hidden":"true","aria-expanded":"false"}).eq(g).attr({"aria-hidden":"false","aria-expanded":"true"})};f.fixTabOrder=function(g){f.slides.not(g).attr("tabindex","-1").find(":tabbable").each(function(){a(this).addClass("not-tabbable");if(a(this).attr("tabindex")){a(this).data("cached-tabindex",a(this).attr("tabindex"))}a(this).attr("tabindex","-1")});f.slides.eq(g).attr("tabindex","0").find(".not-tabbable").each(function(){a(this).removeClass("not-tabbable").removeAttr("tabindex");if(a(this).data("cached-tabindex")){a(this).attr("tabindex",a(this).data("cached-tabindex")).removeData("cached-tabindex")}})};f.isFocusInSlider=function(){return f.find(a(document.activeElement)).length==1};f.init()};a.flexslider.defaults={animation:"fade",slideDirection:"horizontal",slideshow:true,slideshowSpeed:7000,animationDuration:600,directionNav:true,controlNav:true,keyboardNav:true,mousewheel:false,prevText:"Previous",nextText:"Next",pausePlay:false,pauseText:"Pause",playText:"Play",randomize:false,slideToStart:0,animationLoop:true,pauseOnAction:true,pauseOnHover:false,useCSS:true,touch:true,controlsContainer:"",manualControls:"",start:function(){},before:function(){},after:function(){},end:function(){}};a.fn.flexslider=function(d){return this.each(function(){var e=a(this).find(".slides > li");if(e.length===1){e.fadeIn(400);if(d&&d.start){d.start(a(this))}}else{if(a(this).data("flexsliderInit")!=true){new a.flexslider(this,d)}}})};function c(f,d){var i=f.nodeName.toLowerCase(),h,g,e;if("area"===i){h=f.parentNode;g=h.name;if(!f.href||!g||h.nodeName.toLowerCase()!=="map"){return false}e=a("img[usemap=#"+g+"]")[0];return !!e&&b(e)}return(/input|select|textarea|button|object/.test(i)?!f.disabled:"a"==i?f.href||d:d)&&b(f)}function b(d){return !a(d).parents().andSelf().filter(function(){return a.curCSS(this,"visibility")==="hidden"||a.expr.filters.hidden(this)}).length}a.extend(a.expr[":"],{data:function(f,e,d){return !!a.data(f,d[3])},focusable:function(d){return c(d,!isNaN(a.attr(d,"tabindex")))},tabbable:function(f){var d=a.attr(f,"tabindex"),e=isNaN(d);return(e||d>=0)&&c(f,!e)}})})(jQuery);