Blame view
app/bower_components/jquery/src/core/access.js
1.23 KB
87c93a029
|
1 |
define( [ |
f986e111b
|
2 3 |
"../core" ], function( jQuery ) { |
87c93a029
|
4 |
"use strict"; |
f986e111b
|
5 6 |
// Multifunctional method to get and set values of a collection // The value/s can optionally be executed if it's a function |
87c93a029
|
7 |
var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { |
f986e111b
|
8 |
var i = 0, |
87c93a029
|
9 |
len = elems.length, |
f986e111b
|
10 11 12 13 14 15 |
bulk = key == null; // Sets many values if ( jQuery.type( key ) === "object" ) { chainable = true; for ( i in key ) { |
87c93a029
|
16 |
access( elems, fn, i, key[ i ], true, emptyGet, raw ); |
f986e111b
|
17 18 19 20 21 22 23 24 25 26 27 |
} // Sets one value } else if ( value !== undefined ) { chainable = true; if ( !jQuery.isFunction( value ) ) { raw = true; } if ( bulk ) { |
87c93a029
|
28 |
|
f986e111b
|
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
// Bulk operations run against the entire set if ( raw ) { fn.call( elems, value ); fn = null; // ...except when executing function values } else { bulk = fn; fn = function( elem, key, value ) { return bulk.call( jQuery( elem ), value ); }; } } if ( fn ) { |
87c93a029
|
44 45 46 47 48 49 |
for ( ; i < len; i++ ) { fn( elems[ i ], key, raw ? value : value.call( elems[ i ], i, fn( elems[ i ], key ) ) ); |
f986e111b
|
50 51 52 |
} } } |
87c93a029
|
53 54 55 56 57 58 59 60 |
if ( chainable ) { return elems; } // Gets if ( bulk ) { return fn.call( elems ); } |
f986e111b
|
61 |
|
87c93a029
|
62 |
return len ? fn( elems[ 0 ], key ) : emptyGet; |
f986e111b
|
63 64 65 |
}; return access; |
87c93a029
|
66 |
} ); |