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