Sha256: a241ef7202a2e29dc053bddfcfa40115b8af6ae88a03e37811dc55881e404662

Contents?: true

Size: 1.38 KB

Versions: 38

Compression:

Stored size: 1.38 KB

Contents

/*
 *
 *	jQuery Timer plugin v0.1
 *		Matt Schmidt [http://www.mattptr.net]
 *
 *	Licensed under the BSD License:
 *		http://mattptr.net/license/license.txt
 *
 */
 
 jQuery.timer = function (interval, callback)
 {
 /**
  *
  * timer() provides a cleaner way to handle intervals  
  *
  *	@usage
  * $.timer(interval, callback);
  *
  *
  * @example
  * $.timer(1000, function (timer) {
  * 	alert("hello");
  * 	timer.stop();
  * });
  * @desc Show an alert box after 1 second and stop
  * 
  * @example
  * var second = false;
  *	$.timer(1000, function (timer) {
  *		if (!second) {
  *			alert('First time!');
  *			second = true;
  *			timer.reset(3000);
  *		}
  *		else {
  *			alert('Second time');
  *			timer.stop();
  *		}
  *	});
  * @desc Show an alert box after 1 second and show another after 3 seconds
  *
  * 
  */

	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || interval || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
picky-generators-1.3.4 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.3.3 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.3.2 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.3.1 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.3.0 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.2.4 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.2.3 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.2.2 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.2.1 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.2.0 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.7 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.6 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.5 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.4 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.3 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.2 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.1 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-generators-1.1.0 prototypes/client/sinatra/javascripts/jquery.timer.js
picky-client-1.1.0 sinatra_prototype/javascripts/jquery.timer.js
picky-client-1.0.0 sinatra_prototype/javascripts/jquery.timer.js