Merge branch 'MDL-32509' of git://github.com/danpoltawski/moodle
[moodle.git] / lib / yui / 3.5.0 / build / arraylist-add / arraylist-add-debug.js
blobca73d145da49b6965b21dbf1144fa36b525b8df4
1 /*
2 YUI 3.5.0 (build 5089)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('arraylist-add', function(Y) {
9 /**
10  * Collection utilities beyond what is provided in the YUI core
11  * @module collection
12  * @submodule arraylist-add
13  * @deprecated Use ModelList or a custom ArrayList subclass
14  */
17  * Adds methods add and remove to Y.ArrayList
18  */
19 Y.mix(Y.ArrayList.prototype, {
21     /**
22      * Add a single item to the ArrayList.  Does not prevent duplicates.
23      *
24      * @method add
25      * @param { mixed } item Item presumably of the same type as others in the
26      *                       ArrayList.
27      * @param {Number} index (Optional.)  Number representing the position at
28      * which the item should be inserted.
29      * @return {ArrayList} the instance.
30      * @for ArrayList
31      * @deprecated Use ModelList or a custom ArrayList subclass
32      * @chainable
33      */
34     add: function(item, index) {
35         var items = this._items;
37         if (Y.Lang.isNumber(index)) {
38             items.splice(index, 0, item);
39         }
40         else {
41             items.push(item);
42         }
44         return this;
45     },
47     /**
48      * Removes first or all occurrences of an item to the ArrayList.  If a
49      * comparator is not provided, uses itemsAreEqual method to determine
50      * matches.
51      *
52      * @method remove
53      * @param { mixed } needle Item to find and remove from the list.
54      * @param { Boolean } all If true, remove all occurrences.
55      * @param { Function } comparator optional a/b function to test equivalence.
56      * @return {ArrayList} the instance.
57      * @for ArrayList
58      * @deprecated Use ModelList or a custom ArrayList subclass
59      * @chainable
60      */
61     remove: function(needle, all, comparator) {
62         comparator = comparator || this.itemsAreEqual;
64         for (var i = this._items.length - 1; i >= 0; --i) {
65             if (comparator.call(this, needle, this.item(i))) {
66                 this._items.splice(i, 1);
67                 if (!all) {
68                     break;
69                 }
70             }
71         }
73         return this;
74     },
76     /**
77      * Default comparator for items stored in this list.  Used by remove().
78      *
79      * @method itemsAreEqual
80      * @param { mixed } a item to test equivalence with.
81      * @param { mixed } b other item to test equivalance.
82      * @return { Boolean } true if items are deemed equivalent.
83      * @for ArrayList
84      * @deprecated Use ModelList or a custom ArrayList subclass
85      */
86     itemsAreEqual: function(a, b) {
87         return a === b;
88     }
90 });
93 }, '3.5.0' ,{requires:['arraylist']});