|
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.0 |
|
6 build: 1549 |
|
7 */ |
|
8 YUI.add('queue-promote', function(Y) { |
|
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)); |
|
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.0.0' ,{requires:['yui-base']}); |