|
0
|
1 |
/* |
|
|
2 |
Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
|
3 |
Code licensed under the BSD License: |
|
|
4 |
http://developer.yahoo.net/yui/license.txt |
|
|
5 |
version: 3.0.0b1 |
|
|
6 |
build: 1163 |
|
|
7 |
*/ |
|
|
8 |
YUI.add('queue-promote', function(Y) { |
|
|
9 |
|
|
|
10 |
/** |
|
|
11 |
* Adds methods promote and remove to Queue instances |
|
|
12 |
* |
|
|
13 |
* @module queue |
|
|
14 |
* @submodule queue-promote |
|
|
15 |
* @for Queue |
|
|
16 |
*/ |
|
|
17 |
|
|
|
18 |
Y.mix(Y.Queue.prototype, { |
|
|
19 |
/** |
|
|
20 |
* Returns the current index in the queue of the specified callback |
|
|
21 |
* |
|
|
22 |
* @method indexOf |
|
|
23 |
* @param callback {Function} the callback function |
|
|
24 |
* @return {Number} the index of the callback or -1 if not found |
|
|
25 |
*/ |
|
|
26 |
indexOf : function (callback) { |
|
|
27 |
return Y.Array.indexOf(this._q, callback); |
|
|
28 |
}, |
|
|
29 |
|
|
|
30 |
/** |
|
|
31 |
* Moves the referenced callback function to the top of the queue |
|
|
32 |
* |
|
|
33 |
* @method promote |
|
|
34 |
* @param callback {Function} reference to a function in the queue |
|
|
35 |
*/ |
|
|
36 |
promote : function (callback) { |
|
|
37 |
var index = this.indexOf(callback); |
|
|
38 |
|
|
|
39 |
if (index > -1) { |
|
|
40 |
this._q.unshift(this._q.splice(index,1)); |
|
|
41 |
} |
|
|
42 |
}, |
|
|
43 |
|
|
|
44 |
/** |
|
|
45 |
* Removes the referenced callback function from the queue |
|
|
46 |
* |
|
|
47 |
* @method remove |
|
|
48 |
* @param callback {Function} reference to a function in the queue |
|
|
49 |
*/ |
|
|
50 |
remove : function (callback) { |
|
|
51 |
var index = this.indexOf(callback); |
|
|
52 |
|
|
|
53 |
if (index > -1) { |
|
|
54 |
this._q.splice(index,1); |
|
|
55 |
} |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
}); |
|
|
59 |
|
|
|
60 |
|
|
|
61 |
}, '3.0.0b1' ,{requires:['queue-base']}); |