Skip to content

Instantly share code, notes, and snippets.

@micmath
Created July 14, 2009 13:34
Show Gist options
  • Save micmath/146935 to your computer and use it in GitHub Desktop.
Save micmath/146935 to your computer and use it in GitHub Desktop.
window.jQuery = (window.jQuery || {});
(function() {
var uuid = 0;
var expando = "jQuery" + +new Date; // like "jQuery123456789"
jQuery._cache = {};
jQuery.data = function( elem, name, value ) {
if (typeof value == "undefined") {
return jQuery._getData(elem, name);
}
else {
return jQuery._setData(elem, name, value);
}
}
jQuery._setData = function( elem, name, value ) {
if (!elem[expando]) elem[expando] = ++uuid;
var id = elem[expando];
if (!jQuery._cache[id]) jQuery._cache[id] = {};
jQuery._cache[id][name] = value;
return id;
}
jQuery._getData = function( elem, name ) {
var id = elem[expando];
return jQuery._cache[id][name];
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment