aboutsummaryrefslogtreecommitdiffstats
path: root/lib/jquery/src/core/access.js
diff options
context:
space:
mode:
authorJesús Eduardo <heckyel@hyperbola.info>2017-08-06 20:43:24 -0500
committerJesús Eduardo <heckyel@hyperbola.info>2017-08-06 20:43:24 -0500
commitf7045b862a5b7c3de8ee2ea3da67616b38a667cc (patch)
tree504f420546df4934495bbd6f3d9761650b3783bd /lib/jquery/src/core/access.js
downloadytlibre-f7045b862a5b7c3de8ee2ea3da67616b38a667cc.tar.lz
ytlibre-f7045b862a5b7c3de8ee2ea3da67616b38a667cc.tar.xz
ytlibre-f7045b862a5b7c3de8ee2ea3da67616b38a667cc.zip
first commit
Diffstat (limited to 'lib/jquery/src/core/access.js')
-rw-r--r--lib/jquery/src/core/access.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/jquery/src/core/access.js b/lib/jquery/src/core/access.js
new file mode 100644
index 0000000..86cdbc7
--- /dev/null
+++ b/lib/jquery/src/core/access.js
@@ -0,0 +1,70 @@
+define( [
+ "../core"
+], function( jQuery ) {
+
+"use strict";
+
+// Multifunctional method to get and set values of a collection
+// The value/s can optionally be executed if it's a function
+var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
+ var i = 0,
+ len = elems.length,
+ bulk = key == null;
+
+ // Sets many values
+ if ( jQuery.type( key ) === "object" ) {
+ chainable = true;
+ for ( i in key ) {
+ 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 < len; i++ ) {
+ fn(
+ elems[ i ], key, raw ?
+ value :
+ value.call( elems[ i ], i, fn( elems[ i ], key ) )
+ );
+ }
+ }
+ }
+
+ if ( chainable ) {
+ return elems;
+ }
+
+ // Gets
+ if ( bulk ) {
+ return fn.call( elems );
+ }
+
+ return len ? fn( elems[ 0 ], key ) : emptyGet;
+};
+
+return access;
+
+} );