Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix #5571. Setters should treat
undefined
as a no-op and be chainable.
- Loading branch information
Showing
14 changed files
with
248 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -801,31 +801,55 @@ jQuery.extend({ | ||
|
||
// Mutifunctional method to get and set values to a collection | ||
// The value/s can optionally be executed if it's a function | ||
access: function( elems, key, value, exec, fn, pass ) { | ||
var length = elems.length; | ||
access: function( elems, fn, key, value, chainable, emptyGet, pass ) { | ||
var exec, | ||
bulk = key == null, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rdworth
Contributor
|
||
i = 0, | ||
length = elems.length; | ||
|
||
// Setting many attributes | ||
if ( typeof key === "object" ) { | ||
for ( var k in key ) { | ||
jQuery.access( elems, k, key[k], exec, fn, value ); | ||
// Sets many values | ||
if ( key && typeof key === "object" ) { | ||
for ( i in key ) { | ||
jQuery.access( elems, fn, i, key[i], 1, emptyGet, value ); | ||
} | ||
return elems; | ||
} | ||
chainable = 1; | ||
|
||
// Setting one attribute | ||
if ( value !== undefined ) { | ||
// Sets one value | ||
} else if ( value !== undefined ) { | ||
// Optionally, function values get executed if exec is true | ||
exec = !pass && exec && jQuery.isFunction(value); | ||
exec = pass === undefined && jQuery.isFunction( value ); | ||
|
||
if ( bulk ) { | ||
// Bulk operations only iterate when executing function values | ||
if ( exec ) { | ||
exec = fn; | ||
fn = function( elem, key, value ) { | ||
return exec.call( jQuery( elem ), value ); | ||
}; | ||
|
||
for ( var i = 0; i < length; i++ ) { | ||
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); | ||
// Otherwise they run against the entire set | ||
} else { | ||
fn.call( elems, value ); | ||
fn = null; | ||
} | ||
} | ||
|
||
return elems; | ||
if ( fn ) { | ||
for (; i < length; i++ ) { | ||
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); | ||
} | ||
} | ||
|
||
chainable = 1; | ||
} | ||
|
||
// Getting an attribute | ||
return length ? fn( elems[0], key ) : undefined; | ||
return chainable ? | ||
elems : | ||
|
||
// Gets | ||
bulk ? | ||
fn.call( elems ) : | ||
length ? fn( elems[0], key ) : emptyGet; | ||
}, | ||
|
||
now: function() { | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Sorry to jump here and excuse me if I'm wrong, but I'm not clear why is the variable "key" created here and set to null... will not that prevent the access to the same name parameter "key"