Skip to content

maxschuster/jQuery.timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jQuery.timer

Licence: Apache License, Version 2.0
Demo: http://dev.maxschuster.eu/jQuery.timer/

jQuery wrapper for setInterval() with events

Table of contents

Example

var $timer = $({}).timer({
      'delay': 1000,
      'repeatCount': 5
}).on('tick.timer complete.timer stop.timer start.timer reset.timer destroy.timer', function(e, d) {
      console.log(e.type, d);
}).timer('start');

Methods

init

Initializes the plugin on a jQuery object

Usage:

$({}).timer(options);

Parameter:

Name Type Default Comment
options Object {} Plugin options to override predefined settings. (See Settings)

Returns:

jQuery Object To provide chainability.

start

Starts the timer

Usage:

$({}).timer('start');

Returns:

jQuery Object To provide chainability.

stop

Stops the timer

Usage:

$({}).timer('stop', triggerEvent);

Parameter:

Name Type Default Comment
triggerEvent Boolean true Trigger the stop.timer event?

Returns:

jQuery Object To provide chainability.

reset

Stops the timer and resets its repeatCount.

Usage:

$({}).timer('reset');

Returns:

jQuery Object To provide chainability.

destroy

Removes the timer from the current jQuery object

Usage:

$({}).timer('destroy');

Returns:

jQuery Object To provide chainability.

Events

Usage Sample:

$({}).timer({
      'repeatCount': 5
}).on('tick.timer, function(event, data) {
      console.log(event, data);
});

Handler parameter

Name Type Comment
event Object jQuery event
data Object Timer information (Boolean running, Integer repeatCount, Integer delay, Integer currentCount)

tick.timer

Dispatched whenever a Timer object reaches an interval specified according to the delay option.

complete.timer

Dispatched whenever it has completed the number of requests set by repeatCount option.

stop.timer

Dispatched whenever the timer has been stoped.

start.timer

Dispatched whenever the timer has been started.

reset.timer

Dispatched whenever the timer has been reseted.

destroy.timer

Dispatched whenever the timer has been destroyed.

Settings

delay

The delay between tick.timer events in milliseconds.
Type: Integer
Default: 1000

repeatCount

The number of times the timer has to tick till its complete
Type: Integer
Default: 1

autoStart

Start the timer after initializing
Type: Boolean
Default: false

About

jQuery wrapper for setInterval() with events

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published