Skip to content

Instantly share code, notes, and snippets.

@tylr
Created August 26, 2010 23:06
Show Gist options
  • Save tylr/552433 to your computer and use it in GitHub Desktop.
Save tylr/552433 to your computer and use it in GitHub Desktop.
PP.Rotator = function(){
_rotator = {
_opts: {
interval: 5,
rotate: function(){}
},
_timer: null,
start: function(){
this.setTimer();
},
stop: function(){
if (this._timer)
window.clearTimeout(this._timer);
},
next: function(){
this.reset();
this._opts.rotate();
},
reset: function(){
this.stop();
this.start();
},
setTimer: function(){
var that = this;
that._timer = setTimeout(function(){
that._opts.rotate();
that.setTimer();
}, that._opts.interval * 1000);
}
};
function init(opts){
var self = $.extend(true, {}, _rotator);
if (opts) $.extend(self._opts, opts);
return self;
};
return {
init: init
};
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment