Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('arraylist-add', function (Y, NAME) {
2
 
3
/**
4
 * Collection utilities beyond what is provided in the YUI core
5
 * @module collection
6
 * @submodule arraylist-add
7
 * @deprecated Use ModelList or a custom ArrayList subclass
8
 */
9
 
10
/*
11
 * Adds methods add and remove to Y.ArrayList
12
 */
13
Y.mix(Y.ArrayList.prototype, {
14
 
15
    /**
16
     * Add a single item to the ArrayList.  Does not prevent duplicates.
17
     *
18
     * @method add
19
     * @param { mixed } item Item presumably of the same type as others in the
20
     *                       ArrayList.
21
     * @param {Number} index (Optional.)  Number representing the position at
22
     * which the item should be inserted.
23
     * @return {ArrayList} the instance.
24
     * @for ArrayList
25
     * @deprecated Use ModelList or a custom ArrayList subclass
26
     * @chainable
27
     */
28
    add: function(item, index) {
29
        var items = this._items;
30
 
31
        if (Y.Lang.isNumber(index)) {
32
            items.splice(index, 0, item);
33
        }
34
        else {
35
            items.push(item);
36
        }
37
 
38
        return this;
39
    },
40
 
41
    /**
42
     * Removes first or all occurrences of an item to the ArrayList.  If a
43
     * comparator is not provided, uses itemsAreEqual method to determine
44
     * matches.
45
     *
46
     * @method remove
47
     * @param { mixed } needle Item to find and remove from the list.
48
     * @param { Boolean } all If true, remove all occurrences.
49
     * @param { Function } comparator optional a/b function to test equivalence.
50
     * @return {ArrayList} the instance.
51
     * @for ArrayList
52
     * @deprecated Use ModelList or a custom ArrayList subclass
53
     * @chainable
54
     */
55
    remove: function(needle, all, comparator) {
56
        comparator = comparator || this.itemsAreEqual;
57
 
58
        for (var i = this._items.length - 1; i >= 0; --i) {
59
            if (comparator.call(this, needle, this.item(i))) {
60
                this._items.splice(i, 1);
61
                if (!all) {
62
                    break;
63
                }
64
            }
65
        }
66
 
67
        return this;
68
    },
69
 
70
    /**
71
     * Default comparator for items stored in this list.  Used by remove().
72
     *
73
     * @method itemsAreEqual
74
     * @param { mixed } a item to test equivalence with.
75
     * @param { mixed } b other item to test equivalance.
76
     * @return { Boolean } true if items are deemed equivalent.
77
     * @for ArrayList
78
     * @deprecated Use ModelList or a custom ArrayList subclass
79
     */
80
    itemsAreEqual: function(a, b) {
81
        return a === b;
82
    }
83
 
84
});
85
 
86
 
87
}, '3.18.1', {"requires": ["arraylist"]});