UnderZ

Javascript Library.

Added in v 1.0.0

(window Bound)

Timer.

Creating a timer to call a function or evaluates an expression at specified intervals (in milliseconds).


As in v 1.0.0

Schedule a function

new _z.timer(function);

Returns: Object Timer object

This method is a shortcut for _z.timer(1000, function).


Schedule a function to execute at specified intervals

new _z.timer(function, milliseconds);

Returns: Object Timer object


Timer object

Timer object is object contains all timer options (interval, callback function, stop(), …).

To create Timer object use:

var timer = new _z.timer(function);

So that timer is variable contains Timer object.


Timer object properties

Stop execution of all timers

_z.timer.hold

Default timer interval

_z.timer.interval

Timers list

_z.timer.instances

Start all existing timers

_z.timer.startAll()

Stop all existing timers

_z.timer.stopAll()

Remove all existing timers

_z.timer.removeAll(keepData)

Timer object properties

Variables:

  1. callback: Contains the function to execute.
  2. interval: Contains the intervals (in milliseconds) on how often to execute the function (in milliseconds).
  3. isRunning: Contains Boolean value, the status of the timer.

Methods:

  1. start: Start the timer.
  2. stop: Stop the timer.
  3. once: Start the timer once, no repeat.
  4. remove: Delete this timer object.
  5. execFunction: Execute the function.

Examples

var timer1 = new _z.timer(function() {
    document.title = fns.time('s') + ":" + fns.time('m');
});
// execute every 1 second
timer1.interval = 1000 * 1;
timer1.isRunning; // false
timer1.isReady(); // true
timer1.start();
timer1.isReady(); // false
timer1.isRunning; // true
timer1.stop();
timer1.isRunning; // false
timer1.start();
timer1.isRunning; // true
_z.timer.startAll();
timer1.isRunning; // true

var timer2 = new _z.timer(function() {
    document.title = "Execite once";
});
timer2.once(true); // set as one timer execution **execute after X second**
timer2.isReady(); // true
timer2.start(); // EXECUTE SUCCESS
timer2.isReady(); // false
timer2.isRunnung; // false
timer2.start(); // EXECUTE FAILD
timer2.execFunction(); // EXECUTE SUCCESS


timer1.isRunnung; // true
timer2.isRunnung; // false
_z.timer.hold = true;
timer1.isRunnung; // false
timer2.isRunnung; // false
_z.timer.hold = false;
timer1.isRunnung; // true
timer2.isRunnung; // false
_z.timer.stopAll();
timer1.isRunnung; // false
timer2.isRunnung; // false
timer1.remove(true);
_z.timer.startAll();
timer1.isRunnung; // false
timer1.isReady(); // true
timer1.start();
timer1.isRunnung; // true
timer1.isReady(); // false
_z.timer.stopAll();
timer1.isRunnung; // true
timer1.isReady(); // false
timer1.stop();
timer1.isRunnung; // false
timer1.isReady(); // true
timer1.start();
timer1.isRunnung; // true
timer1.isReady(); // false
_z.timer.hold = true; // this will hold all timers even they were started
timer1.isRunnung; // false
timer1.isReady(); // false
_z.timer.hold = false;
timer1.isRunnung; // true
timer1.isReady(); // false

_z.timer.startAll(); // start all timers
_z.timer.stopAll(); // stop all timers
_z.timer.removeAll(); // stop & remove all timers