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