diff -r d334a616c023 -r e16a97fb364a src/cm/media/js/lib/yui/yui3-3.15.0/build/datasource-polling/datasource-polling-debug.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/media/js/lib/yui/yui3-3.15.0/build/datasource-polling/datasource-polling-debug.js Mon Mar 10 15:19:48 2014 +0100 @@ -0,0 +1,93 @@ +YUI.add('datasource-polling', function (Y, NAME) { + +/** + * Extends DataSource with polling functionality. + * + * @module datasource + * @submodule datasource-polling + */ + +/** + * Adds polling to the DataSource Utility. + * @class Pollable + * @extends DataSource.Local + */ +function Pollable() { + this._intervals = {}; +} + +Pollable.prototype = { + + /** + * @property _intervals + * @description Hash of polling interval IDs that have been enabled, + * stored here to be able to clear all intervals. + * @private + */ + _intervals: null, + + /** + * Sets up a polling mechanism to send requests at set intervals and + * forward responses to given callback. + * + * @method setInterval + * @param msec {Number} Length of interval in milliseconds. + * @param [request] {Object} An object literal with the following properties: + *
+ *
request
+ *
The request to send to the live data source, if any.
+ *
callback
+ *
An object literal with the following properties: + *
+ *
success
+ *
The function to call when the data is ready.
+ *
failure
+ *
The function to call upon a response failure condition.
+ *
argument
+ *
Arbitrary data payload that will be passed back to the success and failure handlers.
+ *
+ *
+ *
cfg
+ *
Configuration object, if any.
+ *
+ * @return {Number} Interval ID. + */ + setInterval: function(msec, request) { + var x = Y.later(msec, this, this.sendRequest, [ request ], true); + this._intervals[x.id] = x; + // First call happens immediately, but async + Y.later(0, this, this.sendRequest, [request]); + return x.id; + }, + + /** + * Disables polling mechanism associated with the given interval ID. + * + * @method clearInterval + * @param id {Number} Interval ID. + */ + clearInterval: function(id, key) { + // In case of being called by clearAllIntervals() + id = key || id; + if(this._intervals[id]) { + // Clear the interval + this._intervals[id].cancel(); + // Clear from tracker + delete this._intervals[id]; + } + }, + + /** + * Clears all intervals. + * + * @method clearAllIntervals + */ + clearAllIntervals: function() { + Y.each(this._intervals, this.clearInterval, this); + } +}; + +Y.augment(Y.DataSource.Local, Pollable); + + +}, '@VERSION@', {"requires": ["datasource-local"]});