MCPcopy Create free account
hub / github.com/components/jquery / access

Function access

jquery.js:841–898  ·  view source on GitHub ↗
( elems, fn, key, value, chainable, emptyGet, raw )

Source from the content-addressed store, hash-verified

839// Multifunctional method to get and set values of a collection
840// The value/s can optionally be executed if it's a function
841function access( elems, fn, key, value, chainable, emptyGet, raw ) {
842 var i = 0,
843 len = elems.length,
844 bulk = key == null;
845
846 // Sets many values
847 if ( toType( key ) === "object" ) {
848 chainable = true;
849 for ( i in key ) {
850 access( elems, fn, i, key[ i ], true, emptyGet, raw );
851 }
852
853 // Sets one value
854 } else if ( value !== undefined ) {
855 chainable = true;
856
857 if ( typeof value !== "function" ) {
858 raw = true;
859 }
860
861 if ( bulk ) {
862
863 // Bulk operations run against the entire set
864 if ( raw ) {
865 fn.call( elems, value );
866 fn = null;
867
868 // ...except when executing function values
869 } else {
870 bulk = fn;
871 fn = function( elem, _key, value ) {
872 return bulk.call( jQuery( elem ), value );
873 };
874 }
875 }
876
877 if ( fn ) {
878 for ( ; i < len; i++ ) {
879 fn(
880 elems[ i ], key, raw ?
881 value :
882 value.call( elems[ i ], i, fn( elems[ i ], key ) )
883 );
884 }
885 }
886 }
887
888 if ( chainable ) {
889 return elems;
890 }
891
892 // Gets
893 if ( bulk ) {
894 return fn.call( elems );
895 }
896
897 return len ? fn( elems[ 0 ], key ) : emptyGet;
898}

Callers 1

jquery.jsFile · 0.70

Calls 2

toTypeFunction · 0.70
jQueryFunction · 0.70

Tested by

no test coverage detected