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