From 872fd919fd6b8c89c9fcec6aca13795399d57898 Mon Sep 17 00:00:00 2001 From: Henry Cooke Date: Wed, 6 Mar 2013 13:21:24 +0000 Subject: [PATCH] added slidechange event & play, pause and toggleControls methods with public accessors --- js/bjqs-1.3.js | 54 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/js/bjqs-1.3.js b/js/bjqs-1.3.js index f06e7b2..5c53506 100755 --- a/js/bjqs-1.3.js +++ b/js/bjqs-1.3.js @@ -163,14 +163,35 @@ $slider.show(); $slides.eq(state.currentindex).show(); - // Finally, if automatic is set to true, kick off the interval + // Finally, if automatic is set to true, play if(settings.automatic){ - state.interval = setInterval(function () { + play( false ); + } + + }; + + var play = function( immediate ) { + // if there's an interval already set, bail + if( state.interval !== null ) return; + + // kick off the interval + state.interval = setInterval(function () { go(vars.fwd, false); }, settings.animspeed); - } + + // start immediately if we've been asked + if( immediate ) go(vars.fwd, false); + }; + // public accessor + $wrapper.play = play; + var stop = function() + { + clearInterval( state.interval ); + state.interval = null; }; + // public accessor + $wrapper.stop = stop; var conf_responsive = function() { @@ -630,6 +651,8 @@ set_next(direction); } + var outgoingindex = state.currentindex-1; + // fade animation if(settings.animtype === 'fade'){ @@ -648,6 +671,10 @@ state.currentslide = state.nextslide; state.currentindex = state.nextindex; + // emit slide change event + var e = jQuery.Event( "slidechange", { outgoingindex: outgoingindex, incomingindex: state.currentindex-1 } ); + $wrapper.trigger( e ); + }); } @@ -703,14 +730,31 @@ state.animating = false; + // emit slide change event + var e = jQuery.Event( "slidechange", { outgoingindex: outgoingindex, incomingindex: state.currentindex-1 } ); + $wrapper.trigger( e ); + }); } - } - }; + $wrapper.toggleControls = function( show, duration ) { + if( !duration && duration !== 0 ) duration = defaults.animduration; + $c_fwd = $wrapper.find( "li.bjqs-next a" ); + $c_prev = $wrapper.find( "li.bjqs-prev a" ); + if( $c_fwd.length > 0 && $c_prev.length > 0 ){ + if( show ) { + $c_fwd.fadeIn( duration ); + $c_prev.fadeIn( duration ); + } else { + $c_fwd.fadeOut( duration ); + $c_prev.fadeOut( duration ); + } + } + }; + // lets get the party started :) init();