git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactor jQuery.data a bit to reduce property lookups
[jquery.git]
/
src
/
data.js
diff --git
a/src/data.js
b/src/data.js
index
e429c0d
..
9cc76c6
100644
(file)
--- a/
src/data.js
+++ b/
src/data.js
@@
-8,25
+8,24
@@
jQuery.extend({
windowData :
\r
elem;
\r
\r
windowData :
\r
elem;
\r
\r
- var id = elem[ expando ];
\r
+ var id = elem[ expando ], cache = jQuery.cache;
\r
\r
// Compute a unique ID for the element
\r
\r
// Compute a unique ID for the element
\r
- if ( !id )
\r
- id = elem[ expando ] = ++uuid;
\r
+ if(!id) id = elem[ expando ] = ++uuid;
\r
\r
// Only generate the data cache if we're
\r
// trying to access or manipulate it
\r
\r
// Only generate the data cache if we're
\r
// trying to access or manipulate it
\r
- if ( name && !jQuery.cache[ id ] )
\r
- jQuery.cache[ id ] = {};
\r
+ if ( name && !cache[ id ] )
\r
+ cache[ id ] = {};
\r
+
\r
+ var thisCache = cache[ id ];
\r
\r
// Prevent overriding the named cache with undefined values
\r
\r
// Prevent overriding the named cache with undefined values
\r
- if ( data !== undefined )
\r
- jQuery.cache[ id ][ name ] = data;
\r
+ if ( data !== undefined ) thisCache[ name ] = data;
\r
\r
\r
- // Return the named cache data, or the ID for the element
\r
- return name ?
\r
- jQuery.cache[ id ][ name ] :
\r
- id;
\r
+ if(name === true) return thisCache
\r
+ else if(name) return thisCache[name]
\r
+ else return id
\r
},
\r
\r
removeData: function( elem, name ) {
\r
},
\r
\r
removeData: function( elem, name ) {
\r
@@
-34,21
+33,16
@@
jQuery.extend({
windowData :
\r
elem;
\r
\r
windowData :
\r
elem;
\r
\r
- var id = elem[ expando ];
\r
+ var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ];
\r
\r
// If we want to remove a specific section of the element's data
\r
if ( name ) {
\r
\r
// If we want to remove a specific section of the element's data
\r
if ( name ) {
\r
- if ( jQuery.cache[ id ] ) {
\r
+ if ( thisCache ) {
\r
// Remove the section of cache data
\r
// Remove the section of cache data
\r
- delete jQuery.cache[ id ][ name ];
\r
+ delete thisCache[ name ];
\r
\r
// If we've removed all the data, remove the element's cache
\r
\r
// If we've removed all the data, remove the element's cache
\r
- name = "";
\r
-
\r
- for ( name in jQuery.cache[ id ] )
\r
- break;
\r
-
\r
- if ( !name )
\r
+ if( jQuery.isEmptyObject(thisCache) )
\r
jQuery.removeData( elem );
\r
}
\r
\r
jQuery.removeData( elem );
\r
}
\r
\r
@@
-65,7
+59,7
@@
jQuery.extend({
}
\r
\r
// Completely remove the data cache
\r
}
\r
\r
// Completely remove the data cache
\r
- delete jQuery.cache[ id ];
\r
+ delete cache[ id ];
\r
}
\r
},
\r
queue: function( elem, type, data ) {
\r
}
\r
},
\r
queue: function( elem, type, data ) {
\r
@@
-98,6
+92,8
@@
jQuery.extend({
\r
jQuery.fn.extend({
\r
data: function( key, value ){
\r
\r
jQuery.fn.extend({
\r
data: function( key, value ){
\r
+ if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true);
\r
+
\r
var parts = key.split(".");
\r
parts[1] = parts[1] ? "." + parts[1] : "";
\r
\r
var parts = key.split(".");
\r
parts[1] = parts[1] ? "." + parts[1] : "";
\r
\r
@@
-130,16
+126,19
@@
jQuery.fn.extend({
if ( data === undefined )
\r
return jQuery.queue( this[0], type );
\r
\r
if ( data === undefined )
\r
return jQuery.queue( this[0], type );
\r
\r
- return this.each(function(){
\r
+ return this.each(function(i, elem){
\r
var queue = jQuery.queue( this, type, data );
\r
\r
var queue = jQuery.queue( this, type, data );
\r
\r
- if( type == "fx" && queue.length == 1 )
\r
- queue[0].call(this);
\r
+ if( type == "fx" && queue.length == 1 )
\r
+ queue[0].call(this, function() { jQuery(elem).dequeue(type); });
\r
});
\r
},
\r
dequeue: function(type){
\r
return this.each(function(){
\r
jQuery.dequeue( this, type );
\r
});
\r
});
\r
},
\r
dequeue: function(type){
\r
return this.each(function(){
\r
jQuery.dequeue( this, type );
\r
});
\r
+ },
\r
+ clearQueue: function(type){
\r
+ return this.queue( type || "fx", [] );
\r
}
\r
});
\ No newline at end of file
}
\r
});
\ No newline at end of file