PageSourceSearch

https://albo.arpa.puglia.it/html/js/aui/aui-delayed-task-deprecate…=&languageId=it_IT&b=6205&t=1612708754000

js arpa.puglia.it collected 2026-09-24 18:18:14 UTC 4,228 bytes, 191 lines download raw bytes

1YUI.add('aui-delayed-task-deprecated', function (A, NAME) {
2
3/**
4 * The DelayedTask Utility - Executes the supplied function in the context of
5 * the supplied object 'when' milliseconds later
6 *
7 * @module aui-delayed-task
8 */
9
10/**
11 * A base class for DelayedTask, providing:
12 * <ul>
13 *    <li>Executes the supplied function in the context of the supplied object 'when' milliseconds later</li>
14 * </ul>
15 *
16 * Quick Example:<br/>
17 *
18 * <pre><code>var delayed = new A.DelayedTask({
19 *	 function() {
20 *     // This callback will be executed when the <code>DelayedTask</code> be invoked
21 *	 },
22 *	 scope
23 *  });
24 *
25 * 	// executes after 1000ms the callback
26 *  delayed.delay(1000);
27 * </code></pre>
28 *
29 * Check the list of <a href="DelayedTask.html#configattributes">Configuration Attributes</a> available for
30 * DelayedTask.
31 *
32 * @param config {Object} Object literal specifying widget configuration properties.
33 *
34 * @class DelayedTask
35 * @param {function} fn Callback
36 * @param {Object} scope Context object. Optional.
37 * @param args 0..n additional arguments that should be provided to the listener.
38 * @constructor
39 */
40var DelayedTask = function(fn, scope, args) {
41	var instance = this;
42
43	/**
44	 * Stores the passed <code>args</code> attribute.
45	 *
46	 * @property _args
47	 * @type Object
48	 * @protected
49	 */
50	instance._args = args;
51
52	/**
53	 * Stores the passed <code>delay</code> attribute.
54	 *
55	 * @property _delay
56	 * @default 0
57	 * @type Number
58	 * @protected
59	 */
60	instance._delay = 0;
61
62	/**
63	 * Stores the passed <code>fn</code> attribute.
64	 *
65	 * @property _fn
66	 * @type function
67	 * @protected
68	 */
69	instance._fn = fn;
70
71	/**
72	 * Stores the timer <code>id</code> given from the <code>setInterval</code>.
73	 *
74	 * @property _id
75	 * @default null
76	 * @type Number
77	 * @protected
78	 */
79	instance._id = null;
80
81	/**
82	 * Stores the passed <code>scope</code> attribute.
83	 *
84	 * @property _scope
85	 * @default instance
86	 * @type Object
87	 * @protected
88	 */
89	instance._scope = scope || instance;
90
91	/**
92	 * Stores the current timestamp given from
93     * <a href="DelayedTask.html#method__getTime">_getTime</a>.
94	 *
95	 * @property _time
96	 * @default 0
97	 * @type Number
98	 * @protected
99	 */
100	instance._time = 0;
101
102	instance._base = function() {
103		var now = instance._getTime();
104
105		if (now - instance._time >= instance._delay) {
106			clearInterval(instance._id);
107
108			instance._id = null;
109
110			instance._fn.apply(instance._scope, instance._args || []);
111		}
112	};
113};
114
115DelayedTask.prototype = {
116	/**
117	 * <p>This function is responsible to execute the user callback, passed in
118     * the <code>constructor</code> after <code>delay</code> milliseconds.</p>
119	 *
120	 * Example:
121	 *
122	 * <pre><code>// executes after 1000ms the callback
123	 * delayed.delay(1000);</code></pre>
124	 *
125	 * @method delay
126	 * @param {Number} delay Delay in milliseconds.
127	 * @param {function} newFn Callback.
128	 * @param {Object} newScope Context object. Optional.
129	 * @param newArgs 0..n additional arguments that should be provided to the listener.
130	 */
131	delay: function(delay, newFn, newScope, newArgs) {
132		var instance = this;
133
134		if (instance._id && instance._delay != delay) {
135			instance.cancel();
136		}
137
138		instance._delay = delay || instance._delay;
139		instance._time = instance._getTime();
140
141		instance._fn = newFn || instance._fn;
142		instance._scope = newScope || instance._scope;
143		instance._args = newArgs || instance._args;
144
145		if (!A.Lang.isArray(instance._args)) {
146			instance._args = [instance._args];
147		}
148
149		if (!instance._id) {
150			if (instance._delay > 0) {
151				instance._id = setInterval(instance._base, instance._delay);
152			}
153			else {
154				instance._base();
155			}
156		}
157	},
158
159	/**
160	 * Cancel the delayed task in case it's running (i.e., clearInterval from
161     * the current running <a href="DelayedTask.html#property__id">_id</a>).
162	 *
163	 * @method cancel
164	 */
165	cancel: function() {
166		var instance = this;
167
168		if (instance._id) {
169			clearInterval(instance._id);
170
171			instance._id = null;
172		}
173	},
174
175	/**
176	 * Get the current timestamp (i.e., now).
177	 *
178	 * @method _getTime
179	 * @protected
180	 * @return {Number} Current timestamp
181	 */
182	_getTime: function() {
183		var instance = this;
184
185		return (+new Date());
186	}
187};
188
189A.DelayedTask = DelayedTask;
190
191}, '2.0.0', {"requires": ["yui-base"]});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.