X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fdata.js;h=9cc76c603ef5402cae63f42a64fbd3c1758e9cf7;hb=190812c3be99bde536d373b6b6ab65cfe053a532;hp=e429c0de5cf89367667fbad22acff3a947c1d962;hpb=89b4bc53ca0ca3d4e5c80b94ce92b09cc34af8ef;p=jquery.git diff --git a/src/data.js b/src/data.js index e429c0d..9cc76c6 100644 --- a/src/data.js +++ b/src/data.js @@ -8,25 +8,24 @@ jQuery.extend({ windowData : elem; - var id = elem[ expando ]; + var id = elem[ expando ], cache = jQuery.cache; // Compute a unique ID for the element - if ( !id ) - id = elem[ expando ] = ++uuid; + if(!id) id = elem[ expando ] = ++uuid; // Only generate the data cache if we're // trying to access or manipulate it - if ( name && !jQuery.cache[ id ] ) - jQuery.cache[ id ] = {}; + if ( name && !cache[ id ] ) + cache[ id ] = {}; + + var thisCache = cache[ id ]; // Prevent overriding the named cache with undefined values - if ( data !== undefined ) - jQuery.cache[ id ][ name ] = data; + if ( data !== undefined ) thisCache[ name ] = data; - // Return the named cache data, or the ID for the element - return name ? - jQuery.cache[ id ][ name ] : - id; + if(name === true) return thisCache + else if(name) return thisCache[name] + else return id }, removeData: function( elem, name ) { @@ -34,21 +33,16 @@ jQuery.extend({ windowData : elem; - var id = elem[ expando ]; + var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ]; // If we want to remove a specific section of the element's data if ( name ) { - if ( jQuery.cache[ id ] ) { + if ( thisCache ) { // Remove the section of cache data - delete jQuery.cache[ id ][ name ]; + delete thisCache[ name ]; // If we've removed all the data, remove the element's cache - name = ""; - - for ( name in jQuery.cache[ id ] ) - break; - - if ( !name ) + if( jQuery.isEmptyObject(thisCache) ) jQuery.removeData( elem ); } @@ -65,7 +59,7 @@ jQuery.extend({ } // Completely remove the data cache - delete jQuery.cache[ id ]; + delete cache[ id ]; } }, queue: function( elem, type, data ) { @@ -98,6 +92,8 @@ jQuery.extend({ jQuery.fn.extend({ data: function( key, value ){ + if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true); + var parts = key.split("."); parts[1] = parts[1] ? "." + parts[1] : ""; @@ -130,16 +126,19 @@ jQuery.fn.extend({ if ( data === undefined ) return jQuery.queue( this[0], type ); - return this.each(function(){ + return this.each(function(i, elem){ var queue = jQuery.queue( this, type, data ); - if( type == "fx" && queue.length == 1 ) - queue[0].call(this); + if( type == "fx" && queue.length == 1 ) + queue[0].call(this, function() { jQuery(elem).dequeue(type); }); }); }, dequeue: function(type){ return this.each(function(){ jQuery.dequeue( this, type ); }); + }, + clearQueue: function(type){ + return this.queue( type || "fx", [] ); } }); \ No newline at end of file