aboutsummaryrefslogtreecommitdiffstats
path: root/src/core
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 11:34:23 -0400
commit3b53b75160606610cc8f87404f89fc9e10441c4b (patch)
treeb20600c885ee70e7b9cc7c880fc7a2cf141b56a8 /src/core
parent2fe09ceaf9c261d8e7fbdf37a13b21bfd85da962 (diff)
downloadjquery-3b53b75160606610cc8f87404f89fc9e10441c4b.tar.gz
jquery-3b53b75160606610cc8f87404f89fc9e10441c4b.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.
Diffstat (limited to 'src/core')
-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;
+});