Created
February 27, 2010 05:48
-
-
Save rkatic/316506 to your computer and use it in GitHub Desktop.
jQuery.data( object )
This file contains hidden or 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
(function($){ | |
var expando = "jQuery" + (new Date).getTime(), | |
hasOwnProperty = Object.prototype.hasOwnProperty, | |
_data = $.data, | |
_removeData = $.removeData; | |
$.data = function( obj, name, data ) { | |
if ( obj.nodeType ) { | |
return _data( obj, name, data ); | |
} | |
var thisCache, hasCache = hasOwnProperty.call( obj, expando ); | |
if ( !hasCache && typeof name === "string" && data === undefined ) { | |
return undefined; | |
} | |
if ( typeof name === "object" ) { | |
obj[ expando ] = $.extend(true, {}, name); | |
} else if ( !hasCache ) { | |
obj[ expando ] = {}; | |
} | |
thisCache = obj[ expando ]; | |
if ( typeof name === "string" ) { | |
if ( data !== undefined ) { | |
thisCache[ name ] = data; | |
} | |
return thisCache[ name ]; | |
} | |
return thisCache; | |
}; | |
$.removeData = function( obj, name ) { | |
if ( obj.nodeType ) { | |
return _removeData( obj, name ); | |
} | |
if ( name ) { | |
if ( hasOwnProperty.call( obj, expando ) ) { | |
delete obj[ expando ][ name ]; | |
if ( $.isEmptyObject( obj[expando] ) ) { | |
delete obj[ expando ]; | |
} | |
} | |
} else { | |
delete obj[ expando ]; | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment