diff options
author | John Resig <jeresig@gmail.com> | 2009-09-25 17:55:20 +0000 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2009-09-25 17:55:20 +0000 |
commit | 67d445a703491c90a7d3c46be34bcdceb4d1c896 (patch) | |
tree | 4d2dd78e8190202205091c46463aaa980c77f089 /src/data.js | |
parent | 67089eedf6f84acd9c16ea2a6dadadf7b13a7c84 (diff) | |
download | jquery-67d445a703491c90a7d3c46be34bcdceb4d1c896.tar.gz jquery-67d445a703491c90a7d3c46be34bcdceb4d1c896.zip |
A follow-up to [6578] (which stopped adding expandos to elements that didn't have data). That broke jQuery.unique() (so we're now using the unique from Sizzle). Using Sizzle's unique (which also sorts in document order) changed how add, andSelf, parents, nextAll, prevAll, and siblings work. after and before were changed to not use .add() (in order to guarantee their position in the jQuery set). Also, jQuery.data(elem) was updated to return that element's data object (instead of its ID).
$("<div/>").after("<span/>")
=> [ div, span ]
(calling after on a disconnected DOM node adds the nodes to the end of the jQuery set)
$("<div/>").before("<span/>")
=> [ span, div ]
(calling before on a disconnected DOM node adds the nodes to the beginning of the jQuery set)
$("div").add("span")
=> [ div, span, span, div, span ]
(results now come out in document order)
$("div").find("code").andSelf();
=> [ div, code, code ]
(results now come out in document order)
Same goes for .parents(), .nextAll(), .prevAll(), and .siblings().
Exception: .parents() will still return the results in reverse document order.
jQuery.data(elem)
=> { object of data }
(no longer returns the unique ID assigned to the node)
Diffstat (limited to 'src/data.js')
-rw-r--r-- | src/data.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/data.js b/src/data.js index 085db0bb3..500f7ea43 100644 --- a/src/data.js +++ b/src/data.js @@ -14,8 +14,8 @@ jQuery.extend({ var id = elem[ expando ], cache = jQuery.cache, thisCache;
// Handle the case where there's no name immediately
- if ( !name ) {
- return id;
+ if ( !name && !id ) {
+ return null;
}
// Compute a unique ID for the element
@@ -39,7 +39,7 @@ jQuery.extend({ thisCache[ name ] = data;
}
- return name === true ? thisCache : thisCache[ name ];
+ return name ? thisCache[ name ] : thisCache;
},
removeData: function( elem, name ) {
@@ -116,7 +116,9 @@ jQuery.extend({ jQuery.fn.extend({
data: function( key, value ){
- if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true);
+ if ( typeof key === "undefined" && this.length ) {
+ return jQuery.data( this[0] );
+ }
var parts = key.split(".");
parts[1] = parts[1] ? "." + parts[1] : "";
@@ -165,4 +167,4 @@ jQuery.fn.extend({ clearQueue: function(type){
return this.queue( type || "fx", [] );
}
-});
\ No newline at end of file +});
|