1,12 → 1,11 |
/** |
* <title>PointedEars' DOM Library: Timeout</title> |
* @requires types.js |
* @recommends xpath.js |
* @requires object.js |
* |
* @section Copyright & Disclaimer |
* |
* @author |
* (C) 2002-2012 Thomas Lahn <js@PointedEars.de> |
* (C) 2002-2013 Thomas Lahn <js@PointedEars.de> |
* |
* @partof PointedEars' JavaScript Extensions (JSX) |
* |
40,49 → 39,50 |
jsx.dom = {}; |
} |
|
if (typeof jsx.dom.timeout == "undefined") |
{ |
/** |
* @namespace |
*/ |
jsx.dom.timeout = {}; |
} |
jsx.dom.timeout = (function () { |
/* Imports */ |
var _isMethod = jsx.object.isMethod; |
|
/* Private variables */ |
var _Timeout = ( |
/** |
* Creates a container for code that can be run later |
* Creates a container for code that can be run later. |
* |
* @param f : Function |
* @constructor |
* @param {Function} f |
* Code to be run later. The default is <code>null</code>. |
* @param delay : int |
* @param {int} delay |
* Milliseconds after which the code will be run by default. |
* @constructor |
*/ |
jsx.dom.timeout.Timeout = function(f, delay) { |
function jsx_dom_timeout_Timeout (f, delay) { |
this.running = false; |
this.code = f || null; |
this.delay = parseInt(delay, 10) || 50; |
}; |
|
} |
).extend(null, { |
/** |
* Runs the associated code after <var>delay</var> milliseconds; |
* cancels any planned but not yet performed executions. |
* |
* @param f : Function |
* @memberOf jsx.dom.timeout.Timeout.prototype |
* @param {Function} f |
* Code to be run later. The default is the value of the |
* <code>code</code> property as initialized upon construction. |
* This argument's value will modify that property if the type |
* is correct. |
* @param delay : int |
* @param {int} delay |
* Milliseconds after which the code will be run by default. |
* The default is the value of the <code>delay</code> property |
* as initialized upon construction. |
* This argument's value will modify that property if the type |
* is correct. |
* @see #Timeout() |
* @return jsx.dom.timeout.Timeout |
* @return {jsx.dom.timeout.Timeout} |
* This object |
*/ |
jsx.dom.timeout.Timeout.prototype.run = function(f, delay) { |
run: function(f, delay) { |
this.unset(); |
|
if (typeof f == "function") |
95,7 → 95,7 |
this.delay = parseInt(delay, 10); |
} |
|
if (jsx.object.isMethod(jsx.global, "window", "setTimeout")) |
if (_isMethod(jsx.global, "window", "setTimeout")) |
{ |
this.running = true; |
var me = this; |
106,15 → 106,15 |
} |
|
return this; |
}; |
}, |
|
/** |
* Cancels the execution of the associated code |
*/ |
jsx.dom.timeout.Timeout.prototype.unset = function() { |
unset: function() { |
if (this.running) |
{ |
if (jsx.object.isMethod(jsx.global, "window", "clearTimeout")) |
if (_isMethod(jsx.global, "window", "clearTimeout")) |
{ |
window.clearTimeout(this.data); |
} |
121,41 → 121,54 |
|
this.running = false; |
} |
}; |
} |
}); |
|
return { |
/** |
* @memberOf jsx.dom.timeout |
*/ |
Timeout: _Timeout, |
|
TimeoutList: ( |
/** |
* Provides a container for {@link #Timeout}s. |
* |
* @param timeouts : Array[Timeout] |
* @constructor |
* @param {Array} timeouts |
* The list of {@link jsx.dom.timeout#Timeout Timeouts} to be considered |
* @constructor |
*/ |
jsx.dom.timeout.TimeoutList = function(timeouts) { |
function jsx_dom_timeout_TimeoutList (timeouts) { |
this.timeouts = timeouts || []; |
}; |
|
} |
).extend(null, { |
/** |
* Unsets all {@link #Timeout}s in this container |
* |
* @memberOf jsx.dom.timeout.TimeoutList.prototype |
*/ |
jsx.dom.timeout.TimeoutList.prototype.unsetAll = function() { |
unsetAll: function() { |
for (var i = 0, timeouts = this.timeouts, len = timeouts.length; i < len; ++i) |
{ |
timeouts[i].unset(); |
} |
}; |
} |
}), |
|
/** |
* Schedules code for later execution. |
* |
* @param code : String|Function |
* @param {String|Function} code |
* Code to be executed or function to be called. |
* @param iTimeout : number |
* @param {number} iTimeout |
* Number of milliseconds after which <var>code</var> should be run. |
* The time of execution is implementation-dependent, but the timer |
* will usually not start before control has returned to the caller. |
* @return jsx.dom.timeout.Timeout |
* @return {jsx.dom.timeout.Timeout} |
* The created <code>Timeout</code> |
*/ |
jsx.dom.timeout.runAsync = function (code, iTimeout) { |
return (new jsx.dom.timeout.Timeout(code, iTimeout)).run(); |
}; |
runAsync: function (code, iTimeout) { |
return (new _Timeout(code, iTimeout)).run(); |
} |
}; |
}()); |