~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/arraylist/arraylist.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('arraylist', function(Y) {
8
 
 
9
 
/**
10
 
 * Collection utilities beyond what is provided in the YUI core
11
 
 * @module collection
12
 
 * @submodule arraylist
13
 
 */
14
 
 
15
 
var YArray      = Y.Array,
16
 
    YArray_each = YArray.each,
17
 
    ArrayListProto;
18
 
 
19
 
/**
20
 
 * Generic ArrayList class for managing lists of items and iterating operations
21
 
 * over them.  The targeted use for this class is for augmentation onto a
22
 
 * class that is responsible for managing multiple instances of another class
23
 
 * (e.g. NodeList for Nodes).  The recommended use is to augment your class with
24
 
 * ArrayList, then use ArrayList.addMethod to mirror the API of the constituent
25
 
 * items on the list's API.
26
 
 *
27
 
 * The default implementation creates immutable lists, but mutability can be
28
 
 * provided via the arraylist-add submodule or by implementing mutation methods
29
 
 * directly on the augmented class's prototype.
30
 
 *
31
 
 * @class ArrayList
32
 
 * @constructor
33
 
 * @param items { Array } array of items this list will be responsible for
34
 
 */
35
 
function ArrayList( items ) {
36
 
    if ( items !== undefined ) {
37
 
        this._items = Y.Lang.isArray( items ) ? items : YArray( items );
38
 
    } else {
39
 
        // ||= to support lazy initialization from augment
40
 
        this._items = this._items || [];
41
 
    }
42
 
}
43
 
 
44
 
ArrayListProto = {
45
 
    /**
46
 
     * Get an item by index from the list.  Override this method if managing a
47
 
     * list of objects that have a different public representation (e.g. Node
48
 
     * instances vs DOM nodes).  The iteration methods that accept a user
49
 
     * function will use this method for access list items for operation.
50
 
     *
51
 
     * @method item
52
 
     * @param i { Integer } index to fetch
53
 
     * @return { mixed } the item at the requested index
54
 
     */
55
 
    item: function ( i ) {
56
 
        return this._items[i];
57
 
    },
58
 
 
59
 
    /**
60
 
     * <p>Execute a function on each item of the list, optionally providing a
61
 
     * custom execution context.  Default context is the item.</p>
62
 
     *
63
 
     * <p>The callback signature is <code>callback( item, index )</code>.</p>
64
 
     *
65
 
     * @method each
66
 
     * @param fn { Function } the function to execute
67
 
     * @param context { mixed } optional override 'this' in the function
68
 
     * @return { ArrayList } this instance
69
 
     * @chainable
70
 
     */
71
 
    each: function ( fn, context ) {
72
 
        YArray_each( this._items, function ( item, i ) {
73
 
            item = this.item( i );
74
 
 
75
 
            fn.call( context || item, item, i, this );
76
 
        }, this);
77
 
 
78
 
        return this;
79
 
    },
80
 
 
81
 
    /**
82
 
     * <p>Execute a function on each item of the list, optionally providing a
83
 
     * custom execution context.  Default context is the item.</p>
84
 
     *
85
 
     * <p>The callback signature is <code>callback( item, index )</code>.</p>
86
 
     *
87
 
     * <p>Unlike <code>each</code>, if the callback returns true, the
88
 
     * iteratation will stop.</p>
89
 
     *
90
 
     * @method some
91
 
     * @param fn { Function } the function to execute
92
 
     * @param context { mixed } optional override 'this' in the function
93
 
     * @return { Boolean } True if the function returned true on an item
94
 
     */
95
 
    some: function ( fn, context ) {
96
 
        return YArray.some( this._items, function ( item, i ) {
97
 
            item = this.item( i );
98
 
 
99
 
            return fn.call( context || item, item, i, this );
100
 
        }, this);
101
 
    },
102
 
 
103
 
    /**
104
 
     * Finds the first index of the needle in the managed array of items.
105
 
     *
106
 
     * @method indexOf
107
 
     * @param needle { mixed } The item to search for
108
 
     * @return { Integer } Array index if found.  Otherwise -1
109
 
     */
110
 
    indexOf: function ( needle ) {
111
 
        return YArray.indexOf( this._items, needle );
112
 
    },
113
 
 
114
 
    /**
115
 
     * How many items are in this list?
116
 
     *
117
 
     * @method size
118
 
     * @return { Integer } Number of items in the list
119
 
     */
120
 
    size: function () {
121
 
        return this._items.length;
122
 
    },
123
 
 
124
 
    /**
125
 
     * Is this instance managing any items?
126
 
     *
127
 
     * @method isEmpty
128
 
     * @return { Boolean } true if 1 or more items are being managed
129
 
     */
130
 
    isEmpty: function () {
131
 
        return !this.size();
132
 
    },
133
 
 
134
 
    /**
135
 
     * Provides an array-like representation for JSON.stringify.
136
 
     *
137
 
     * @method toJSON
138
 
     * @return { Array } an array representation of the ArrayList
139
 
     */
140
 
    toJSON: function () {
141
 
        return this._items;
142
 
    }
143
 
};
144
 
// Default implementation does not distinguish between public and private
145
 
// item getter
146
 
/**
147
 
 * Protected method for optimizations that may be appropriate for API
148
 
 * mirroring. Similar in functionality to <code>item</code>, but is used by
149
 
 * methods added with <code>ArrayList.addMethod()</code>.
150
 
 *
151
 
 * @method _item
152
 
 * @protected
153
 
 * @param i { Integer } Index of item to fetch
154
 
 * @return { mixed } The item appropriate for pass through API methods
155
 
 */
156
 
ArrayListProto._item = ArrayListProto.item;
157
 
 
158
 
ArrayList.prototype  = ArrayListProto;
159
 
 
160
 
Y.mix( ArrayList, {
161
 
 
162
 
    /**
163
 
     * <p>Adds a pass through method to dest (typically the prototype of a list
164
 
     * class) that calls the named method on each item in the list with
165
 
     * whatever parameters are passed in.  Allows for API indirection via list
166
 
     * instances.</p>
167
 
     *
168
 
     * <p>Accepts a single string name or an array of string names.</p>
169
 
     *
170
 
     * <pre><code>list.each( function ( item ) {
171
 
     *     item.methodName( 1, 2, 3 );
172
 
     * } );
173
 
     * // becomes
174
 
     * list.methodName( 1, 2, 3 );</code></pre>
175
 
     *
176
 
     * <p>Additionally, the pass through methods use the item retrieved by the
177
 
     * <code>_item</code> method in case there is any special behavior that is
178
 
     * appropriate for API mirroring.</p>
179
 
     *
180
 
     * <p>If the iterated method returns a value, the return value from the
181
 
     * added method will be an array of values with each value being at the
182
 
     * corresponding index for that item.  If the iterated method does not
183
 
     * return a value, the added method will be chainable.
184
 
     *
185
 
     * @method addMethod
186
 
     * @static
187
 
     * @param dest {Object} Object or prototype to receive the iterator method
188
 
     * @param name {String|String[]} Name of method of methods to create
189
 
     */
190
 
    addMethod: function ( dest, names ) {
191
 
 
192
 
        names = YArray( names );
193
 
 
194
 
        YArray_each( names, function ( name ) {
195
 
            dest[ name ] = function () {
196
 
                var args = YArray( arguments, 0, true ),
197
 
                    ret  = [];
198
 
 
199
 
                YArray_each( this._items, function ( item, i ) {
200
 
                    item = this._item( i );
201
 
 
202
 
                    var result = item[ name ].apply( item, args );
203
 
 
204
 
                    if ( result !== undefined && result !== item ) {
205
 
                        ret[i] = result;
206
 
                    }
207
 
                }, this);
208
 
 
209
 
                return ret.length ? ret : this;
210
 
            };
211
 
        } );
212
 
    }
213
 
} );
214
 
 
215
 
Y.ArrayList = ArrayList;
216
 
 
217
 
 
218
 
}, '3.4.1' ,{requires:['yui-base']});