diff --git a/jquery.bxSlider.min.js b/jquery.bxSlider.min.js index c3cbf25..f82fac5 100755 --- a/jquery.bxSlider.min.js +++ b/jquery.bxSlider.min.js @@ -1,5 +1,5 @@ /** - * jQuery bxSlider v3.0 + * jQuery bxSlider v3.1 * http://bxslider.com * * Copyright 2010, Steven Wanderski @@ -9,4 +9,4 @@ * http://www.opensource.org/licenses/mit-license.php * */ -(function(a){a.fn.bxSlider=function(b){function H(){I(b.startingSlide);if(b.mode=="horizontal"){e.wrap('
').wrap('
').css({width:"999999px",position:"relative",left:"-"+(b.infiniteLoop?y:0)+"px"});e.children(b.childSelector).css({width:j,"float":"left",listStyle:"none"});h=e.parent().parent();g.addClass("bx-child")}else if(b.mode=="vertical"){e.wrap('
').wrap('
').css({height:"999999px",position:"relative",top:"-"+z+"px"});e.children(b.childSelector).css({listStyle:"none",height:w});h=e.parent().parent();g.addClass("bx-child")}else if(b.mode=="fade"){e.wrap('
').wrap('
');e.children(b.childSelector).css({listStyle:"none",position:"absolute",top:0,left:0,zIndex:98});h=e.parent().parent();g.not(":eq("+x+")").fadeTo(0,0);g.eq(x).css("zIndex",99)}if(b.captions&&b.captionsSelector==null){h.append('
')}}function I(){if((b.mode=="horizontal"||b.mode=="vertical")&&b.infiniteLoop){var c=Z(g,0,b.moveSlideQty,"backward");a.each(c,function(b){e.prepend(a(this))});var d=g.length+b.moveSlideQty-1;var f=g.length-b.displaySlideQty;var h=d-f;var i=Z(g,0,h,"forward");if(b.infiniteLoop){a.each(i,function(b){e.append(a(this))})}}}function J(){if(b.nextImage!=""){nextContent=b.nextImage;nextType="image"}else{nextContent=b.nextText;nextType="text"}if(b.prevImage!=""){prevContent=b.prevImage;prevType="image"}else{prevContent=b.prevText;prevType="text"}R(nextType,nextContent,prevType,prevContent)}function K(){if(b.auto){clearInterval(o);if(!b.infiniteLoop){if(b.autoDirection=="next"){o=setInterval(function(){x+=b.moveSlideQty;if(x>G){x=x%g.length}d.goToSlide(x,false)},b.pause)}else if(b.autoDirection=="prev"){o=setInterval(function(){x-=b.moveSlideQty;if(x<0){negativeOffset=x%g.length;if(negativeOffset==0){x=0}else{x=g.length+negativeOffset}}d.goToSlide(x,false)},b.pause)}}else{if(b.autoDirection=="next"){o=setInterval(function(){d.goToNextSlide(false)},b.pause)}else if(b.autoDirection=="prev"){o=setInterval(function(){d.goToPreviousSlide(false)},b.pause)}}}else if(b.ticker){b.tickerSpeed*=10;a(".bx-child",h).each(function(b){A+=a(this).width();B+=a(this).height()});if(b.tickerDirection=="prev"&&b.mode=="horizontal"){e.css("left","-"+(A+y)+"px")}else if(b.tickerDirection=="prev"&&b.mode=="vertical"){e.css("top","-"+(B+z)+"px")}if(b.mode=="horizontal"){C=parseInt(e.css("left"));L(C,A,b.tickerSpeed)}else if(b.mode=="vertical"){D=parseInt(e.css("top"));L(D,B,b.tickerSpeed)}if(b.tickerHover){O()}}}function L(a,c,d){if(b.mode=="horizontal"){if(b.tickerDirection=="next"){e.animate({left:"-="+c+"px"},d,"linear",function(){e.css("left",a);L(a,A,b.tickerSpeed)})}else if(b.tickerDirection=="prev"){e.animate({left:"+="+c+"px"},d,"linear",function(){e.css("left",a);L(a,A,b.tickerSpeed)})}}else if(b.mode=="vertical"){if(b.tickerDirection=="next"){e.animate({top:"-="+c+"px"},d,"linear",function(){e.css("top",a);L(a,B,b.tickerSpeed)})}else if(b.tickerDirection=="prev"){e.animate({top:"+="+c+"px"},d,"linear",function(){e.css("top",a);L(a,B,b.tickerSpeed)})}}}function M(){if(b.startImage!=""){startContent=b.startImage;startType="image"}else{startContent=b.startText;startType="text"}if(b.stopImage!=""){stopContent=b.stopImage;stopType="image"}else{stopContent=b.stopText;stopType="text"}U(startType,startContent,stopType,stopContent)}function N(){h.children(".bx-window").hover(function(){if(t){d.suspendShow(false)}},function(){if(t){d.restartShow(false)}})}function O(){e.hover(function(){if(t){d.stopTicker(false)}},function(){if(t){d.startTicker(false)}})}function P(){g.not(":eq("+x+")").fadeTo(b.speed,0).css("zIndex",98);g.eq(x).css("zIndex",99).fadeTo(b.speed,1,function(){E=false;if(jQuery.browser.msie){g.eq(x).get(0).style.removeAttribute("filter")}b.onAfterSlide(x,g.length,g.eq(x))})}function Q(c){if(b.pagerType=="full"&&b.pager){a("a",n).removeClass(b.pagerActiveClass);a("a",n).eq(c).addClass(b.pagerActiveClass)}else if(b.pagerType=="short"&&b.pager){a(".bx-pager-current",n).html(x+1)}}function R(c,e,f,g){var i=a('');var j=a('');if(c=="text"){i.html(e)}else{i.html('')}if(f=="text"){j.html(g)}else{j.html('')}if(b.prevSelector){a(b.prevSelector).append(j)}else{h.append(j)}if(b.nextSelector){a(b.nextSelector).append(i)}else{h.append(i)}i.click(function(){d.goToNextSlide();return false});j.click(function(){d.goToPreviousSlide();return false})}function S(c){var e=g.length;if(b.moveSlideQty>1){if(g.length%b.moveSlideQty!=0){e=Math.ceil(g.length/b.moveSlideQty)}else{e=g.length/b.moveSlideQty}}var f="";if(b.buildPager){for(var i=0;i'+i+""}}else if(c=="short"){f=''+(b.startingSlide+1)+" "+b.pagerShortSeparator+' '+g.length+""}if(b.pagerSelector){a(b.pagerSelector).append(f);n=a(b.pagerSelector)}else{var j=a('
');j.append(f);if(b.pagerLocation=="top"){h.prepend(j)}else if(b.pagerLocation=="bottom"){h.append(j)}n=h.children(".bx-pager")}n.children().click(function(){if(b.pagerType=="full"){var a=n.children().index(this);if(b.moveSlideQty>1){a*=b.moveSlideQty}d.goToSlide(a)}return false})}function T(){var c=a("img",g.eq(x)).attr("title");if(c!=""){if(b.captionsSelector){a(b.captionsSelector).html(c)}else{h.children(".bx-captions").html(c)}}else{if(b.captionsSelector){a(b.captionsSelector).html(" ")}else{h.children(".bx-captions").html(" ")}}}function U(c,e,f,g){p=a('');if(c=="text"){r=e}else{r=''}if(f=="text"){s=g}else{s=''}if(b.autoControlsSelector){a(b.autoControlsSelector).append(p)}else{h.append('
');h.children(".bx-auto").html(p)}p.click(function(){if(b.ticker){if(a(this).hasClass("stop")){d.stopTicker()}else if(a(this).hasClass("start")){d.startTicker()}}else{if(a(this).hasClass("stop")){d.stopShow(true)}else if(a(this).hasClass("start")){d.startShow(true)}}return false})}function V(){if(!b.infiniteLoop&&b.hideControlOnEnd){if(x==F){h.children(".bx-prev").hide()}else{h.children(".bx-prev").show()}var a=Math.floor(G/b.displaySlideQty)*b.displaySlideQty;if(x>=a){h.children(".bx-next").hide()}else{h.children(".bx-next").show()}}}function W(a,b){var c=e.find(" > .bx-child").eq(a).position();return b=="left"?c.left:c.top}function X(){var a=i.outerWidth()*b.displaySlideQty;return a}function Y(){var a=i.outerHeight()*b.displaySlideQty;return a}function Z(b,c,d,e){var f=[];var g=d;var h=false;if(e=="backward"){b=a.makeArray(b);b.reverse()}while(g>0){a.each(b,function(b,d){if(g>0){if(!h){if(b==c){h=true;f.push(a(this).clone());g--}}else{f.push(a(this).clone());g--}}else{return false}})}return f}var c={mode:"horizontal",childSelector:"",infiniteLoop:true,hideControlOnEnd:false,controls:true,speed:500,easing:"swing",pager:false,pagerSelector:null,pagerType:"full",pagerLocation:"bottom",pagerShortSeparator:"/",pagerActiveClass:"pager-active",nextText:"next",nextImage:"",nextSelector:null,prevText:"prev",prevImage:"",prevSelector:null,captions:false,captionsSelector:null,auto:false,autoDirection:"next",autoControls:false,autoControlsSelector:null,autoStart:true,autoHover:false,autoDelay:0,pause:3e3,startText:"start",startImage:"",stopText:"stop",stopImage:"",ticker:false,tickerSpeed:5e3,tickerDirection:"next",tickerHover:false,wrapperClass:"bx-wrapper",startingSlide:0,displaySlideQty:1,moveSlideQty:1,randomStart:false,onBeforeSlide:function(){},onAfterSlide:function(){},onLastSlide:function(){},onFirstSlide:function(){},onNextSlide:function(){},onPrevSlide:function(){},buildPager:null};var b=a.extend(c,b);var d=this;var e="";var f="";var g="";var h="";var i="";var j="";var k="";var l="";var m="";var n="";var o="";var p="";var q="";var r="";var s="";var t=true;var u=false;var v=0;var w=0;var x=0;var y=0;var z=0;var A=0;var B=0;var C=0;var D=0;var E=false;var F=0;var G=g.length-1;this.goToSlide=function(a,c){if(!E){E=true;x=a;b.onBeforeSlide(x,g.length,g.eq(x));if(typeof c=="undefined"){var c=true}if(c){if(b.auto){d.stopShow(true)}}slide=a;if(slide==F){b.onFirstSlide(x,g.length,g.eq(x))}if(slide==G){b.onLastSlide(x,g.length,g.eq(x))}if(b.mode=="horizontal"){e.animate({left:"-"+W(slide,"left")+"px"},b.speed,b.easing,function(){E=false;b.onAfterSlide(x,g.length,g.eq(x))})}else if(b.mode=="vertical"){e.animate({top:"-"+W(slide,"top")+"px"},b.speed,b.easing,function(){E=false;b.onAfterSlide(x,g.length,g.eq(x))})}else if(b.mode=="fade"){P()}V();if(b.moveSlideQty>1){a=Math.floor(a/b.moveSlideQty)}Q(a);T()}};this.goToNextSlide=function(a){if(typeof a=="undefined"){var a=true}if(a){if(b.auto){d.stopShow(true)}}if(!b.infiniteLoop){if(!E){var c=false;x=x+b.moveSlideQty;if(x<=G){V();b.onNextSlide(x,g.length,g.eq(x));d.goToSlide(x)}else{x-=b.moveSlideQty}}}else{if(!E){E=true;var c=false;x=x+b.moveSlideQty;if(x>G){x=x%g.length;c=true}b.onNextSlide(x,g.length,g.eq(x));b.onBeforeSlide(x,g.length,g.eq(x));if(b.mode=="horizontal"){var f=b.moveSlideQty*k;e.animate({left:"-="+f+"px"},b.speed,b.easing,function(){E=false;if(c){e.css("left","-"+W(x,"left")+"px")}b.onAfterSlide(x,g.length,g.eq(x))})}else if(b.mode=="vertical"){var h=b.moveSlideQty*w;e.animate({top:"-="+h+"px"},b.speed,b.easing,function(){E=false;if(c){e.css("top","-"+W(x,"top")+"px")}b.onAfterSlide(x,g.length,g.eq(x))})}else if(b.mode=="fade"){P()}if(b.moveSlideQty>1){Q(Math.ceil(x/b.moveSlideQty))}else{Q(x)}T()}}};this.goToPreviousSlide=function(a){if(typeof a=="undefined"){var a=true}if(a){if(b.auto){d.stopShow(true)}}if(!b.infiniteLoop){if(!E){var c=false;x=x-b.moveSlideQty;if(x<0){x=0;if(b.hideControlOnEnd){h.children(".bx-prev").hide()}}V();b.onPrevSlide(x,g.length,g.eq(x));d.goToSlide(x)}}else{if(!E){E=true;var c=false;x=x-b.moveSlideQty;if(x<0){negativeOffset=x%g.length;if(negativeOffset==0){x=0}else{x=g.length+negativeOffset}c=true}b.onPrevSlide(x,g.length,g.eq(x));b.onBeforeSlide(x,g.length,g.eq(x));if(b.mode=="horizontal"){var f=b.moveSlideQty*k;e.animate({left:"+="+f+"px"},b.speed,b.easing,function(){E=false;if(c){e.css("left","-"+W(x,"left")+"px")}b.onAfterSlide(x,g.length,g.eq(x))})}else if(b.mode=="vertical"){var i=b.moveSlideQty*w;e.animate({top:"+="+i+"px"},b.speed,b.easing,function(){E=false;if(c){e.css("top","-"+W(x,"top")+"px")}b.onAfterSlide(x,g.length,g.eq(x))})}else if(b.mode=="fade"){P()}if(b.moveSlideQty>1){Q(Math.ceil(x/b.moveSlideQty))}else{Q(x)}T()}}};this.goToFirstSlide=function(a){if(typeof a=="undefined"){var a=true}d.goToSlide(F,a)};this.goToLastSlide=function(){if(typeof a=="undefined"){var a=true}d.goToSlide(G,a)};this.getCurrentSlide=function(){return x};this.getSlideCount=function(){return g.length};this.suspendShow=function(a){clearInterval(o);if(typeof a=="undefined"){var a=true}if(a&&b.autoControls){p.html(r).removeClass("stop").addClass("start")}};this.restartShow=function(a){if(typeof a=="undefined"){var a=true}if(t){K()}if(a&&b.autoControls){p.html(s).removeClass("start").addClass("stop")}};this.stopShow=function(a){t=false;this.suspendShow(a)};this.startShow=function(a){t=true;this.restartShow(a)};this.stopTicker=function(a){e.stop();if(typeof a=="undefined"){var a=true}if(a&&b.ticker){p.html(r).removeClass("stop").addClass("start");t=false}};this.startTicker=function(a){if(b.mode=="horizontal"){if(b.tickerDirection=="next"){var c=parseInt(e.css("left"));var d=A+c+g.eq(0).width()}else if(b.tickerDirection=="prev"){var c=-parseInt(e.css("left"));var d=c-g.eq(0).width()}var f=d*b.tickerSpeed/A;L(C,d,f)}else if(b.mode=="vertical"){if(b.tickerDirection=="next"){var h=parseInt(e.css("top"));var d=B+h+g.eq(0).height()}else if(b.tickerDirection=="prev"){var h=-parseInt(e.css("top"));var d=h-g.eq(0).height()}var f=d*b.tickerSpeed/B;L(D,d,f);if(typeof a=="undefined"){var a=true}if(a&&b.ticker){p.html(s).removeClass("start").addClass("stop");t=true}}};this.initShow=function(){e=a(this);f=e.clone();g=e.children(b.childSelector);h="";i=e.children(b.childSelector+":first");j=i.width();v=0;k=i.outerWidth();w=0;l=X();m=Y();E=false;n="";x=0;y=0;z=0;o="";p="";q="";r="";s="";t=true;u=false;A=0;B=0;C=0;D=0;F=0;G=g.length-1;g.each(function(b){if(a(this).outerHeight()>w){w=a(this).outerHeight()}if(a(this).outerWidth()>v){v=a(this).outerWidth()}});if(b.randomStart){var c=Math.floor(Math.random()*g.length);x=c;y=k*(b.moveSlideQty+c);z=w*(b.moveSlideQty+c)}else{x=b.startingSlide;y=k*(b.moveSlideQty+b.startingSlide);z=w*(b.moveSlideQty+b.startingSlide)}H();if(b.pager&&!b.ticker){if(b.pagerType=="full"){S("full")}else if(b.pagerType=="short"){S("short")}}if(b.controls&&!b.ticker&&g.length>1){J()}if(b.auto||b.ticker){if(b.autoControls){M()}if(b.autoStart){t=false;setTimeout(function(){d.startShow(true)},b.autoDelay)}else{d.stopShow(true)}if(b.autoHover&&!b.ticker){N()}}if(b.moveSlideQty>1){Q(Math.ceil(x/b.moveSlideQty))}else{Q(x)}V();if(b.captions){T()}b.onAfterSlide(x,g.length,g.eq(x))};this.destroyShow=function(){clearInterval(o);h.children(".bx-next, .bx-prev, .bx-pager, .bx-auto").remove();e.unwrap().unwrap().removeAttr("style");e.children(b.childSelector).removeAttr("style").not(".bx-child").remove();g.removeClass("bx-child")};this.reloadShow=function(){d.destroyShow();d.initShow()};this.each(function(){if(a(this).children().length>0){d.initShow()}});return this};jQuery.fx.prototype.cur=function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null)){return this.elem[this.prop]}var a=parseFloat(jQuery.css(this.elem,this.prop));return a}})(jQuery) \ No newline at end of file +(function(e){e.fn.bxSlider=function(t){function j(){F(t.startingSlide);if(t.mode=="horizontal"){i.wrap('
').wrap('
').css({width:"999999px",position:"relative",left:"-"+(t.infiniteLoop?T:0)+"px"});i.children(t.childSelector).css({width:f,"float":"left",listStyle:"none"});u=i.parent().parent();o.addClass("bx-child")}else if(t.mode=="vertical"){i.wrap('
').wrap('
').css({height:"999999px",position:"relative",top:"-"+N+"px"});i.children(t.childSelector).css({listStyle:"none",height:S});u=i.parent().parent();o.addClass("bx-child")}else if(t.mode=="fade"){i.wrap('
').wrap('
');i.children(t.childSelector).css({listStyle:"none",position:"absolute",top:0,left:0,zIndex:98});u=i.parent().parent();o.not(":eq("+x+")").fadeTo(0,0);o.eq(x).css("zIndex",99)}if(t.captions&&t.captionsSelector==null){u.append('
')}}function F(){if((t.mode=="horizontal"||t.mode=="vertical")&&t.infiniteLoop){var n=nt(o,0,t.moveSlideQty,"backward");e.each(n,function(t){i.prepend(e(this))});var r=o.length+t.moveSlideQty-1;var s=o.length-t.displaySlideQty;var u=r-s;var a=nt(o,0,u,"forward");if(t.infiniteLoop){e.each(a,function(t){i.append(e(this))})}}}function I(){if(t.nextImage!=""){nextContent=t.nextImage;nextType="image"}else{nextContent=t.nextText;nextType="text"}if(t.prevImage!=""){prevContent=t.prevImage;prevType="image"}else{prevContent=t.prevText;prevType="text"}J(nextType,nextContent,prevType,prevContent)}function q(){if(t.auto){clearInterval(d);if(!t.infiniteLoop){if(t.autoDirection=="next"){d=setInterval(function(){x+=t.moveSlideQty;if(x>_){x=x%o.length}r.goToSlide(x,false)},t.pause)}else if(t.autoDirection=="prev"){d=setInterval(function(){x-=t.moveSlideQty;if(x<0){negativeOffset=x%o.length;if(negativeOffset==0){x=0}else{x=o.length+negativeOffset}}r.goToSlide(x,false)},t.pause)}}else{if(t.autoDirection=="next"){d=setInterval(function(){r.goToNextSlide(false)},t.pause)}else if(t.autoDirection=="prev"){d=setInterval(function(){r.goToPreviousSlide(false)},t.pause)}}}else if(t.ticker){t.tickerSpeed*=10;e(".bx-child",u).each(function(t){C+=e(this).width();k+=e(this).height()});if(t.tickerDirection=="prev"&&t.mode=="horizontal"){i.css("left","-"+(C+T)+"px")}else if(t.tickerDirection=="prev"&&t.mode=="vertical"){i.css("top","-"+(k+N)+"px")}if(t.mode=="horizontal"){L=parseInt(i.css("left"));R(L,C,t.tickerSpeed)}else if(t.mode=="vertical"){A=parseInt(i.css("top"));R(A,k,t.tickerSpeed)}if(t.tickerHover){W()}}}function R(e,n,r){if(t.mode=="horizontal"){if(t.tickerDirection=="next"){i.animate({left:"-="+n+"px"},r,"linear",function(){i.css("left",e);R(e,C,t.tickerSpeed)})}else if(t.tickerDirection=="prev"){i.animate({left:"+="+n+"px"},r,"linear",function(){i.css("left",e);R(e,C,t.tickerSpeed)})}}else if(t.mode=="vertical"){if(t.tickerDirection=="next"){i.animate({top:"-="+n+"px"},r,"linear",function(){i.css("top",e);R(e,k,t.tickerSpeed)})}else if(t.tickerDirection=="prev"){i.animate({top:"+="+n+"px"},r,"linear",function(){i.css("top",e);R(e,k,t.tickerSpeed)})}}}function U(){if(t.startImage!=""){startContent=t.startImage;startType="image"}else{startContent=t.startText;startType="text"}if(t.stopImage!=""){stopContent=t.stopImage;stopType="image"}else{stopContent=t.stopText;stopType="text"}G(startType,startContent,stopType,stopContent)}function z(){u.children(".bx-window").hover(function(){if(b){r.suspendShow(false)}},function(){if(b){r.restartShow(false)}})}function W(){i.hover(function(){if(b){r.stopTicker(false)}},function(){if(b){r.startTicker(false)}})}function X(){o.not(":eq("+x+")").fadeTo(t.speed,0).css("zIndex",98);o.eq(x).css("zIndex",99).fadeTo(t.speed,1,function(){O=false;if(jQuery.browser.msie){o.eq(x).get(0).style.removeAttribute("filter")}t.onAfterSlide(x,o.length,o.eq(x))})}function V(n){if(t.pagerType=="full"&&t.pager){e("a",p).removeClass(t.pagerActiveClass);e("a",p).eq(n).addClass(t.pagerActiveClass)}else if(t.pagerType=="short"&&t.pager){e(".bx-pager-current",p).html(x+1)}}function J(n,i,s,o){var a=e('');var f=e('');if(n=="text"){a.html(i)}else{a.html('')}if(s=="text"){f.html(o)}else{f.html('')}if(t.prevSelector){e(t.prevSelector).append(f)}else{u.append(f)}if(t.nextSelector){e(t.nextSelector).append(a)}else{u.append(a)}a.click(function(){r.goToNextSlide();return false});f.click(function(){r.goToPreviousSlide();return false})}function K(n){var i=o.length;if(t.moveSlideQty>1){if(o.length%t.moveSlideQty!=0){i=Math.ceil(o.length/t.moveSlideQty)}else{i=o.length/t.moveSlideQty}}var s="";if(t.buildPager){for(var a=0;a'+a+""}}else if(n=="short"){s=''+(t.startingSlide+1)+" "+t.pagerShortSeparator+' '+o.length+""}if(t.pagerSelector){e(t.pagerSelector).append(s);p=e(t.pagerSelector)}else{var f=e('
');f.append(s);if(t.pagerLocation=="top"){u.prepend(f)}else if(t.pagerLocation=="bottom"){u.append(f)}p=u.children(".bx-pager")}p.children().click(function(){if(t.pagerType=="full"){var e=p.children().index(this);if(t.moveSlideQty>1){e*=t.moveSlideQty}r.goToSlide(e)}return false})}function Q(){var n=e("img",o.eq(x)).attr("title");if(n!=""){if(t.captionsSelector){e(t.captionsSelector).html(n)}else{u.children(".bx-captions").html(n)}}else{if(t.captionsSelector){e(t.captionsSelector).html(" ")}else{u.children(".bx-captions").html(" ")}}}function G(n,i,s,o){v=e('');if(n=="text"){g=i}else{g=''}if(s=="text"){y=o}else{y=''}if(t.autoControlsSelector){e(t.autoControlsSelector).append(v)}else{u.append('
');u.children(".bx-auto").html(v)}v.click(function(){if(t.ticker){if(e(this).hasClass("stop")){r.stopTicker()}else if(e(this).hasClass("start")){r.startTicker()}}else{if(e(this).hasClass("stop")){r.stopShow(true)}else if(e(this).hasClass("start")){r.startShow(true)}}return false})}function Y(){if(!t.infiniteLoop&&t.hideControlOnEnd){if(x==M){u.children(".bx-prev").hide()}else{u.children(".bx-prev").show()}var e=Math.floor(_/t.displaySlideQty)*t.displaySlideQty;if(x>=e){u.children(".bx-next").hide()}else{u.children(".bx-next").show()}}}function Z(e,t){var n=i.find(" > .bx-child").eq(e).position();return t=="left"?n.left:n.top}function et(){var e=a.outerWidth()*t.displaySlideQty;return e}function tt(){var e=a.outerHeight()*t.displaySlideQty;return e}function nt(t,n,r,i){var s=[];var o=r;var u=false;if(i=="backward"){t=e.makeArray(t);t.reverse()}while(o>0){e.each(t,function(t,r){if(o>0){if(!u){if(t==n){u=true;s.push(e(this).clone());o--}}else{s.push(e(this).clone());o--}}else{return false}})}return s}var n={mode:"horizontal",childSelector:"",infiniteLoop:true,hideControlOnEnd:false,controls:true,speed:500,easing:"swing",pager:false,pagerSelector:null,pagerType:"full",pagerLocation:"bottom",pagerShortSeparator:"/",pagerActiveClass:"pager-active",nextText:"next",nextImage:"",nextSelector:null,prevText:"prev",prevImage:"",prevSelector:null,captions:false,captionsSelector:null,auto:false,autoDirection:"next",autoControls:false,autoControlsSelector:null,autoStart:true,autoHover:false,autoDelay:0,pause:3e3,startText:"start",startImage:"",stopText:"stop",stopImage:"",ticker:false,responsive:false,minSlides:1,maxSlides:50,tickerSpeed:5e3,tickerDirection:"next",tickerHover:false,wrapperClass:"bx-wrapper",startingSlide:0,displaySlideQty:1,moveSlideQty:1,randomStart:false,onBeforeSlide:function(){},onAfterSlide:function(){},onLastSlide:function(){},onFirstSlide:function(){},onNextSlide:function(){},onPrevSlide:function(){},buildPager:null};var t=e.extend(n,t);var r=this;var i="";var s="";var o="";var u="";var a="";var f="";var l="";var c="";var h="";var p="";var d="";var v="";var m="";var g="";var y="";var b=true;var w=false;var E=0;var S=0;var x=0;var T=0;var N=0;var C=0;var k=0;var L=0;var A=0;var O=false;var M=0;var _=o.length-1;this.goToSlide=function(e,n){if(!O){O=true;x=e;t.onBeforeSlide(x,o.length,o.eq(x));if(typeof n=="undefined"){var n=true}if(n){if(t.auto){r.stopShow(true)}}slide=e;if(slide==M){t.onFirstSlide(x,o.length,o.eq(x))}if(slide==_){t.onLastSlide(x,o.length,o.eq(x))}if(t.mode=="horizontal"){i.animate({left:"-"+Z(slide,"left")+"px"},t.speed,t.easing,function(){O=false;t.onAfterSlide(x,o.length,o.eq(x))})}else if(t.mode=="vertical"){i.animate({top:"-"+Z(slide,"top")+"px"},t.speed,t.easing,function(){O=false;t.onAfterSlide(x,o.length,o.eq(x))})}else if(t.mode=="fade"){X()}Y();if(t.moveSlideQty>1){e=Math.floor(e/t.moveSlideQty)}V(e);Q()}};var D,P;var H=function(t){var n=e(window).width();var i=e(window).height();if(D!=n||P!=i){D=n;P=i;r.autoUpdateDisplayQty()}};this.reloadSlider=function(n){t=e.extend(t,n);r.reloadShow()};var B;this.calculateDisplayQty=function(){return Math.floor(u.parent().width()/f)};this.autoUpdateDisplayQty=function(){var e=r.calculateDisplayQty();if(B!=e){B=e;r.reloadSlider({startingSlide:x})}};this.goToNextSlide=function(e){if(typeof e=="undefined"){var e=true}if(e){if(t.auto){r.stopShow(true)}}if(!t.infiniteLoop){if(!O){var n=false;x=x+t.moveSlideQty;if(x<=_){Y();t.onNextSlide(x,o.length,o.eq(x));r.goToSlide(x)}else{x-=t.moveSlideQty}}}else{if(!O){O=true;var n=false;x=x+t.moveSlideQty;if(x>_){x=x%o.length;n=true}t.onNextSlide(x,o.length,o.eq(x));t.onBeforeSlide(x,o.length,o.eq(x));if(t.mode=="horizontal"){var s=t.moveSlideQty*l;i.animate({left:"-="+s+"px"},t.speed,t.easing,function(){O=false;if(n){i.css("left","-"+Z(x,"left")+"px")}t.onAfterSlide(x,o.length,o.eq(x))})}else if(t.mode=="vertical"){var u=t.moveSlideQty*S;i.animate({top:"-="+u+"px"},t.speed,t.easing,function(){O=false;if(n){i.css("top","-"+Z(x,"top")+"px")}t.onAfterSlide(x,o.length,o.eq(x))})}else if(t.mode=="fade"){X()}if(t.moveSlideQty>1){V(Math.ceil(x/t.moveSlideQty))}else{V(x)}Q()}}};this.goToPreviousSlide=function(e){if(typeof e=="undefined"){var e=true}if(e){if(t.auto){r.stopShow(true)}}if(!t.infiniteLoop){if(!O){var n=false;x=x-t.moveSlideQty;if(x<0){x=0;if(t.hideControlOnEnd){u.children(".bx-prev").hide()}}Y();t.onPrevSlide(x,o.length,o.eq(x));r.goToSlide(x)}}else{if(!O){O=true;var n=false;x=x-t.moveSlideQty;if(x<0){negativeOffset=x%o.length;if(negativeOffset==0){x=0}else{x=o.length+negativeOffset}n=true}t.onPrevSlide(x,o.length,o.eq(x));t.onBeforeSlide(x,o.length,o.eq(x));if(t.mode=="horizontal"){var s=t.moveSlideQty*l;i.animate({left:"+="+s+"px"},t.speed,t.easing,function(){O=false;if(n){i.css("left","-"+Z(x,"left")+"px")}t.onAfterSlide(x,o.length,o.eq(x))})}else if(t.mode=="vertical"){var a=t.moveSlideQty*S;i.animate({top:"+="+a+"px"},t.speed,t.easing,function(){O=false;if(n){i.css("top","-"+Z(x,"top")+"px")}t.onAfterSlide(x,o.length,o.eq(x))})}else if(t.mode=="fade"){X()}if(t.moveSlideQty>1){V(Math.ceil(x/t.moveSlideQty))}else{V(x)}Q()}}};this.goToFirstSlide=function(e){if(typeof e=="undefined"){var e=true}r.goToSlide(M,e)};this.goToLastSlide=function(){if(typeof e=="undefined"){var e=true}r.goToSlide(_,e)};this.getCurrentSlide=function(){return x};this.getSlideCount=function(){return o.length};this.suspendShow=function(e){clearInterval(d);if(typeof e=="undefined"){var e=true}if(e&&t.autoControls){v.html(g).removeClass("stop").addClass("start")}};this.restartShow=function(e){if(typeof e=="undefined"){var e=true}if(b){q()}if(e&&t.autoControls){v.html(y).removeClass("start").addClass("stop")}};this.stopShow=function(e){b=false;this.suspendShow(e)};this.startShow=function(e){b=true;this.restartShow(e)};this.stopTicker=function(e){i.stop();if(typeof e=="undefined"){var e=true}if(e&&t.ticker){v.html(g).removeClass("stop").addClass("start");b=false}};this.startTicker=function(e){if(t.mode=="horizontal"){if(t.tickerDirection=="next"){var n=parseInt(i.css("left"));var r=C+n+o.eq(0).width()}else if(t.tickerDirection=="prev"){var n=-parseInt(i.css("left"));var r=n-o.eq(0).width()}var s=r*t.tickerSpeed/C;R(L,r,s)}else if(t.mode=="vertical"){if(t.tickerDirection=="next"){var u=parseInt(i.css("top"));var r=k+u+o.eq(0).height()}else if(t.tickerDirection=="prev"){var u=-parseInt(i.css("top"));var r=u-o.eq(0).height()}var s=r*t.tickerSpeed/k;R(A,r,s);if(typeof e=="undefined"){var e=true}if(e&&t.ticker){v.html(y).removeClass("start").addClass("stop");b=true}}};this.initShow=function(){i=e(this);s=i.clone();o=i.children(t.childSelector);u=i;a=i.children(t.childSelector+":first");f=a.width();E=0;l=a.outerWidth();S=0;O=false;p="";x=0;T=0;N=0;d="";v="";m="";g="";y="";b=true;w=false;C=0;k=0;L=0;A=0;M=0;_=o.length-1;o.each(function(t){if(e(this).outerHeight()>S){S=e(this).outerHeight()}if(e(this).outerWidth()>E){E=e(this).outerWidth()}});if(t.randomStart){var n=Math.floor(Math.random()*o.length);x=B=n;T=l*(t.moveSlideQty+n);N=S*(t.moveSlideQty+n)}else{x=t.startingSlide;T=l*(t.moveSlideQty+t.startingSlide);N=S*(t.moveSlideQty+t.startingSlide)}if(t.responsive){t.displaySlideQty=r.calculateDisplayQty()||1;e(window).bind("resize",H)}if(t.displaySlideQtymaxSlides)t.displaySlideQty=maxSlides;c=et();h=tt();j();if(t.pager&&!t.ticker){if(t.pagerType=="full"){K("full")}else if(t.pagerType=="short"){K("short")}}if(t.controls&&!t.ticker&&o.length>1){I()}if(t.auto||t.ticker){if(t.autoControls){U()}if(t.autoStart){b=false;setTimeout(function(){r.startShow(true)},t.autoDelay)}else{r.stopShow(true)}if(t.autoHover&&!t.ticker){z()}}if(t.moveSlideQty>1){V(Math.ceil(x/t.moveSlideQty))}else{V(x)}Y();if(t.captions){Q()}t.onAfterSlide(x,o.length,o.eq(x))};this.destroyShow=function(){clearInterval(d);u.children(".bx-next, .bx-prev, .bx-pager, .bx-auto").remove();i.unwrap().unwrap().removeAttr("style");i.children(t.childSelector).removeAttr("style").not(".bx-child").remove();o.removeClass("bx-child");if(t.responsive)e(window).unbind("resize",H)};this.reloadShow=function(){r.destroyShow();r.initShow()};this.each(function(){if(e(this).children().length>0){r.initShow()}});return this};jQuery.fx.prototype.cur=function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null)){return this.elem[this.prop]}var e=parseFloat(jQuery.css(this.elem,this.prop));return e}})(jQuery) \ No newline at end of file diff --git a/source/jquery.bxSlider.js b/source/jquery.bxSlider.js index 93dad55..4eb954a 100755 --- a/source/jquery.bxSlider.js +++ b/source/jquery.bxSlider.js @@ -1,5 +1,5 @@ /** - * jQuery bxSlider v3.0 + * jQuery bxSlider v3.1 * http://bxslider.com * * Copyright 2011, Steven Wanderski @@ -11,1264 +11,1344 @@ */ (function($){ - - $.fn.bxSlider = function(options){ - - var defaults = { - mode: 'horizontal', // 'horizontal', 'vertical', 'fade' - childSelector: '', // jQuery selector - elements to be used as slides - infiniteLoop: true, // true, false - display first slide after last - hideControlOnEnd: false, // true, false - if true, will hide 'next' control on last slide and 'prev' control on first - controls: true, // true, false - previous and next controls - speed: 500, // integer - in ms, duration of time slide transitions will occupy - easing: 'swing', // used with jquery.easing.1.3.js - see http://gsgd.co.uk/sandbox/jquery/easing/ for available options - pager: false, // true / false - display a pager - pagerSelector: null, // jQuery selector - element to contain the pager. ex: '#pager' - pagerType: 'full', // 'full', 'short' - if 'full' pager displays 1,2,3... if 'short' pager displays 1 / 4 - pagerLocation: 'bottom', // 'bottom', 'top' - location of pager - pagerShortSeparator: '/', // string - ex: 'of' pager would display 1 of 4 - pagerActiveClass: 'pager-active', // string - classname attached to the active pager link - nextText: 'next', // string - text displayed for 'next' control - nextImage: '', // string - filepath of image used for 'next' control. ex: 'images/next.jpg' - nextSelector: null, // jQuery selector - element to contain the next control. ex: '#next' - prevText: 'prev', // string - text displayed for 'previous' control - prevImage: '', // string - filepath of image used for 'previous' control. ex: 'images/prev.jpg' - prevSelector: null, // jQuery selector - element to contain the previous control. ex: '#next' - captions: false, // true, false - display image captions (reads the image 'title' tag) - captionsSelector: null, // jQuery selector - element to contain the captions. ex: '#captions' - auto: false, // true, false - make slideshow change automatically - autoDirection: 'next', // 'next', 'prev' - direction in which auto show will traverse - autoControls: false, // true, false - show 'start' and 'stop' controls for auto show - autoControlsSelector: null, // jQuery selector - element to contain the auto controls. ex: '#auto-controls' - autoStart: true, // true, false - if false show will wait for 'start' control to activate - autoHover: false, // true, false - if true show will pause on mouseover - autoDelay: 0, // integer - in ms, the amount of time before starting the auto show - pause: 3000, // integer - in ms, the duration between each slide transition - startText: 'start', // string - text displayed for 'start' control - startImage: '', // string - filepath of image used for 'start' control. ex: 'images/start.jpg' - stopText: 'stop', // string - text displayed for 'stop' control - stopImage: '', // string - filepath of image used for 'stop' control. ex: 'images/stop.jpg' - ticker: false, // true, false - continuous motion ticker mode (think news ticker) - // note: autoControls, autoControlsSelector, and autoHover apply to ticker! - tickerSpeed: 5000, // float - use value between 1 and 5000 to determine ticker speed - the smaller the value the faster the ticker speed - tickerDirection: 'next', // 'next', 'prev' - direction in which ticker show will traverse - tickerHover: false, // true, false - if true ticker will pause on mouseover - wrapperClass: 'bx-wrapper', // string - classname attached to the slider wraper - startingSlide: 0, // integer - show will start on specified slide. note: slides are zero based! - displaySlideQty: 1, // integer - number of slides to display at once - moveSlideQty: 1, // integer - number of slides to move at once - randomStart: false, // true, false - if true show will start on a random slide - onBeforeSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager - onAfterSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager - onLastSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager - onFirstSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager - onNextSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager - onPrevSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager - buildPager: null, // function(slideIndex, slideHtmlObject){ return string; } - advanced use only! see the tutorial here: http://bxslider.com/custom-pager - } - - var options = $.extend(defaults, options); - - // cache the base element - var base = this; - // initialize (and localize) all variables - var $parent = ''; - var $origElement = ''; - var $children = ''; - var $outerWrapper = ''; - var $firstChild = ''; - var childrenWidth = ''; - var childrenOuterWidth = ''; - var wrapperWidth = ''; - var wrapperHeight = ''; - var $pager = ''; - var interval = ''; - var $autoControls = ''; - var $stopHtml = ''; - var $startContent = ''; - var $stopContent = ''; - var autoPlaying = true; - var loaded = false; - var childrenMaxWidth = 0; - var childrenMaxHeight = 0; - var currentSlide = 0; - var origLeft = 0; - var origTop = 0; - var origShowWidth = 0; - var origShowHeight = 0; - var tickerLeft = 0; - var tickerTop = 0; - var isWorking = false; - var firstSlide = 0; - var lastSlide = $children.length - 1; - - - // PUBLIC FUNCTIONS - - /** - * Go to specified slide - */ - this.goToSlide = function(number, stopAuto){ - if(!isWorking){ - isWorking = true; - // set current slide to argument - currentSlide = number; - options.onBeforeSlide(currentSlide, $children.length, $children.eq(currentSlide)); - // check if stopAuto argument is supplied - if(typeof(stopAuto) == 'undefined'){ - var stopAuto = true; - } - if(stopAuto){ - // if show is auto playing, stop it - if(options.auto){ - base.stopShow(true); - } - } - slide = number; - // check for first slide callback - if(slide == firstSlide){ - options.onFirstSlide(currentSlide, $children.length, $children.eq(currentSlide)); - } - // check for last slide callback - if(slide == lastSlide){ - options.onLastSlide(currentSlide, $children.length, $children.eq(currentSlide)); - } - // horizontal - if(options.mode == 'horizontal'){ - $parent.animate({'left': '-'+getSlidePosition(slide, 'left')+'px'}, options.speed, options.easing, function(){ - isWorking = false; - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - }); - // vertical - }else if(options.mode == 'vertical'){ - $parent.animate({'top': '-'+getSlidePosition(slide, 'top')+'px'}, options.speed, options.easing, function(){ - isWorking = false; - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - }); - // fade - }else if(options.mode == 'fade'){ - setChildrenFade(); - } - // check to remove controls on last/first slide - checkEndControls(); - // accomodate multi slides - if(options.moveSlideQty > 1){ - number = Math.floor(number / options.moveSlideQty); - } - // make the current slide active - makeSlideActive(number); - // display the caption - showCaptions(); - } - } - - /** - * Go to next slide - */ - this.goToNextSlide = function(stopAuto){ - // check if stopAuto argument is supplied - if(typeof(stopAuto) == 'undefined'){ - var stopAuto = true; - } - if(stopAuto){ - // if show is auto playing, stop it - if(options.auto){ - base.stopShow(true); - } - } - // makes slideshow finite - if(!options.infiniteLoop){ - if(!isWorking){ - var slideLoop = false; - // make current slide the old value plus moveSlideQty - currentSlide = (currentSlide + (options.moveSlideQty)); - // if current slide has looped on itself - if(currentSlide <= lastSlide){ - checkEndControls(); - // next slide callback - options.onNextSlide(currentSlide, $children.length, $children.eq(currentSlide)); - // move to appropriate slide - base.goToSlide(currentSlide); - }else{ - currentSlide -= options.moveSlideQty; - } - } // end if(!isWorking) - }else{ - if(!isWorking){ - isWorking = true; - var slideLoop = false; - // make current slide the old value plus moveSlideQty - currentSlide = (currentSlide + options.moveSlideQty); - // if current slide has looped on itself - if(currentSlide > lastSlide){ - currentSlide = currentSlide % $children.length; - slideLoop = true; - } - // next slide callback - options.onNextSlide(currentSlide, $children.length, $children.eq(currentSlide)); - // slide before callback - options.onBeforeSlide(currentSlide, $children.length, $children.eq(currentSlide)); - if(options.mode == 'horizontal'){ - // get the new 'left' property for $parent - var parentLeft = (options.moveSlideQty * childrenOuterWidth); - // animate to the new 'left' - $parent.animate({'left': '-='+parentLeft+'px'}, options.speed, options.easing, function(){ - isWorking = false; - // if its time to loop, reset the $parent - if(slideLoop){ - $parent.css('left', '-'+getSlidePosition(currentSlide, 'left')+'px'); - } - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - }); - }else if(options.mode == 'vertical'){ - // get the new 'left' property for $parent - var parentTop = (options.moveSlideQty * childrenMaxHeight); - // animate to the new 'left' - $parent.animate({'top': '-='+parentTop+'px'}, options.speed, options.easing, function(){ - isWorking = false; - // if its time to loop, reset the $parent - if(slideLoop){ - $parent.css('top', '-'+getSlidePosition(currentSlide, 'top')+'px'); - } - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - }); - }else if(options.mode == 'fade'){ - setChildrenFade(); - } - // make the current slide active - if(options.moveSlideQty > 1){ - makeSlideActive(Math.ceil(currentSlide / options.moveSlideQty)); - }else{ - makeSlideActive(currentSlide); - } - // display the caption - showCaptions(); - } // end if(!isWorking) - - } - } // end function - - /** - * Go to previous slide - */ - this.goToPreviousSlide = function(stopAuto){ - // check if stopAuto argument is supplied - if(typeof(stopAuto) == 'undefined'){ - var stopAuto = true; - } - if(stopAuto){ - // if show is auto playing, stop it - if(options.auto){ - base.stopShow(true); - } - } - // makes slideshow finite - if(!options.infiniteLoop){ - if(!isWorking){ - var slideLoop = false; - // make current slide the old value plus moveSlideQty - currentSlide = currentSlide - options.moveSlideQty; - // if current slide has looped on itself - if(currentSlide < 0){ - currentSlide = 0; - // if specified, hide the control on the last slide - if(options.hideControlOnEnd){ - $outerWrapper.children('.bx-prev').hide(); - } - } - checkEndControls(); - // next slide callback - options.onPrevSlide(currentSlide, $children.length, $children.eq(currentSlide)); - // move to appropriate slide - base.goToSlide(currentSlide); - } - }else{ - if(!isWorking){ - isWorking = true; - var slideLoop = false; - // make current slide the old value plus moveSlideQty - currentSlide = (currentSlide - (options.moveSlideQty)); - // if current slide has looped on itself - if(currentSlide < 0){ - negativeOffset = (currentSlide % $children.length); - if(negativeOffset == 0){ - currentSlide = 0; - }else{ - currentSlide = ($children.length) + negativeOffset; - } - slideLoop = true; - } - // next slide callback - options.onPrevSlide(currentSlide, $children.length, $children.eq(currentSlide)); - // slide before callback - options.onBeforeSlide(currentSlide, $children.length, $children.eq(currentSlide)); - if(options.mode == 'horizontal'){ - // get the new 'left' property for $parent - var parentLeft = (options.moveSlideQty * childrenOuterWidth); - // animate to the new 'left' - $parent.animate({'left': '+='+parentLeft+'px'}, options.speed, options.easing, function(){ - isWorking = false; - // if its time to loop, reset the $parent - if(slideLoop){ - $parent.css('left', '-'+getSlidePosition(currentSlide, 'left')+'px'); - } - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - }); - }else if(options.mode == 'vertical'){ - // get the new 'left' property for $parent - var parentTop = (options.moveSlideQty * childrenMaxHeight); - // animate to the new 'left' - $parent.animate({'top': '+='+parentTop+'px'}, options.speed, options.easing, function(){ - isWorking = false; - // if its time to loop, reset the $parent - if(slideLoop){ - $parent.css('top', '-'+getSlidePosition(currentSlide, 'top')+'px'); - } - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - }); - }else if(options.mode == 'fade'){ - setChildrenFade(); - } - // make the current slide active - if(options.moveSlideQty > 1){ - makeSlideActive(Math.ceil(currentSlide / options.moveSlideQty)); - }else{ - makeSlideActive(currentSlide); - } - // display the caption - showCaptions(); - } // end if(!isWorking) - } - } // end function - - /** - * Go to first slide - */ - this.goToFirstSlide = function(stopAuto){ - // check if stopAuto argument is supplied - if(typeof(stopAuto) == 'undefined'){ - var stopAuto = true; - } - base.goToSlide(firstSlide, stopAuto); - } - - /** - * Go to last slide - */ - this.goToLastSlide = function(){ - // check if stopAuto argument is supplied - if(typeof(stopAuto) == 'undefined'){ - var stopAuto = true; - } - base.goToSlide(lastSlide, stopAuto); - } - - /** - * Get the current slide - */ - this.getCurrentSlide = function(){ - return currentSlide; - } - - /** - * Get the total slide count - */ - this.getSlideCount = function(){ - return $children.length; - } - - /** - * Suspend the slideshow - */ - this.suspendShow = function(changeText){ - clearInterval(interval); - // check if changeText argument is supplied - if(typeof(changeText) == 'undefined'){ - var changeText = true; - } - if(changeText && options.autoControls){ - $autoControls.html($startContent).removeClass('stop').addClass('start'); - } - } - - /** - * Restart the suspended slideshow - */ - this.restartShow = function(changeText){ - // check if changeText argument is supplied - if(typeof(changeText) == 'undefined'){ - var changeText = true; - } - if(autoPlaying){ - setAutoInterval(); - } - if(changeText && options.autoControls){ - $autoControls.html($stopContent).removeClass('start').addClass('stop'); - } - } - - /** - * Stop the slideshow permanently - */ - this.stopShow = function(changeText){ - autoPlaying = false; - this.suspendShow(changeText); - } - - /** - * Start the slideshow - */ - this.startShow = function(changeText){ - autoPlaying = true; - this.restartShow(changeText); - } - - /** - * Stops the ticker - */ - this.stopTicker = function(changeText){ - $parent.stop(); - // check if changeText argument is supplied - if(typeof(changeText) == 'undefined'){ - var changeText = true; - } - if(changeText && options.ticker){ - $autoControls.html($startContent).removeClass('stop').addClass('start'); - autoPlaying = false; - } - } - - /** - * Starts the ticker - */ - this.startTicker = function(changeText){ - if(options.mode == 'horizontal'){ - if(options.tickerDirection == 'next'){ - // get the 'left' property where the ticker stopped - var stoppedLeft = parseInt($parent.css('left')); - // calculate the remaining distance the show must travel until the loop - var remainingDistance = (origShowWidth + stoppedLeft) + $children.eq(0).width(); - }else if(options.tickerDirection == 'prev'){ - // get the 'left' property where the ticker stopped - var stoppedLeft = -parseInt($parent.css('left')); - // calculate the remaining distance the show must travel until the loop - var remainingDistance = (stoppedLeft) - $children.eq(0).width(); - } - // calculate the speed ratio to seamlessly finish the loop - var finishingSpeed = (remainingDistance * options.tickerSpeed) / origShowWidth; - // call the show - moveTheShow(tickerLeft, remainingDistance, finishingSpeed); - }else if(options.mode == 'vertical'){ - if(options.tickerDirection == 'next'){ - // get the 'top' property where the ticker stopped - var stoppedTop = parseInt($parent.css('top')); - // calculate the remaining distance the show must travel until the loop - var remainingDistance = (origShowHeight + stoppedTop) + $children.eq(0).height(); - }else if(options.tickerDirection == 'prev'){ - // get the 'left' property where the ticker stopped - var stoppedTop = -parseInt($parent.css('top')); - // calculate the remaining distance the show must travel until the loop - var remainingDistance = (stoppedTop) - $children.eq(0).height(); - } - // calculate the speed ratio to seamlessly finish the loop - var finishingSpeed = (remainingDistance * options.tickerSpeed) / origShowHeight; - // call the show - moveTheShow(tickerTop, remainingDistance, finishingSpeed); - // check if changeText argument is supplied - if(typeof(changeText) == 'undefined'){ - var changeText = true; - } - if(changeText && options.ticker){ - $autoControls.html($stopContent).removeClass('start').addClass('stop'); - autoPlaying = true; - } - } - } - - /** - * Initialize a new slideshow - */ - this.initShow = function(){ - - // reinitialize all variables - // base = this; - $parent = $(this); - $origElement = $parent.clone(); - $children = $parent.children(options.childSelector); - $outerWrapper = ''; - $firstChild = $parent.children(options.childSelector + ':first'); - childrenWidth = $firstChild.width(); - childrenMaxWidth = 0; - childrenOuterWidth = $firstChild.outerWidth(); - childrenMaxHeight = 0; - wrapperWidth = getWrapperWidth(); - wrapperHeight = getWrapperHeight(); - isWorking = false; - $pager = ''; - currentSlide = 0; - origLeft = 0; - origTop = 0; - interval = ''; - $autoControls = ''; - $stopHtml = ''; - $startContent = ''; - $stopContent = ''; - autoPlaying = true; - loaded = false; - origShowWidth = 0; - origShowHeight = 0; - tickerLeft = 0; - tickerTop = 0; + $.fn.bxSlider = function(options){ + + var defaults = { + mode: 'horizontal', // 'horizontal', 'vertical', 'fade' + childSelector: '', // jQuery selector - elements to be used as slides + infiniteLoop: true, // true, false - display first slide after last + hideControlOnEnd: false, // true, false - if true, will hide 'next' control on last slide and 'prev' control on first + controls: true, // true, false - previous and next controls + speed: 500, // integer - in ms, duration of time slide transitions will occupy + easing: 'swing', // used with jquery.easing.1.3.js - see http://gsgd.co.uk/sandbox/jquery/easing/ for available options + pager: false, // true / false - display a pager + pagerSelector: null, // jQuery selector - element to contain the pager. ex: '#pager' + pagerType: 'full', // 'full', 'short' - if 'full' pager displays 1,2,3... if 'short' pager displays 1 / 4 + pagerLocation: 'bottom', // 'bottom', 'top' - location of pager + pagerShortSeparator: '/', // string - ex: 'of' pager would display 1 of 4 + pagerActiveClass: 'pager-active', // string - classname attached to the active pager link + nextText: 'next', // string - text displayed for 'next' control + nextImage: '', // string - filepath of image used for 'next' control. ex: 'images/next.jpg' + nextSelector: null, // jQuery selector - element to contain the next control. ex: '#next' + prevText: 'prev', // string - text displayed for 'previous' control + prevImage: '', // string - filepath of image used for 'previous' control. ex: 'images/prev.jpg' + prevSelector: null, // jQuery selector - element to contain the previous control. ex: '#next' + captions: false, // true, false - display image captions (reads the image 'title' tag) + captionsSelector: null, // jQuery selector - element to contain the captions. ex: '#captions' + auto: false, // true, false - make slideshow change automatically + autoDirection: 'next', // 'next', 'prev' - direction in which auto show will traverse + autoControls: false, // true, false - show 'start' and 'stop' controls for auto show + autoControlsSelector: null, // jQuery selector - element to contain the auto controls. ex: '#auto-controls' + autoStart: true, // true, false - if false show will wait for 'start' control to activate + autoHover: false, // true, false - if true show will pause on mouseover + autoDelay: 0, // integer - in ms, the amount of time before starting the auto show + pause: 3000, // integer - in ms, the duration between each slide transition + startText: 'start', // string - text displayed for 'start' control + startImage: '', // string - filepath of image used for 'start' control. ex: 'images/start.jpg' + stopText: 'stop', // string - text displayed for 'stop' control + stopImage: '', // string - filepath of image used for 'stop' control. ex: 'images/stop.jpg' + ticker: false, // true, false - continuous motion ticker mode (think news ticker) + responsive: false, // true, false - automatic define displaySlideQty + + minSlides: 1, // number - minimun displaySlideQty + maxSlides: 50, // number - maximun displaySlideQty + // note: autoControls, autoControlsSelector, and autoHover apply to ticker! + tickerSpeed: 5000, // float - use value between 1 and 5000 to determine ticker speed - the smaller the value the faster the ticker speed + tickerDirection: 'next', // 'next', 'prev' - direction in which ticker show will traverse + tickerHover: false, // true, false - if true ticker will pause on mouseover + wrapperClass: 'bx-wrapper', // string - classname attached to the slider wraper + startingSlide: 0, // integer - show will start on specified slide. note: slides are zero based! + displaySlideQty: 1, // integer - number of slides to display at once + moveSlideQty: 1, // integer - number of slides to move at once + randomStart: false, // true, false - if true show will start on a random slide + onBeforeSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager + onAfterSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager + onLastSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager + onFirstSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager + onNextSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager + onPrevSlide: function(){}, // function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) - advanced use only! see the tutorial here: http://bxslider.com/custom-pager + buildPager: null, // function(slideIndex, slideHtmlObject){ return string; } - advanced use only! see the tutorial here: http://bxslider.com/custom-pager + } + + var options = $.extend(defaults, options); + + // cache the base element + var base = this; + // initialize (and localize) all variables + var $parent = ''; + var $origElement = ''; + var $children = ''; + var $outerWrapper = ''; + var $firstChild = ''; + var childrenWidth = ''; + var childrenOuterWidth = ''; + var wrapperWidth = ''; + var wrapperHeight = ''; + var $pager = ''; + var interval = ''; + var $autoControls = ''; + var $stopHtml = ''; + var $startContent = ''; + var $stopContent = ''; + var autoPlaying = true; + var loaded = false; + var childrenMaxWidth = 0; + var childrenMaxHeight = 0; + var currentSlide = 0; + var origLeft = 0; + var origTop = 0; + var origShowWidth = 0; + var origShowHeight = 0; + var tickerLeft = 0; + var tickerTop = 0; + var isWorking = false; + + var firstSlide = 0; + var lastSlide = $children.length - 1; + + + // PUBLIC FUNCTIONS + + /** + * Go to specified slide + */ + this.goToSlide = function(number, stopAuto){ + if(!isWorking){ + isWorking = true; + // set current slide to argument + currentSlide = number; + options.onBeforeSlide(currentSlide, $children.length, $children.eq(currentSlide)); + // check if stopAuto argument is supplied + if(typeof(stopAuto) == 'undefined'){ + var stopAuto = true; + } + if(stopAuto){ + // if show is auto playing, stop it + if(options.auto){ + base.stopShow(true); + } + } + slide = number; + // check for first slide callback + if(slide == firstSlide){ + options.onFirstSlide(currentSlide, $children.length, $children.eq(currentSlide)); + } + // check for last slide callback + if(slide == lastSlide){ + options.onLastSlide(currentSlide, $children.length, $children.eq(currentSlide)); + } + // horizontal + if(options.mode == 'horizontal'){ + $parent.animate({'left': '-'+getSlidePosition(slide, 'left')+'px'}, options.speed, options.easing, function(){ + isWorking = false; + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + }); + // vertical + }else if(options.mode == 'vertical'){ + $parent.animate({'top': '-'+getSlidePosition(slide, 'top')+'px'}, options.speed, options.easing, function(){ + isWorking = false; + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + }); + // fade + }else if(options.mode == 'fade'){ + setChildrenFade(); + } + // check to remove controls on last/first slide + checkEndControls(); + // accomodate multi slides + if(options.moveSlideQty > 1){ + number = Math.floor(number / options.moveSlideQty); + } + // make the current slide active + makeSlideActive(number); + // display the caption + showCaptions(); + } + } + + var windowWidth, windowHeight; + + /** + * Window resize event callback + */ + var resizeWindow = function(e){ + // get the new window dimens (again, thank you IE) + var windowWidthNew = $(window).width(); + var windowHeightNew = $(window).height(); + // make sure that it is a true window resize + // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements + // are resized. Can you just die already?* + if(windowWidth != windowWidthNew || windowHeight != windowHeightNew){ + // set the new window dimens + windowWidth = windowWidthNew; + windowHeight = windowHeightNew; + // update all dynamic elements + base.autoUpdateDisplayQty(); + } + } + + + /** + * Reload the slider. Useful when adding slides on the fly. Accepts an optional settings object. + */ + this.reloadSlider = function(new_options){ + options = $.extend(options, new_options); + base.reloadShow(); + }; + + var lastQty; + + /** + * Returns maximum amount of display that fits on the slide + */ + this.calculateDisplayQty = function(){ + return Math.floor($outerWrapper.parent().width() / childrenWidth); + } + + /** + * Update maximum amount of display that fits on the slide + */ + this.autoUpdateDisplayQty = function(){ + var qty = base.calculateDisplayQty(); + + if(lastQty != qty){ + lastQty = qty; + + base.reloadSlider({ + startingSlide: currentSlide + }); + } + }; + + + /** + * Go to next slide + */ + this.goToNextSlide = function(stopAuto){ + // check if stopAuto argument is supplied + if(typeof(stopAuto) == 'undefined'){ + var stopAuto = true; + } + if(stopAuto){ + // if show is auto playing, stop it + if(options.auto){ + base.stopShow(true); + } + } + // makes slideshow finite + if(!options.infiniteLoop){ + if(!isWorking){ + var slideLoop = false; + // make current slide the old value plus moveSlideQty + currentSlide = (currentSlide + (options.moveSlideQty)); + // if current slide has looped on itself + if(currentSlide <= lastSlide){ + checkEndControls(); + // next slide callback + options.onNextSlide(currentSlide, $children.length, $children.eq(currentSlide)); + // move to appropriate slide + base.goToSlide(currentSlide); + }else{ + currentSlide -= options.moveSlideQty; + } + } // end if(!isWorking) + }else{ + if(!isWorking){ + isWorking = true; + var slideLoop = false; + // make current slide the old value plus moveSlideQty + currentSlide = (currentSlide + options.moveSlideQty); + // if current slide has looped on itself + if(currentSlide > lastSlide){ + currentSlide = currentSlide % $children.length; + slideLoop = true; + } + // next slide callback + options.onNextSlide(currentSlide, $children.length, $children.eq(currentSlide)); + // slide before callback + options.onBeforeSlide(currentSlide, $children.length, $children.eq(currentSlide)); + if(options.mode == 'horizontal'){ + // get the new 'left' property for $parent + var parentLeft = (options.moveSlideQty * childrenOuterWidth); + // animate to the new 'left' + $parent.animate({'left': '-='+parentLeft+'px'}, options.speed, options.easing, function(){ + isWorking = false; + // if its time to loop, reset the $parent + if(slideLoop){ + $parent.css('left', '-'+getSlidePosition(currentSlide, 'left')+'px'); + } + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + }); + }else if(options.mode == 'vertical'){ + // get the new 'left' property for $parent + var parentTop = (options.moveSlideQty * childrenMaxHeight); + // animate to the new 'left' + $parent.animate({'top': '-='+parentTop+'px'}, options.speed, options.easing, function(){ + isWorking = false; + // if its time to loop, reset the $parent + if(slideLoop){ + $parent.css('top', '-'+getSlidePosition(currentSlide, 'top')+'px'); + } + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + }); + }else if(options.mode == 'fade'){ + setChildrenFade(); + } + // make the current slide active + if(options.moveSlideQty > 1){ + makeSlideActive(Math.ceil(currentSlide / options.moveSlideQty)); + }else{ + makeSlideActive(currentSlide); + } + // display the caption + showCaptions(); + } // end if(!isWorking) + + } + } // end function + + /** + * Go to previous slide + */ + this.goToPreviousSlide = function(stopAuto){ + // check if stopAuto argument is supplied + if(typeof(stopAuto) == 'undefined'){ + var stopAuto = true; + } + if(stopAuto){ + // if show is auto playing, stop it + if(options.auto){ + base.stopShow(true); + } + } + // makes slideshow finite + if(!options.infiniteLoop){ + if(!isWorking){ + var slideLoop = false; + // make current slide the old value plus moveSlideQty + currentSlide = currentSlide - options.moveSlideQty; + // if current slide has looped on itself + if(currentSlide < 0){ + currentSlide = 0; + // if specified, hide the control on the last slide + if(options.hideControlOnEnd){ + $outerWrapper.children('.bx-prev').hide(); + } + } + checkEndControls(); + // next slide callback + options.onPrevSlide(currentSlide, $children.length, $children.eq(currentSlide)); + // move to appropriate slide + base.goToSlide(currentSlide); + } + }else{ + if(!isWorking){ + isWorking = true; + var slideLoop = false; + // make current slide the old value plus moveSlideQty + currentSlide = (currentSlide - (options.moveSlideQty)); + // if current slide has looped on itself + if(currentSlide < 0){ + negativeOffset = (currentSlide % $children.length); + if(negativeOffset == 0){ + currentSlide = 0; + }else{ + currentSlide = ($children.length) + negativeOffset; + } + slideLoop = true; + } + // next slide callback + options.onPrevSlide(currentSlide, $children.length, $children.eq(currentSlide)); + // slide before callback + options.onBeforeSlide(currentSlide, $children.length, $children.eq(currentSlide)); + if(options.mode == 'horizontal'){ + // get the new 'left' property for $parent + var parentLeft = (options.moveSlideQty * childrenOuterWidth); + // animate to the new 'left' + $parent.animate({'left': '+='+parentLeft+'px'}, options.speed, options.easing, function(){ + isWorking = false; + // if its time to loop, reset the $parent + if(slideLoop){ + $parent.css('left', '-'+getSlidePosition(currentSlide, 'left')+'px'); + } + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + }); + }else if(options.mode == 'vertical'){ + // get the new 'left' property for $parent + var parentTop = (options.moveSlideQty * childrenMaxHeight); + // animate to the new 'left' + $parent.animate({'top': '+='+parentTop+'px'}, options.speed, options.easing, function(){ + isWorking = false; + // if its time to loop, reset the $parent + if(slideLoop){ + $parent.css('top', '-'+getSlidePosition(currentSlide, 'top')+'px'); + } + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + }); + }else if(options.mode == 'fade'){ + setChildrenFade(); + } + // make the current slide active + if(options.moveSlideQty > 1){ + makeSlideActive(Math.ceil(currentSlide / options.moveSlideQty)); + }else{ + makeSlideActive(currentSlide); + } + // display the caption + showCaptions(); + } // end if(!isWorking) + } + } // end function + + /** + * Go to first slide + */ + this.goToFirstSlide = function(stopAuto){ + // check if stopAuto argument is supplied + if(typeof(stopAuto) == 'undefined'){ + var stopAuto = true; + } + base.goToSlide(firstSlide, stopAuto); + } + + /** + * Go to last slide + */ + this.goToLastSlide = function(){ + // check if stopAuto argument is supplied + if(typeof(stopAuto) == 'undefined'){ + var stopAuto = true; + } + base.goToSlide(lastSlide, stopAuto); + } + + /** + * Get the current slide + */ + this.getCurrentSlide = function(){ + return currentSlide; + } + + /** + * Get the total slide count + */ + this.getSlideCount = function(){ + return $children.length; + } + + /** + * Suspend the slideshow + */ + this.suspendShow = function(changeText){ + clearInterval(interval); + // check if changeText argument is supplied + if(typeof(changeText) == 'undefined'){ + var changeText = true; + } + if(changeText && options.autoControls){ + $autoControls.html($startContent).removeClass('stop').addClass('start'); + } + } + + /** + * Restart the suspended slideshow + */ + this.restartShow = function(changeText){ + // check if changeText argument is supplied + if(typeof(changeText) == 'undefined'){ + var changeText = true; + } + if(autoPlaying){ + setAutoInterval(); + } + if(changeText && options.autoControls){ + $autoControls.html($stopContent).removeClass('start').addClass('stop'); + } + } + + /** + * Stop the slideshow permanently + */ + this.stopShow = function(changeText){ + autoPlaying = false; + this.suspendShow(changeText); + } + + /** + * Start the slideshow + */ + this.startShow = function(changeText){ + autoPlaying = true; + this.restartShow(changeText); + } + + /** + * Stops the ticker + */ + this.stopTicker = function(changeText){ + $parent.stop(); + // check if changeText argument is supplied + if(typeof(changeText) == 'undefined'){ + var changeText = true; + } + if(changeText && options.ticker){ + $autoControls.html($startContent).removeClass('stop').addClass('start'); + autoPlaying = false; + } + } + + /** + * Starts the ticker + */ + this.startTicker = function(changeText){ + if(options.mode == 'horizontal'){ + if(options.tickerDirection == 'next'){ + // get the 'left' property where the ticker stopped + var stoppedLeft = parseInt($parent.css('left')); + // calculate the remaining distance the show must travel until the loop + var remainingDistance = (origShowWidth + stoppedLeft) + $children.eq(0).width(); + }else if(options.tickerDirection == 'prev'){ + // get the 'left' property where the ticker stopped + var stoppedLeft = -parseInt($parent.css('left')); + // calculate the remaining distance the show must travel until the loop + var remainingDistance = (stoppedLeft) - $children.eq(0).width(); + } + // calculate the speed ratio to seamlessly finish the loop + var finishingSpeed = (remainingDistance * options.tickerSpeed) / origShowWidth; + // call the show + moveTheShow(tickerLeft, remainingDistance, finishingSpeed); + }else if(options.mode == 'vertical'){ + if(options.tickerDirection == 'next'){ + // get the 'top' property where the ticker stopped + var stoppedTop = parseInt($parent.css('top')); + // calculate the remaining distance the show must travel until the loop + var remainingDistance = (origShowHeight + stoppedTop) + $children.eq(0).height(); + }else if(options.tickerDirection == 'prev'){ + // get the 'left' property where the ticker stopped + var stoppedTop = -parseInt($parent.css('top')); + // calculate the remaining distance the show must travel until the loop + var remainingDistance = (stoppedTop) - $children.eq(0).height(); + } + // calculate the speed ratio to seamlessly finish the loop + var finishingSpeed = (remainingDistance * options.tickerSpeed) / origShowHeight; + // call the show + moveTheShow(tickerTop, remainingDistance, finishingSpeed); + // check if changeText argument is supplied + if(typeof(changeText) == 'undefined'){ + var changeText = true; + } + if(changeText && options.ticker){ + $autoControls.html($stopContent).removeClass('start').addClass('stop'); + autoPlaying = true; + } + } + } + + /** + * Initialize a new slideshow + */ + this.initShow = function(){ + + // reinitialize all variables + // base = this; + $parent = $(this); + $origElement = $parent.clone(); + $children = $parent.children(options.childSelector); + $outerWrapper = $parent; + + $firstChild = $parent.children(options.childSelector + ':first'); + childrenWidth = $firstChild.width(); + childrenMaxWidth = 0; + childrenOuterWidth = $firstChild.outerWidth(); + childrenMaxHeight = 0; + isWorking = false; + $pager = ''; + currentSlide = 0; + origLeft = 0; + origTop = 0; + interval = ''; + $autoControls = ''; + $stopHtml = ''; + $startContent = ''; + $stopContent = ''; + autoPlaying = true; + loaded = false; + origShowWidth = 0; + origShowHeight = 0; + tickerLeft = 0; + tickerTop = 0; - firstSlide = 0; - lastSlide = $children.length - 1; - - // get the largest child's height and width - $children.each(function(index) { - if($(this).outerHeight() > childrenMaxHeight){ - childrenMaxHeight = $(this).outerHeight(); - } - if($(this).outerWidth() > childrenMaxWidth){ - childrenMaxWidth = $(this).outerWidth(); - } - }); + firstSlide = 0; + lastSlide = $children.length - 1; + + // get the largest child's height and width + $children.each(function(index) { + if($(this).outerHeight() > childrenMaxHeight){ + childrenMaxHeight = $(this).outerHeight(); + } + if($(this).outerWidth() > childrenMaxWidth){ + childrenMaxWidth = $(this).outerWidth(); + } + }); + + // get random slide number + if(options.randomStart){ + var randomNumber = Math.floor(Math.random() * $children.length); + currentSlide = lastQty = randomNumber; + origLeft = childrenOuterWidth * (options.moveSlideQty + randomNumber); + origTop = childrenMaxHeight * (options.moveSlideQty + randomNumber); + // start show at specific slide + }else{ + currentSlide = options.startingSlide; + origLeft = childrenOuterWidth * (options.moveSlideQty + options.startingSlide); + origTop = childrenMaxHeight * (options.moveSlideQty + options.startingSlide); + } + + if(options.responsive){ + options.displaySlideQty = base.calculateDisplayQty() || 1; + $(window).bind('resize', resizeWindow); + } + + if(options.displaySlideQty < minSlides) + options.displaySlideQty = minSlides; + + if(options.displaySlideQty > maxSlides) + options.displaySlideQty = maxSlides; + + + wrapperWidth = getWrapperWidth(); + wrapperHeight = getWrapperHeight(); + + + + // set initial css + initCss(); + + // check to show pager + if(options.pager && !options.ticker){ + if(options.pagerType == 'full'){ + showPager('full'); + }else if(options.pagerType == 'short'){ + showPager('short'); + } + } + + // check to show controls + if(options.controls && !options.ticker && $children.length > 1){ + setControlsVars(); + } + + // check if auto + if(options.auto || options.ticker){ + // check if auto controls are displayed + if(options.autoControls){ + setAutoControlsVars(); + } + // check if show should auto start + if(options.autoStart){ + // check if autostart should delay + autoPlaying = false; // prevent playing during the deplay + setTimeout(function(){ + base.startShow(true); + }, options.autoDelay); + }else{ + base.stopShow(true); + } + // check if show should pause on hover + if(options.autoHover && !options.ticker){ + setAutoHover(); + } + } + // make the starting slide active + if(options.moveSlideQty > 1){ + makeSlideActive(Math.ceil(currentSlide / options.moveSlideQty)); + }else{ + makeSlideActive(currentSlide); + } + // check for finite show and if controls should be hidden + checkEndControls(); + // show captions + if(options.captions){ + showCaptions(); + } + - // get random slide number - if(options.randomStart){ - var randomNumber = Math.floor(Math.random() * $children.length); - currentSlide = randomNumber; - origLeft = childrenOuterWidth * (options.moveSlideQty + randomNumber); - origTop = childrenMaxHeight * (options.moveSlideQty + randomNumber); - // start show at specific slide - }else{ - currentSlide = options.startingSlide; - origLeft = childrenOuterWidth * (options.moveSlideQty + options.startingSlide); - origTop = childrenMaxHeight * (options.moveSlideQty + options.startingSlide); - } - - // set initial css - initCss(); - - // check to show pager - if(options.pager && !options.ticker){ - if(options.pagerType == 'full'){ - showPager('full'); - }else if(options.pagerType == 'short'){ - showPager('short'); - } - } - - // check to show controls - if(options.controls && !options.ticker && $children.length > 1){ - setControlsVars(); - } - - // check if auto - if(options.auto || options.ticker){ - // check if auto controls are displayed - if(options.autoControls){ - setAutoControlsVars(); - } - // check if show should auto start - if(options.autoStart){ - // check if autostart should delay - autoPlaying = false; // prevent playing during the deplay - setTimeout(function(){ - base.startShow(true); - }, options.autoDelay); - }else{ - base.stopShow(true); - } - // check if show should pause on hover - if(options.autoHover && !options.ticker){ - setAutoHover(); - } - } - // make the starting slide active - if(options.moveSlideQty > 1){ - makeSlideActive(Math.ceil(currentSlide / options.moveSlideQty)); - }else{ - makeSlideActive(currentSlide); - } - // check for finite show and if controls should be hidden - checkEndControls(); - // show captions - if(options.captions){ - showCaptions(); - } - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - } - - /** - * Destroy the current slideshow - */ - this.destroyShow = function(){ - // stop the auto show - clearInterval(interval); - // remove any controls / pagers that have been appended - $outerWrapper.children('.bx-next, .bx-prev, .bx-pager, .bx-auto').remove(); - // unwrap all bx-wrappers - $parent.unwrap().unwrap().removeAttr('style'); - // remove any styles that were appended - $parent.children(options.childSelector).removeAttr('style').not('.bx-child').remove(); - // remove any childrent that were appended - $children.removeClass('bx-child'); - - } - - /** - * Reload the current slideshow - */ - this.reloadShow = function(){ - base.destroyShow(); - base.initShow(); - } - - // PRIVATE FUNCTIONS - - /** - * Creates all neccessary styling for the slideshow - */ - function initCss(){ - // layout the children - setChildrenLayout(options.startingSlide); - // CSS for horizontal mode - if(options.mode == 'horizontal'){ - // wrap the
    in div that acts as a window and make the
      uber wide - $parent - .wrap('
      ') - .wrap('
      ') - .css({ - width: '999999px', - position: 'relative', - left: '-'+(options.infiniteLoop ? origLeft : 0)+'px' - }); - $parent.children(options.childSelector).css({ - width: childrenWidth, - 'float': 'left', - listStyle: 'none' - }); - $outerWrapper = $parent.parent().parent(); - $children.addClass('bx-child'); - // CSS for vertical mode - }else if(options.mode == 'vertical'){ - // wrap the
        in div that acts as a window and make the
          uber tall - $parent - .wrap('
          ') - .wrap('
          ') - .css({ - height: '999999px', - position: 'relative', - top: '-'+(origTop)+'px' - }); - $parent.children(options.childSelector).css({ - listStyle: 'none', - height: childrenMaxHeight - }); - $outerWrapper = $parent.parent().parent(); - $children.addClass('bx-child'); - // CSS for fade mode - }else if(options.mode == 'fade'){ - // wrap the
            in div that acts as a window - $parent - .wrap('
            ') - .wrap('
            '); - $parent.children(options.childSelector).css({ - listStyle: 'none', - position: 'absolute', - top: 0, - left: 0, - zIndex: 98 - }); - $outerWrapper = $parent.parent().parent(); - $children.not(':eq('+currentSlide+')').fadeTo(0, 0); - $children.eq(currentSlide).css('zIndex', 99); - } - // if captions = true setup a div placeholder - if(options.captions && options.captionsSelector == null){ - $outerWrapper.append('
            '); - } - } - - /** - * Depending on mode, lays out children in the proper setup - */ - function setChildrenLayout(){ - // lays out children for horizontal or vertical modes - if( (options.mode == 'horizontal' || options.mode == 'vertical') && options.infiniteLoop) { - // get the children behind - var $prependedChildren = getArraySample($children, 0, options.moveSlideQty, 'backward'); - - // add each prepended child to the back of the original element - $.each($prependedChildren, function(index) { - $parent.prepend($(this)); - }); - - // total number of slides to be hidden after the window - var totalNumberAfterWindow = ($children.length + options.moveSlideQty) - 1; - // number of original slides hidden after the window - var pagerExcess = $children.length - options.displaySlideQty; - // number of slides to append to the original hidden slides - var numberToAppend = totalNumberAfterWindow - pagerExcess; - // get the sample of extra slides to append - var $appendedChildren = getArraySample($children, 0, numberToAppend, 'forward'); - - if(options.infiniteLoop){ - // add each appended child to the front of the original element - $.each($appendedChildren, function(index) { - $parent.append($(this)); - }); - } - } - } - - /** - * Sets all variables associated with the controls - */ - function setControlsVars(){ - // check if text or images should be used for controls - // check "next" - if(options.nextImage != ''){ - nextContent = options.nextImage; - nextType = 'image'; - }else{ - nextContent = options.nextText; - nextType = 'text'; - } - // check "prev" - if(options.prevImage != ''){ - prevContent = options.prevImage; - prevType = 'image'; - }else{ - prevContent = options.prevText; - prevType = 'text'; - } - // show the controls - showControls(nextType, nextContent, prevType, prevContent); - } - - /** - * Puts slideshow into auto mode - * - * @param int pause number of ms the slideshow will wait between slides - * @param string direction 'forward', 'backward' sets the direction of the slideshow (forward/backward) - * @param bool controls determines if start/stop controls will be displayed - */ - function setAutoInterval(){ - if(options.auto){ - clearInterval(interval); // clear any existing interval - - // finite loop - if(!options.infiniteLoop){ - if(options.autoDirection == 'next'){ - interval = setInterval(function(){ - currentSlide += options.moveSlideQty; - // if currentSlide has exceeded total number - if(currentSlide > lastSlide){ - currentSlide = currentSlide % $children.length; - } - base.goToSlide(currentSlide, false); - }, options.pause); - }else if(options.autoDirection == 'prev'){ - interval = setInterval(function(){ - currentSlide -= options.moveSlideQty; - // if currentSlide is smaller than zero - if(currentSlide < 0){ - negativeOffset = (currentSlide % $children.length); - if(negativeOffset == 0){ - currentSlide = 0; - }else{ - currentSlide = ($children.length) + negativeOffset; - } - } - base.goToSlide(currentSlide, false); - }, options.pause); - } - // infinite loop - }else{ - if(options.autoDirection == 'next'){ - interval = setInterval(function(){ - base.goToNextSlide(false); - }, options.pause); - }else if(options.autoDirection == 'prev'){ - interval = setInterval(function(){ - base.goToPreviousSlide(false); - }, options.pause); - } - } - - }else if(options.ticker){ - - options.tickerSpeed *= 10; - - // get the total width of the original show - $('.bx-child', $outerWrapper).each(function(index) { - origShowWidth += $(this).width(); - origShowHeight += $(this).height(); - }); - - // if prev start the show from the last slide - if(options.tickerDirection == 'prev' && options.mode == 'horizontal'){ - $parent.css('left', '-'+(origShowWidth+origLeft)+'px'); - }else if(options.tickerDirection == 'prev' && options.mode == 'vertical'){ - $parent.css('top', '-'+(origShowHeight+origTop)+'px'); - } - - if(options.mode == 'horizontal'){ - // get the starting left position - tickerLeft = parseInt($parent.css('left')); - // start the ticker - moveTheShow(tickerLeft, origShowWidth, options.tickerSpeed); - }else if(options.mode == 'vertical'){ - // get the starting top position - tickerTop = parseInt($parent.css('top')); - // start the ticker - moveTheShow(tickerTop, origShowHeight, options.tickerSpeed); - } - - // check it tickerHover applies - if(options.tickerHover){ - setTickerHover(); - } - } - } - - function moveTheShow(leftCss, distance, speed){ - // if horizontal - if(options.mode == 'horizontal'){ - // if next - if(options.tickerDirection == 'next'){ - $parent.animate({'left': '-='+distance+'px'}, speed, 'linear', function(){ - $parent.css('left', leftCss); - moveTheShow(leftCss, origShowWidth, options.tickerSpeed); - }); - // if prev - }else if(options.tickerDirection == 'prev'){ - $parent.animate({'left': '+='+distance+'px'}, speed, 'linear', function(){ - $parent.css('left', leftCss); - moveTheShow(leftCss, origShowWidth, options.tickerSpeed); - }); - } - // if vertical - }else if(options.mode == 'vertical'){ - // if next - if(options.tickerDirection == 'next'){ - $parent.animate({'top': '-='+distance+'px'}, speed, 'linear', function(){ - $parent.css('top', leftCss); - moveTheShow(leftCss, origShowHeight, options.tickerSpeed); - }); - // if prev - }else if(options.tickerDirection == 'prev'){ - $parent.animate({'top': '+='+distance+'px'}, speed, 'linear', function(){ - $parent.css('top', leftCss); - moveTheShow(leftCss, origShowHeight, options.tickerSpeed); - }); - } - } - } - - /** - * Sets all variables associated with the controls - */ - function setAutoControlsVars(){ - // check if text or images should be used for controls - // check "start" - if(options.startImage != ''){ - startContent = options.startImage; - startType = 'image'; - }else{ - startContent = options.startText; - startType = 'text'; - } - // check "stop" - if(options.stopImage != ''){ - stopContent = options.stopImage; - stopType = 'image'; - }else{ - stopContent = options.stopText; - stopType = 'text'; - } - // show the controls - showAutoControls(startType, startContent, stopType, stopContent); - } - - /** - * Handles hover events for auto shows - */ - function setAutoHover(){ - // hover over the slider window - $outerWrapper.children('.bx-window').hover(function() { - if(autoPlaying){ - base.suspendShow(false); - } - }, function() { - if(autoPlaying){ - base.restartShow(false); - } - }); - } - - /** - * Handles hover events for ticker mode - */ - function setTickerHover(){ - // on hover stop the animation - $parent.hover(function() { - if(autoPlaying){ - base.stopTicker(false); - } - }, function() { - if(autoPlaying){ - base.startTicker(false); - } - }); - } - - /** - * Handles fade animation - */ - function setChildrenFade(){ - // fade out any other child besides the current - $children.not(':eq('+currentSlide+')').fadeTo(options.speed, 0).css('zIndex', 98); - // fade in the current slide - $children.eq(currentSlide).css('zIndex', 99).fadeTo(options.speed, 1, function(){ - isWorking = false; - // ie fade fix - if(jQuery.browser.msie){ - $children.eq(currentSlide).get(0).style.removeAttribute('filter'); - } - // perform the callback function - options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); - }); - }; - - /** - * Makes slide active - */ - function makeSlideActive(number){ - if(options.pagerType == 'full' && options.pager){ - // remove all active classes - $('a', $pager).removeClass(options.pagerActiveClass); - // assign active class to appropriate slide - $('a', $pager).eq(number).addClass(options.pagerActiveClass); - }else if(options.pagerType == 'short' && options.pager){ - $('.bx-pager-current', $pager).html(currentSlide+1); - } - } - - /** - * Displays next/prev controls - * - * @param string nextType 'image', 'text' - * @param string nextContent if type='image', specify a filepath to the image. if type='text', specify text. - * @param string prevType 'image', 'text' - * @param string prevContent if type='image', specify a filepath to the image. if type='text', specify text. - */ - function showControls(nextType, nextContent, prevType, prevContent){ - // create pager html elements - var $nextHtml = $(''); - var $prevHtml = $(''); - // check if next is 'text' or 'image' - if(nextType == 'text'){ - $nextHtml.html(nextContent); - }else{ - $nextHtml.html(''); - } - // check if prev is 'text' or 'image' - if(prevType == 'text'){ - $prevHtml.html(prevContent); - }else{ - $prevHtml.html(''); - } - // check if user supplied a selector to populate next control - if(options.prevSelector){ - $(options.prevSelector).append($prevHtml); - }else{ - $outerWrapper.append($prevHtml); - } - // check if user supplied a selector to populate next control - if(options.nextSelector){ - $(options.nextSelector).append($nextHtml); - }else{ - $outerWrapper.append($nextHtml); - } - // click next control - $nextHtml.click(function() { - base.goToNextSlide(); - return false; - }); - // click prev control - $prevHtml.click(function() { - base.goToPreviousSlide(); - return false; - }); - } - - /** - * Displays the pager - * - * @param string type 'full', 'short' - */ - function showPager(type){ - // sets up logic for finite multi slide shows - var pagerQty = $children.length; - // if we are moving more than one at a time and we have a finite loop - if(options.moveSlideQty > 1){ - // if slides create an odd number of pages - if($children.length % options.moveSlideQty != 0){ - // pagerQty = $children.length / options.moveSlideQty + 1; - pagerQty = Math.ceil($children.length / options.moveSlideQty); - // if slides create an even number of pages - }else{ - pagerQty = $children.length / options.moveSlideQty; - } - } - var pagerString = ''; - // check if custom build function was supplied - if(options.buildPager){ - for(var i=0; i'+i+''; - } - }else if(type == 'short') { - // build the short pager - pagerString = ''+(options.startingSlide+1)+' '+options.pagerShortSeparator+' '+$children.length+''; - } - // check if user supplied a pager selector - if(options.pagerSelector){ - $(options.pagerSelector).append(pagerString); - $pager = $(options.pagerSelector); - }else{ - var $pagerContainer = $('
            '); - $pagerContainer.append(pagerString); - // attach the pager to the DOM - if(options.pagerLocation == 'top'){ - $outerWrapper.prepend($pagerContainer); - }else if(options.pagerLocation == 'bottom'){ - $outerWrapper.append($pagerContainer); - } - // cache the pager element - $pager = $outerWrapper.children('.bx-pager'); - } - $pager.children().click(function() { - // only if pager is full mode - if(options.pagerType == 'full'){ - // get the index from the link - var slideIndex = $pager.children().index(this); - // accomodate moving more than one slide - if(options.moveSlideQty > 1){ - slideIndex *= options.moveSlideQty; - } - base.goToSlide(slideIndex); - } - return false; - }); - } - - /** - * Displays captions - */ - function showCaptions(){ - // get the title from each image - var caption = $('img', $children.eq(currentSlide)).attr('title'); - // if the caption exists - if(caption != ''){ - // if user supplied a selector - if(options.captionsSelector){ - $(options.captionsSelector).html(caption); - }else{ - $outerWrapper.children('.bx-captions').html(caption); - } - }else{ - // if user supplied a selector - if(options.captionsSelector){ - $(options.captionsSelector).html(' '); - }else{ - $outerWrapper.children('.bx-captions').html(' '); - } - } - } - - /** - * Displays start/stop controls for auto and ticker mode - * - * @param string type 'image', 'text' - * @param string next [optional] if type='image', specify a filepath to the image. if type='text', specify text. - * @param string prev [optional] if type='image', specify a filepath to the image. if type='text', specify text. - */ - function showAutoControls(startType, startContent, stopType, stopContent){ - // create pager html elements - $autoControls = $(''); - // check if start is 'text' or 'image' - if(startType == 'text'){ - $startContent = startContent; - }else{ - $startContent = ''; - } - // check if stop is 'text' or 'image' - if(stopType == 'text'){ - $stopContent = stopContent; - }else{ - $stopContent = ''; - } - // check if user supplied a selector to populate next control - if(options.autoControlsSelector){ - $(options.autoControlsSelector).append($autoControls); - }else{ - $outerWrapper.append('
            '); - $outerWrapper.children('.bx-auto').html($autoControls); - } - - // click start control - $autoControls.click(function() { - if(options.ticker){ - if($(this).hasClass('stop')){ - base.stopTicker(); - }else if($(this).hasClass('start')){ - base.startTicker(); - } - }else{ - if($(this).hasClass('stop')){ - base.stopShow(true); - }else if($(this).hasClass('start')){ - base.startShow(true); - } - } - return false; - }); - - } - - /** - * Checks if show is in finite mode, and if slide is either first or last, then hides the respective control - */ - function checkEndControls(){ - if(!options.infiniteLoop && options.hideControlOnEnd){ - // check previous - if(currentSlide == firstSlide){ - $outerWrapper.children('.bx-prev').hide(); - }else{ - $outerWrapper.children('.bx-prev').show(); - } - // check next - var lastPossibleSlide = Math.floor(lastSlide/options.displaySlideQty) * options.displaySlideQty; + + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + } + + /** + * Destroy the current slideshow + */ + this.destroyShow = function(){ + // stop the auto show + clearInterval(interval); + // remove any controls / pagers that have been appended + $outerWrapper.children('.bx-next, .bx-prev, .bx-pager, .bx-auto').remove(); + // unwrap all bx-wrappers + $parent.unwrap().unwrap().removeAttr('style'); + // remove any styles that were appended + $parent.children(options.childSelector).removeAttr('style').not('.bx-child').remove(); + // remove any childrent that were appended + $children.removeClass('bx-child'); + + if(options.responsive) $(window).unbind('resize', resizeWindow); + } + + /** + * Reload the current slideshow + */ + this.reloadShow = function(){ + base.destroyShow(); + base.initShow(); + } + + // PRIVATE FUNCTIONS + + /** + * Creates all neccessary styling for the slideshow + */ + function initCss(){ + // layout the children + setChildrenLayout(options.startingSlide); + // CSS for horizontal mode + if(options.mode == 'horizontal'){ + // wrap the
              in div that acts as a window and make the
                uber wide + $parent + .wrap('
                ') + .wrap('
                ') + .css({ + width: '999999px', + position: 'relative', + left: '-'+(options.infiniteLoop ? origLeft : 0)+'px' + }); + $parent.children(options.childSelector).css({ + width: childrenWidth, + 'float': 'left', + listStyle: 'none' + }); + $outerWrapper = $parent.parent().parent(); + $children.addClass('bx-child'); + // CSS for vertical mode + }else if(options.mode == 'vertical'){ + // wrap the
                  in div that acts as a window and make the
                    uber tall + $parent + .wrap('
                    ') + .wrap('
                    ') + .css({ + height: '999999px', + position: 'relative', + top: '-'+(origTop)+'px' + }); + $parent.children(options.childSelector).css({ + listStyle: 'none', + height: childrenMaxHeight + }); + $outerWrapper = $parent.parent().parent(); + $children.addClass('bx-child'); + // CSS for fade mode + }else if(options.mode == 'fade'){ + // wrap the
                      in div that acts as a window + $parent + .wrap('
                      ') + .wrap('
                      '); + $parent.children(options.childSelector).css({ + listStyle: 'none', + position: 'absolute', + top: 0, + left: 0, + zIndex: 98 + }); + $outerWrapper = $parent.parent().parent(); + $children.not(':eq('+currentSlide+')').fadeTo(0, 0); + $children.eq(currentSlide).css('zIndex', 99); + } + // if captions = true setup a div placeholder + if(options.captions && options.captionsSelector == null){ + $outerWrapper.append('
                      '); + } + } + + /** + * Depending on mode, lays out children in the proper setup + */ + function setChildrenLayout(){ + // lays out children for horizontal or vertical modes + if( (options.mode == 'horizontal' || options.mode == 'vertical') && options.infiniteLoop) { + // get the children behind + var $prependedChildren = getArraySample($children, 0, options.moveSlideQty, 'backward'); + + // add each prepended child to the back of the original element + $.each($prependedChildren, function(index) { + $parent.prepend($(this)); + }); + + // total number of slides to be hidden after the window + var totalNumberAfterWindow = ($children.length + options.moveSlideQty) - 1; + // number of original slides hidden after the window + + var pagerExcess = $children.length - options.displaySlideQty; + // number of slides to append to the original hidden slides + var numberToAppend = totalNumberAfterWindow - pagerExcess; + // get the sample of extra slides to append + var $appendedChildren = getArraySample($children, 0, numberToAppend, 'forward'); + + if(options.infiniteLoop){ + // add each appended child to the front of the original element + $.each($appendedChildren, function(index) { + $parent.append($(this)); + }); + } + } + } + + /** + * Sets all variables associated with the controls + */ + function setControlsVars(){ + // check if text or images should be used for controls + // check "next" + if(options.nextImage != ''){ + nextContent = options.nextImage; + nextType = 'image'; + }else{ + nextContent = options.nextText; + nextType = 'text'; + } + // check "prev" + if(options.prevImage != ''){ + prevContent = options.prevImage; + prevType = 'image'; + }else{ + prevContent = options.prevText; + prevType = 'text'; + } + // show the controls + showControls(nextType, nextContent, prevType, prevContent); + } + + /** + * Puts slideshow into auto mode + * + * @param int pause number of ms the slideshow will wait between slides + * @param string direction 'forward', 'backward' sets the direction of the slideshow (forward/backward) + * @param bool controls determines if start/stop controls will be displayed + */ + function setAutoInterval(){ + if(options.auto){ + clearInterval(interval); // clear any existing interval + + // finite loop + if(!options.infiniteLoop){ + if(options.autoDirection == 'next'){ + interval = setInterval(function(){ + currentSlide += options.moveSlideQty; + // if currentSlide has exceeded total number + if(currentSlide > lastSlide){ + currentSlide = currentSlide % $children.length; + } + base.goToSlide(currentSlide, false); + }, options.pause); + }else if(options.autoDirection == 'prev'){ + interval = setInterval(function(){ + currentSlide -= options.moveSlideQty; + // if currentSlide is smaller than zero + if(currentSlide < 0){ + negativeOffset = (currentSlide % $children.length); + if(negativeOffset == 0){ + currentSlide = 0; + }else{ + currentSlide = ($children.length) + negativeOffset; + } + } + base.goToSlide(currentSlide, false); + }, options.pause); + } + // infinite loop + }else{ + if(options.autoDirection == 'next'){ + interval = setInterval(function(){ + base.goToNextSlide(false); + }, options.pause); + }else if(options.autoDirection == 'prev'){ + interval = setInterval(function(){ + base.goToPreviousSlide(false); + }, options.pause); + } + } + + }else if(options.ticker){ + + options.tickerSpeed *= 10; + + // get the total width of the original show + $('.bx-child', $outerWrapper).each(function(index) { + origShowWidth += $(this).width(); + origShowHeight += $(this).height(); + }); + + // if prev start the show from the last slide + if(options.tickerDirection == 'prev' && options.mode == 'horizontal'){ + $parent.css('left', '-'+(origShowWidth+origLeft)+'px'); + }else if(options.tickerDirection == 'prev' && options.mode == 'vertical'){ + $parent.css('top', '-'+(origShowHeight+origTop)+'px'); + } + + if(options.mode == 'horizontal'){ + // get the starting left position + tickerLeft = parseInt($parent.css('left')); + // start the ticker + moveTheShow(tickerLeft, origShowWidth, options.tickerSpeed); + }else if(options.mode == 'vertical'){ + // get the starting top position + tickerTop = parseInt($parent.css('top')); + // start the ticker + moveTheShow(tickerTop, origShowHeight, options.tickerSpeed); + } + + // check it tickerHover applies + if(options.tickerHover){ + setTickerHover(); + } + } + } + + function moveTheShow(leftCss, distance, speed){ + // if horizontal + if(options.mode == 'horizontal'){ + // if next + if(options.tickerDirection == 'next'){ + $parent.animate({'left': '-='+distance+'px'}, speed, 'linear', function(){ + $parent.css('left', leftCss); + moveTheShow(leftCss, origShowWidth, options.tickerSpeed); + }); + // if prev + }else if(options.tickerDirection == 'prev'){ + $parent.animate({'left': '+='+distance+'px'}, speed, 'linear', function(){ + $parent.css('left', leftCss); + moveTheShow(leftCss, origShowWidth, options.tickerSpeed); + }); + } + // if vertical + }else if(options.mode == 'vertical'){ + // if next + if(options.tickerDirection == 'next'){ + $parent.animate({'top': '-='+distance+'px'}, speed, 'linear', function(){ + $parent.css('top', leftCss); + moveTheShow(leftCss, origShowHeight, options.tickerSpeed); + }); + // if prev + }else if(options.tickerDirection == 'prev'){ + $parent.animate({'top': '+='+distance+'px'}, speed, 'linear', function(){ + $parent.css('top', leftCss); + moveTheShow(leftCss, origShowHeight, options.tickerSpeed); + }); + } + } + } + + /** + * Sets all variables associated with the controls + */ + function setAutoControlsVars(){ + // check if text or images should be used for controls + // check "start" + if(options.startImage != ''){ + startContent = options.startImage; + startType = 'image'; + }else{ + startContent = options.startText; + startType = 'text'; + } + // check "stop" + if(options.stopImage != ''){ + stopContent = options.stopImage; + stopType = 'image'; + }else{ + stopContent = options.stopText; + stopType = 'text'; + } + // show the controls + showAutoControls(startType, startContent, stopType, stopContent); + } + + /** + * Handles hover events for auto shows + */ + function setAutoHover(){ + // hover over the slider window + $outerWrapper.children('.bx-window').hover(function() { + if(autoPlaying){ + base.suspendShow(false); + } + }, function() { + if(autoPlaying){ + base.restartShow(false); + } + }); + } + + /** + * Handles hover events for ticker mode + */ + function setTickerHover(){ + // on hover stop the animation + $parent.hover(function() { + if(autoPlaying){ + base.stopTicker(false); + } + }, function() { + if(autoPlaying){ + base.startTicker(false); + } + }); + } + + /** + * Handles fade animation + */ + function setChildrenFade(){ + // fade out any other child besides the current + $children.not(':eq('+currentSlide+')').fadeTo(options.speed, 0).css('zIndex', 98); + // fade in the current slide + $children.eq(currentSlide).css('zIndex', 99).fadeTo(options.speed, 1, function(){ + isWorking = false; + // ie fade fix + if(jQuery.browser.msie){ + $children.eq(currentSlide).get(0).style.removeAttribute('filter'); + } + // perform the callback function + options.onAfterSlide(currentSlide, $children.length, $children.eq(currentSlide)); + }); + }; + + /** + * Makes slide active + */ + function makeSlideActive(number){ + if(options.pagerType == 'full' && options.pager){ + // remove all active classes + $('a', $pager).removeClass(options.pagerActiveClass); + // assign active class to appropriate slide + $('a', $pager).eq(number).addClass(options.pagerActiveClass); + }else if(options.pagerType == 'short' && options.pager){ + $('.bx-pager-current', $pager).html(currentSlide+1); + } + } + + /** + * Displays next/prev controls + * + * @param string nextType 'image', 'text' + * @param string nextContent if type='image', specify a filepath to the image. if type='text', specify text. + * @param string prevType 'image', 'text' + * @param string prevContent if type='image', specify a filepath to the image. if type='text', specify text. + */ + function showControls(nextType, nextContent, prevType, prevContent){ + // create pager html elements + var $nextHtml = $(''); + var $prevHtml = $(''); + // check if next is 'text' or 'image' + if(nextType == 'text'){ + $nextHtml.html(nextContent); + }else{ + $nextHtml.html(''); + } + // check if prev is 'text' or 'image' + if(prevType == 'text'){ + $prevHtml.html(prevContent); + }else{ + $prevHtml.html(''); + } + // check if user supplied a selector to populate next control + if(options.prevSelector){ + $(options.prevSelector).append($prevHtml); + }else{ + $outerWrapper.append($prevHtml); + } + // check if user supplied a selector to populate next control + if(options.nextSelector){ + $(options.nextSelector).append($nextHtml); + }else{ + $outerWrapper.append($nextHtml); + } + // click next control + $nextHtml.click(function() { + base.goToNextSlide(); + return false; + }); + // click prev control + $prevHtml.click(function() { + base.goToPreviousSlide(); + return false; + }); + } + + /** + * Displays the pager + * + * @param string type 'full', 'short' + */ + function showPager(type){ + // sets up logic for finite multi slide shows + var pagerQty = $children.length; + // if we are moving more than one at a time and we have a finite loop + if(options.moveSlideQty > 1){ + // if slides create an odd number of pages + if($children.length % options.moveSlideQty != 0){ + // pagerQty = $children.length / options.moveSlideQty + 1; + pagerQty = Math.ceil($children.length / options.moveSlideQty); + // if slides create an even number of pages + }else{ + pagerQty = $children.length / options.moveSlideQty; + } + } + var pagerString = ''; + // check if custom build function was supplied + if(options.buildPager){ + for(var i=0; i'+i+''; + } + }else if(type == 'short') { + // build the short pager + pagerString = ''+(options.startingSlide+1)+' '+options.pagerShortSeparator+' '+$children.length+''; + } + // check if user supplied a pager selector + if(options.pagerSelector){ + $(options.pagerSelector).append(pagerString); + $pager = $(options.pagerSelector); + }else{ + var $pagerContainer = $('
                      '); + $pagerContainer.append(pagerString); + // attach the pager to the DOM + if(options.pagerLocation == 'top'){ + $outerWrapper.prepend($pagerContainer); + }else if(options.pagerLocation == 'bottom'){ + $outerWrapper.append($pagerContainer); + } + // cache the pager element + $pager = $outerWrapper.children('.bx-pager'); + } + $pager.children().click(function() { + // only if pager is full mode + if(options.pagerType == 'full'){ + // get the index from the link + var slideIndex = $pager.children().index(this); + // accomodate moving more than one slide + if(options.moveSlideQty > 1){ + slideIndex *= options.moveSlideQty; + } + base.goToSlide(slideIndex); + } + return false; + }); + } + + /** + * Displays captions + */ + function showCaptions(){ + // get the title from each image + var caption = $('img', $children.eq(currentSlide)).attr('title'); + // if the caption exists + if(caption != ''){ + // if user supplied a selector + if(options.captionsSelector){ + $(options.captionsSelector).html(caption); + }else{ + $outerWrapper.children('.bx-captions').html(caption); + } + }else{ + // if user supplied a selector + if(options.captionsSelector){ + $(options.captionsSelector).html(' '); + }else{ + $outerWrapper.children('.bx-captions').html(' '); + } + } + } + + /** + * Displays start/stop controls for auto and ticker mode + * + * @param string type 'image', 'text' + * @param string next [optional] if type='image', specify a filepath to the image. if type='text', specify text. + * @param string prev [optional] if type='image', specify a filepath to the image. if type='text', specify text. + */ + function showAutoControls(startType, startContent, stopType, stopContent){ + // create pager html elements + $autoControls = $(''); + // check if start is 'text' or 'image' + if(startType == 'text'){ + $startContent = startContent; + }else{ + $startContent = ''; + } + // check if stop is 'text' or 'image' + if(stopType == 'text'){ + $stopContent = stopContent; + }else{ + $stopContent = ''; + } + // check if user supplied a selector to populate next control + if(options.autoControlsSelector){ + $(options.autoControlsSelector).append($autoControls); + }else{ + $outerWrapper.append('
                      '); + $outerWrapper.children('.bx-auto').html($autoControls); + } + + // click start control + $autoControls.click(function() { + if(options.ticker){ + if($(this).hasClass('stop')){ + base.stopTicker(); + }else if($(this).hasClass('start')){ + base.startTicker(); + } + }else{ + if($(this).hasClass('stop')){ + base.stopShow(true); + }else if($(this).hasClass('start')){ + base.startShow(true); + } + } + return false; + }); + + } + + /** + * Checks if show is in finite mode, and if slide is either first or last, then hides the respective control + */ + function checkEndControls(){ + if(!options.infiniteLoop && options.hideControlOnEnd){ + // check previous + if(currentSlide == firstSlide){ + $outerWrapper.children('.bx-prev').hide(); + }else{ + $outerWrapper.children('.bx-prev').show(); + } + // check next + var lastPossibleSlide = Math.floor(lastSlide/options.displaySlideQty) * options.displaySlideQty; if(currentSlide >= lastPossibleSlide){ - $outerWrapper.children('.bx-next').hide(); - }else{ - $outerWrapper.children('.bx-next').show(); - } - } - } - - /** - * Returns the left offset of the slide from the parent container - */ - function getSlidePosition(number, side){ - var $slidePosition = $parent.find(' > .bx-child').eq(number).position(); - return (side == 'left') ? $slidePosition.left : $slidePosition.top; - } - - /** - * Returns the width of the wrapper - */ - function getWrapperWidth(){ - var wrapperWidth = $firstChild.outerWidth() * options.displaySlideQty; - return wrapperWidth; - } - - /** - * Returns the height of the wrapper - */ - function getWrapperHeight(){ - // if displaying multiple slides, multiple wrapper width by number of slides to display - var wrapperHeight = $firstChild.outerHeight() * options.displaySlideQty; - return wrapperHeight; - } - - /** - * Returns a sample of an arry and loops back on itself if the end of the array is reached - * - * @param array array original array the sample is derived from - * @param int start array index sample will start - * @param int length number of items in the sample - * @param string direction 'forward', 'backward' direction the loop should travel in the array - */ - function getArraySample(array, start, length, direction){ - // initialize empty array - var sample = []; - // clone the length argument - var loopLength = length; - // determines when the empty array should start being populated - var startPopulatingArray = false; - // reverse the array if direction = 'backward' - if(direction == 'backward'){ - array = $.makeArray(array); - array.reverse(); - } - // loop through original array until the length argument is met - while(loopLength > 0){ - // loop through original array - $.each(array, function(index, val) { - // check if length has been met - if(loopLength > 0){ - // don't do anything unless first index has been reached - if(!startPopulatingArray){ - // start populating empty array - if(index == start){ - startPopulatingArray = true; - // add element to array - sample.push($(this).clone()); - // decrease the length clone variable - loopLength--; - } - }else{ - // add element to array - sample.push($(this).clone()); - // decrease the length clone variable - loopLength--; - } - // if length has been met, break loose - }else{ - return false; - } - }); - } - return sample; - } - - this.each(function(){ - // make sure the element has children - if($(this).children().length > 0){ - base.initShow(); - } - }); - - return this; - } - - jQuery.fx.prototype.cur = function(){ - if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) { - return this.elem[ this.prop ]; - } + $outerWrapper.children('.bx-next').hide(); + }else{ + $outerWrapper.children('.bx-next').show(); + } + } + } + + /** + * Returns the left offset of the slide from the parent container + */ + function getSlidePosition(number, side){ + var $slidePosition = $parent.find(' > .bx-child').eq(number).position(); + return (side == 'left') ? $slidePosition.left : $slidePosition.top; + } + + /** + * Returns the width of the wrapper + */ + function getWrapperWidth(){ + var wrapperWidth = $firstChild.outerWidth() * options.displaySlideQty; + return wrapperWidth; + } + + /** + * Returns the height of the wrapper + */ + function getWrapperHeight(){ + // if displaying multiple slides, multiple wrapper width by number of slides to display + var wrapperHeight = $firstChild.outerHeight() * options.displaySlideQty; + return wrapperHeight; + } + + /** + * Returns a sample of an arry and loops back on itself if the end of the array is reached + * + * @param array array original array the sample is derived from + * @param int start array index sample will start + * @param int length number of items in the sample + * @param string direction 'forward', 'backward' direction the loop should travel in the array + */ + function getArraySample(array, start, length, direction){ + // initialize empty array + var sample = []; + // clone the length argument + var loopLength = length; + // determines when the empty array should start being populated + var startPopulatingArray = false; + // reverse the array if direction = 'backward' + if(direction == 'backward'){ + array = $.makeArray(array); + array.reverse(); + } + // loop through original array until the length argument is met + while(loopLength > 0){ + // loop through original array + $.each(array, function(index, val) { + // check if length has been met + if(loopLength > 0){ + // don't do anything unless first index has been reached + if(!startPopulatingArray){ + // start populating empty array + if(index == start){ + startPopulatingArray = true; + // add element to array + sample.push($(this).clone()); + // decrease the length clone variable + loopLength--; + } + }else{ + // add element to array + sample.push($(this).clone()); + // decrease the length clone variable + loopLength--; + } + // if length has been met, break loose + }else{ + return false; + } + }); + } + return sample; + } + + this.each(function(){ + // make sure the element has children + if($(this).children().length > 0){ + base.initShow(); + } + }); + + return this; + } + + jQuery.fx.prototype.cur = function(){ + if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) { + return this.elem[ this.prop ]; + } - var r = parseFloat( jQuery.css( this.elem, this.prop ) ); - // return r && r > -10000 ? r : 0; - return r; - } + var r = parseFloat( jQuery.css( this.elem, this.prop ) ); + // return r && r > -10000 ? r : 0; + return r; + } - + })(jQuery);