MCPcopy
hub / github.com/layui/layui / access

Function access

src/modules/jquery.js:3951–4007  ·  view source on GitHub ↗
(elems, fn, key, value, chainable, emptyGet, raw)

Source from the content-addressed store, hash-verified

3949 // Multifunctional method to get and set values of a collection
3950 // The value/s can optionally be executed if it's a function
3951 var access = function (elems, fn, key, value, chainable, emptyGet, raw) {
3952 var i = 0,
3953 len = elems.length,
3954 bulk = key == null;
3955
3956 // Sets many values
3957 if (toType(key) === 'object') {
3958 chainable = true;
3959 for (i in key) {
3960 access(elems, fn, i, key[i], true, emptyGet, raw);
3961 }
3962
3963 // Sets one value
3964 } else if (value !== undefined) {
3965 chainable = true;
3966
3967 if (!isFunction(value)) {
3968 raw = true;
3969 }
3970
3971 if (bulk) {
3972 // Bulk operations run against the entire set
3973 if (raw) {
3974 fn.call(elems, value);
3975 fn = null;
3976
3977 // ...except when executing function values
3978 } else {
3979 bulk = fn;
3980 fn = function (elem, _key, value) {
3981 return bulk.call(jQuery(elem), value);
3982 };
3983 }
3984 }
3985
3986 if (fn) {
3987 for (; i < len; i++) {
3988 fn(
3989 elems[i],
3990 key,
3991 raw ? value : value.call(elems[i], i, fn(elems[i], key))
3992 );
3993 }
3994 }
3995 }
3996
3997 if (chainable) {
3998 return elems;
3999 }
4000
4001 // Gets
4002 if (bulk) {
4003 return fn.call(elems);
4004 }
4005
4006 return len ? fn(elems[0], key) : emptyGet;
4007 };
4008

Callers 1

jquery.jsFile · 0.85

Calls 4

toTypeFunction · 0.85
isFunctionFunction · 0.85
jQueryFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected