aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/access.js
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2013-09-09 11:26:21 -0400
committerTimmy Willison <timmywillisn@gmail.com>2013-09-09 12:04:03 -0400
commit2063d6c1896b0c46c39fa0fdecef817f2e6f57c3 (patch)
tree1b642c7a1f956ddfb665487c13b8b04d5a4157ee /src/core/access.js
parentfb599f6315512f64e50d02661990cf34bb40c7db (diff)
downloadjquery-2063d6c1896b0c46c39fa0fdecef817f2e6f57c3.tar.gz
jquery-2063d6c1896b0c46c39fa0fdecef817f2e6f57c3.zip
Break jQuery.access out into its own module to separate it from core; Adjust CommonJS+AMD build support to include non-var dependencies. Convert modules with more than a few dependencies to use CJS+AMD syntax.
Conflicts: src/core.js src/css.js src/data.js src/effects.js src/event.js src/manipulation.js src/traversing.js
Diffstat (limited to 'src/core/access.js')
-rw-r--r--src/core/access.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/core/access.js b/src/core/access.js
new file mode 100644
index 000000000..7ad2fd336
--- /dev/null
+++ b/src/core/access.js
@@ -0,0 +1,58 @@
+define([
+ "../core"
+], function( jQuery ) {
+ // Multifunctional method to get and set values of a collection
+ // The value/s can optionally be executed if it's a function
+ var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
+ var i = 0,
+ length = elems.length,
+ bulk = key == null;
+
+ // Sets many values
+ if ( jQuery.type( key ) === "object" ) {
+ chainable = true;
+ for ( i in key ) {
+ jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
+ }
+
+ // Sets one value
+ } else if ( value !== undefined ) {
+ chainable = true;
+
+ if ( !jQuery.isFunction( value ) ) {
+ raw = true;
+ }
+
+ if ( bulk ) {
+ // 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 ) {
+ for ( ; i < length; i++ ) {
+ fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
+ }
+ }
+ }
+
+ return chainable ?
+ elems :
+
+ // Gets
+ bulk ?
+ fn.call( elems ) :
+ length ? fn( elems[0], key ) : emptyGet;
+ };
+
+ return access;
+});