forked from stevenwanderski/bxslider-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.bxslider.min.js
10 lines (10 loc) · 16.4 KB
/
jquery.bxslider.min.js
1
2
3
4
5
6
7
8
9
10
/**
* BxSlider v4.0 - Fully loaded, responsive content slider
* http://bxslider.com
*
* Copyright 2012, Steven Wanderski - http://stevenwanderski.com - http://bxcreative.com
* Written while drinking Belgian ales and listening to jazz
*
* Released under the WTFPL license - http://sam.zoy.org/wtfpl/
*/
(function(t){var e={mode:"horizontal",slideSelector:"",infiniteLoop:!0,hideControlOnEnd:!1,speed:500,easing:null,slideMargin:0,startSlide:0,captions:!1,ticker:!1,tickerHover:!1,adaptiveHeight:!1,adaptiveHeightSpeed:500,touchEnabled:!0,swipeThreshold:50,video:!1,useCSS:!0,pager:!0,pagerType:"full",pagerShortSeparator:" / ",pagerSelector:null,buildPager:null,pagerCustom:null,controls:!0,nextText:"Next",prevText:"Prev",nextSelector:null,prevSelector:null,autoControls:!1,startText:"Start",stopText:"Stop",autoControlsCombine:!1,autoControlsSelector:null,auto:!1,pause:4e3,autoStart:!0,autoDirection:"next",autoHover:!1,autoDelay:0,minSlides:1,maxSlides:1,moveSlides:0,slideWidth:0,onSliderLoad:function(){},onSlideBefore:function(){},onSlideAfter:function(){},onSlideNext:function(){},onSlidePrev:function(){}};t.fn.bxSlider=function(i){if(this.length>1)return this.each(function(){t(this).bxSlider(i)}),this;var n={},s=this,o=function(){n.settings=t.extend({},e,i),n.children=s.children(n.settings.slideSelector),n.active={index:n.settings.startSlide},n.carousel=n.settings.minSlides>1||n.settings.maxSlides>1,n.minThreshold=n.settings.minSlides*n.settings.slideWidth+(n.settings.minSlides-1)*n.settings.slideMargin,n.maxThreshold=n.settings.maxSlides*n.settings.slideWidth+(n.settings.maxSlides-1)*n.settings.slideMargin,n.working=!1,n.controls={},n.animProp=n.settings.mode=="vertical"?"top":"left",n.usingCSS=n.settings.useCSS&&n.settings.mode!="fade"&&function(){var t=document.createElement("div"),e=["WebkitPerspective","MozPerspective","OPerspective","msPerspective"];for(var i in e)if(t.style[e[i]]!==void 0)return n.cssPrefix=e[i].replace("Perspective","").toLowerCase(),n.animProp="-"+n.cssPrefix+"-transform",!0;return!1}(),r()},r=function(){if(s.wrap('<div class="bx-wrapper"><div class="bx-viewport"></div></div>'),n.viewport=s.parent(),n.loader=t('<div class="bx-loading" />'),n.viewport.prepend(n.loader),s.css({width:n.settings.mode=="horizontal"?"2800%":"auto",height:0,overflow:"hidden",position:"relative",margin:0,padding:0}),n.usingCSS&&n.settings.easing?s.css("-"+n.cssPrefix+"-transition-timing-function",n.settings.easing):n.settings.easing||(n.settings.easing="swing"),n.viewport.css({width:"100%",height:"50",overflow:"hidden",position:"relative"}),n.children.css({"float":n.settings.mode=="horizontal"?"left":"none",position:"relative",width:l(),listStyle:"none",marginRight:n.settings.mode=="horizontal"?n.settings.slideMargin:0,marginBottom:n.settings.mode=="vertical"?n.settings.slideMargin:0}),n.settings.mode=="fade"&&(n.children.css({position:"absolute",zIndex:0,display:"none"}),n.children.eq(n.settings.startSlide).css({zIndex:50,display:"block"})),n.controls.el=t('<div class="bx-controls" />'),n.settings.captions&&m(),n.settings.infiniteLoop&&!n.carousel&&n.settings.mode!="fade"&&!n.settings.ticker){var e=n.children.first().clone().addClass("bx-clone"),i=n.children.last().clone().addClass("bx-clone");s.append(e).prepend(i)}n.active.last=n.settings.startSlide==c()-1,n.settings.video&&s.fitVids(),n.settings.ticker||(n.settings.pager&&v(),n.settings.controls&&f(),n.settings.auto&&n.settings.autoControls&&x(),(n.settings.controls||n.settings.autoControls||n.settings.pager)&&n.viewport.after(n.controls.el)),s.children().imagesLoaded(function(){n.loader.remove(),s.css("overflow","visible"),u(),n.settings.mode=="vertical"&&(n.settings.adaptiveHeight=!0),n.viewport.animate({height:a()},200,function(){n.settings.onSliderLoad()}),n.settings.auto&&n.settings.autoStart&&y(),n.settings.ticker&&z(),n.settings.pager&&E(n.settings.startSlide),n.settings.controls&&k(),n.settings.touchEnabled&&!n.settings.ticker&&L()})},a=function(){var e=0,i="";return i=n.settings.mode=="vertical"||n.settings.adaptiveHeight?n.carousel?n.active.last?n.children.slice(n.children.length-n.settings.minSlides,n.children.length):n.children.slice(n.active.index*g(),n.settings.minSlides+n.active.index*g()):n.children.eq(n.active.index):n.children,n.settings.mode=="vertical"?(i.each(function(){e+=t(this).outerHeight()}),n.settings.slideMargin>0&&(e+=n.settings.slideMargin*(n.settings.minSlides-1))):e=Math.max.apply(Math,i.map(function(){return t(this).outerHeight()}).get()),e},l=function(){var t=n.settings.slideWidth,e=n.viewport.width();return n.settings.slideWidth==0?t=e:e>n.maxThreshold?t=(e-n.settings.slideMargin*(n.settings.maxSlides-1))/n.settings.maxSlides:n.minThreshold>e&&(t=(e-n.settings.slideMargin*(n.settings.minSlides-1))/n.settings.minSlides),t},d=function(){var t=1;if(n.settings.mode=="horizontal")if(n.minThreshold>n.viewport.width())t=n.settings.minSlides;else if(n.viewport.width()>n.maxThreshold)t=n.settings.maxSlides;else{var e=n.children.first().width();t=Math.floor(n.viewport.width()/e)}else n.settings.mode=="vertical"&&(t=n.settings.minSlides);return t},c=function(){var t=0;if(n.settings.moveSlides>0){var e=0,i=0;while(n.children.length>e)++t,e=i+d(),i+=d()>=n.settings.moveSlides?n.settings.moveSlides:d()}else t=Math.ceil(n.children.length/d());return t},g=function(){return n.settings.moveSlides>0&&d()>=n.settings.moveSlides?n.settings.moveSlides:d()},u=function(){if(n.active.last){if(n.settings.mode=="horizontal"){var t=n.children.last(),e=t.position();h(-(e.left-(n.viewport.width()-t.width())),"reset",0)}else if(n.settings.mode=="vertical"){var i=n.children.length-n.settings.minSlides,e=n.children.eq(i).position();h(-e.top,"reset",0)}}else{var e=n.children.eq(n.active.index*g()).position();n.active.index==c()-1&&(n.active.last=!0),e!=void 0&&(n.settings.mode=="horizontal"?h(-e.left,"reset",0):n.settings.mode=="vertical"&&h(-e.top,"reset",0))}},h=function(t,e,i,o){if(n.usingCSS){var r=n.settings.mode=="vertical"?"translate3d(0, "+t+"px, 0)":"translate3d("+t+"px, 0, 0)";s.css("-"+n.cssPrefix+"-transition-duration",i/1e3+"s"),e=="slide"?(s.css(n.animProp,r),s.bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){s.unbind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd"),P()})):e=="reset"?s.css(n.animProp,r):e=="ticker"&&(s.css("-"+n.cssPrefix+"-transition-timing-function","linear"),s.css(n.animProp,r),s.bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){s.unbind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd"),h(o.resetValue,"reset",0),M()}))}else{var a={};a[n.animProp]=t,e=="slide"?s.animate(a,i,n.settings.easing,function(){P()}):e=="reset"?s.css(n.animProp,t):e=="ticker"&&s.animate(a,speed,"linear",function(){h(o.resetValue,"reset",0),M()})}},p=function(){var e="";pagerQty=c();for(var i=0;pagerQty>i;i++){var s="";n.settings.buildPager&&t.isFunction(n.settings.buildPager)?(s=n.settings.buildPager(i),n.pagerEl.addClass("bx-custom-pager")):(s=i+1,n.pagerEl.addClass("bx-default-pager")),e+='<div class="bx-pager-item"><a href="" data-slide-index="'+i+'" class="bx-pager-link">'+s+"</a></div>"}n.pagerEl.html(e)},v=function(){n.settings.pagerCustom?n.pagerEl=t(n.settings.pagerCustom):(n.pagerEl=t('<div class="bx-pager" />'),n.settings.pagerSelector?t(n.settings.pagerSelector).html(n.pagerEl):n.controls.el.addClass("bx-has-pager").append(n.pagerEl),p()),n.pagerEl.delegate("a","click",C)},f=function(){n.controls.next=t('<a class="bx-next" href="">'+n.settings.nextText+"</a>"),n.controls.prev=t('<a class="bx-prev" href="">'+n.settings.prevText+"</a>"),n.controls.next.bind("click",S),n.controls.prev.bind("click",b),n.settings.nextSelector&&t(n.settings.nextSelector).append(n.controls.next),n.settings.prevSelector&&t(n.settings.prevSelector).append(n.controls.prev),n.settings.nextSelector||n.settings.prevSelector||(n.controls.directionEl=t('<div class="bx-controls-direction" />'),n.controls.directionEl.append(n.controls.prev).append(n.controls.next),n.controls.el.addClass("bx-has-controls-direction").append(n.controls.directionEl))},x=function(){n.controls.start=t('<div class="bx-controls-auto-item"><a class="bx-start" href="">'+n.settings.startText+"</a></div>"),n.controls.stop=t('<div class="bx-controls-auto-item"><a class="bx-stop" href="">'+n.settings.stopText+"</a></div>"),n.controls.autoEl=t('<div class="bx-controls-auto" />'),n.controls.autoEl.delegate(".bx-start","click",w),n.controls.autoEl.delegate(".bx-stop","click",T),n.settings.autoControlsCombine?n.controls.autoEl.append(n.controls.start):n.controls.autoEl.append(n.controls.start).append(n.controls.stop),n.settings.autoControlsSelector?t(n.settings.autoControlsSelector).html(n.controls.autoEl):n.controls.el.addClass("bx-has-controls-auto").append(n.controls.autoEl),A(n.settings.autoStart?"stop":"start")},m=function(){n.children.each(function(){var e=t(this).find("img:first").attr("title");e!=void 0&&t(this).append('<div class="bx-caption"><span>'+e+"</span></div>")})},S=function(t){n.settings.auto&&s.stopAuto(),s.goToNextSlide(),t.preventDefault()},b=function(t){n.settings.auto&&s.stopAuto(),s.goToPrevSlide(),t.preventDefault()},w=function(t){s.startAuto(),t.preventDefault()},T=function(t){s.stopAuto(),t.preventDefault()},C=function(e){n.settings.auto&&s.stopAuto();var i=t(e.currentTarget),o=parseInt(i.attr("data-slide-index"));o!=n.active.index&&s.goToSlide(o),e.preventDefault()},E=function(t){return n.settings.pagerType=="short"?(n.pagerEl.html(t+1+n.settings.pagerShortSeparator+n.children.length),void 0):(n.pagerEl.find("a").removeClass("active"),n.pagerEl.find("a").eq(t).addClass("active"),void 0)},P=function(){if(!n.carousel&&n.settings.infiniteLoop){var t="";n.active.index==0?t=n.children.eq(0).position():n.active.index==n.children.length-1&&(t=n.children.eq(n.children.length-1).position()),n.settings.mode=="horizontal"?h(-t.left,"reset",0):n.settings.mode=="vertical"&&h(-t.top,"reset",0)}n.working=!1,n.settings.onSlideAfter(n.children.eq(n.active.index))},A=function(t){n.settings.autoControlsCombine?n.controls.autoEl.html(n.controls[t]):(n.controls.autoEl.find("a").removeClass("active"),n.controls.autoEl.find("a:not(.bx-"+t+")").addClass("active"))},k=function(){!n.settings.infiniteLoop&&n.settings.hideControlOnEnd&&(n.active.index==0?(n.controls.prev.addClass("disabled"),n.controls.next.removeClass("disabled")):n.active.index==c()-1?(n.controls.next.addClass("disabled"),n.controls.prev.removeClass("disabled")):(n.controls.prev.removeClass("disabled"),n.controls.next.removeClass("disabled")))},y=function(){n.settings.autoDelay>0?setTimeout(s.startAuto,n.settings.autoDelay):s.startAuto(),n.settings.autoHover&&s.hover(function(){n.interval&&(s.stopAuto(!0),n.autoPaused=!0)},function(){n.autoPaused&&(s.startAuto(!0),n.autoPaused=null)})},z=function(){var e=0;if(n.settings.autoDirection=="next")s.append(n.children.clone().addClass("bx-clone"));else{s.prepend(n.children.clone().addClass("bx-clone"));var i=n.children.first().position();e=n.settings.mode=="horizontal"?-i.left:-i.top}h(e,"reset",0),n.settings.pager=!1,n.settings.controls=!1,n.settings.autoControls=!1,n.settings.tickerHover&&!n.usingCSS&&n.viewport.hover(function(){s.stop()},function(){var e=0;n.children.each(function(){e+=n.settings.mode=="horizontal"?t(this).outerWidth(!0):t(this).outerHeight(!0)});var i=n.settings.speed/e,o=n.settings.mode=="horizontal"?"left":"top",r=i*(e-Math.abs(parseInt(s.css(o))));M(r)}),M()},M=function(t){speed=t?t:n.settings.speed;var e={left:0,top:0},i={left:0,top:0};n.settings.autoDirection=="next"?e=s.find(".bx-clone").first().position():i=n.children.first().position();var o=n.settings.mode=="horizontal"?-e.left:-e.top,r=n.settings.mode=="horizontal"?-i.left:-i.top,a={resetValue:r};h(o,"ticker",speed,a)},L=function(){n.touch={start:{x:0,y:0},end:{x:0,y:0}},n.viewport.bind("touchstart",D)},D=function(t){if(n.working)t.preventDefault();else{n.touch.originalPos=s.position();var e=t.originalEvent;n.touch.start.x=e.changedTouches[0].pageX,n.touch.start.y=e.changedTouches[0].pageY,n.viewport.bind("touchmove",H),n.viewport.bind("touchend",q)}},H=function(t){if(t.preventDefault(),n.settings.mode!="fade"){var e=t.originalEvent,i=0;if(n.settings.mode=="horizontal"){var s=e.changedTouches[0].pageX-n.touch.start.x;i=n.touch.originalPos.left+s}else{var s=e.changedTouches[0].pageY-n.touch.start.y;i=n.touch.originalPos.top+s}h(i,"reset",0)}},q=function(t){n.viewport.unbind("touchmove",H);var e=t.originalEvent,i=0;if(n.touch.end.x=e.changedTouches[0].pageX,n.touch.end.y=e.changedTouches[0].pageY,n.settings.mode=="fade"){var o=Math.abs(n.touch.start.x-n.touch.end.x);o>=n.settings.swipeThreshold&&(n.touch.start.x>n.touch.end.x?s.goToNextSlide():s.goToPrevSlide(),s.stopAuto())}else{var o=0;n.settings.mode=="horizontal"?(o=n.touch.end.x-n.touch.start.x,i=n.touch.originalPos.left):(o=n.touch.end.y-n.touch.start.y,i=n.touch.originalPos.top),!n.settings.infiniteLoop&&(n.active.index==0&&o>0||n.active.last&&0>o)?h(i,"reset",200):Math.abs(o)>=n.settings.swipeThreshold?(0>o?s.goToNextSlide():s.goToPrevSlide(),s.stopAuto()):h(i,"reset",200)}n.viewport.unbind("touchend",q)};s.goToSlide=function(e,i){if(!n.working&&n.active.index!=e)if(n.working=!0,n.active.index=0>e?n.children.length-1:e>=n.children.length?0:e,n.settings.onSlideBefore(n.children.eq(n.active.index)),i=="next"?n.settings.onSlideNext(n.children.eq(n.active.index)):i=="prev"&&n.settings.onSlidePrev(n.children.eq(n.active.index)),n.active.last=n.active.index>=c()-1,n.settings.pager&&E(n.active.index),n.settings.controls&&k(),n.settings.mode=="fade")n.settings.adaptiveHeight&&n.viewport.height()!=a()&&n.viewport.animate({height:a()},n.settings.adaptiveHeightSpeed),n.children.filter(":visible").fadeOut(n.settings.speed).css({zIndex:0}),n.children.eq(n.active.index).css("zIndex",51).fadeIn(n.settings.speed,function(){t(this).css("zIndex",50),P()});else{n.settings.adaptiveHeight&&n.viewport.height()!=a()&&n.viewport.animate({height:a()},n.settings.adaptiveHeightSpeed);var o=0,r={left:0,top:0};if(n.carousel&&n.active.last)if(n.settings.mode=="horizontal"){var l=n.children.eq(n.children.length-1);r=l.position(),o=n.viewport.width()-l.width()}else{var d=n.children.length-n.settings.minSlides;r=n.children.eq(d).position()}else if(n.carousel||i!="next"||n.active.index!=0){if(e>=0){var u=e*g();r=n.children.eq(u).position()}}else r=s.find(".bx-clone:last").position(),n.active.last=!1;var p=n.settings.mode=="horizontal"?-(r.left-o):-r.top;h(p,"slide",n.settings.speed)}},s.goToNextSlide=function(){if(n.settings.infiniteLoop||!n.active.last){var t=n.active.index+1;n.carousel&&n.settings.infiniteLoop&&t>=c()&&(t=0),s.goToSlide(t,"next")}},s.goToPrevSlide=function(){if(n.settings.infiniteLoop||n.active.index!=0){var t=n.active.index-1;n.carousel&&n.settings.infiniteLoop&&0>t&&(t=c()-1),s.goToSlide(t,"prev")}},s.startAuto=function(t){n.interval||(n.interval=setInterval(function(){n.settings.autoDirection=="next"?s.goToNextSlide():s.goToPrevSlide()},n.settings.pause),n.settings.autoControls&&t!=1&&A("stop"))},s.stopAuto=function(t){n.interval&&(clearInterval(n.interval),n.interval=null,n.settings.autoControls&&t!=1&&A("start"))},s.getCurrentSlide=function(){return n.active.index},s.getSlideCount=function(){return n.children.length};var I=t(window).width(),W=t(window).height();return t(window).resize(function(){var e=t(window).width(),i=t(window).height();(I!=e||W!=i)&&(I=e,W=i,n.children.add(s.find(".bx-clone")).width(l()),n.viewport.css("height",a()),n.active.last&&(n.active.index=c()-1),n.active.index>=c()&&(n.active.last=!0),n.settings.pager&&!n.settings.pagerCustom&&(p(),E(n.active.index)),n.settings.ticker||u())}),o(),this}})(jQuery),function(t,e){var i="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";t.fn.imagesLoaded=function(n){function s(){var e=t(g),i=t(u);a&&(u.length?a.reject(d,e,i):a.resolve(d)),t.isFunction(n)&&n.call(r,d,e,i)}function o(e,n){e.src===i||-1!==t.inArray(e,c)||(c.push(e),n?u.push(e):g.push(e),t.data(e,"imagesLoaded",{isBroken:n,src:e.src}),l&&a.notifyWith(t(e),[n,d,t(g),t(u)]),d.length===c.length&&(setTimeout(s),d.unbind(".imagesLoaded")))}var r=this,a=t.isFunction(t.Deferred)?t.Deferred():0,l=t.isFunction(a.notify),d=r.find("img").add(r.filter("img")),c=[],g=[],u=[];return t.isPlainObject(n)&&t.each(n,function(t,e){"callback"===t?n=e:a&&a[t](e)}),d.length?d.bind("load.imagesLoaded error.imagesLoaded",function(t){o(t.target,"error"===t.type)}).each(function(n,s){var r=s.src,a=t.data(s,"imagesLoaded");a&&a.src===r?o(s,a.isBroken):s.complete&&s.naturalWidth!==e?o(s,0===s.naturalWidth||0===s.naturalHeight):(s.readyState||s.complete)&&(s.src=i,s.src=r)}):s(),a?a.promise(r):r}}(jQuery)