Skip to content

Instantly share code, notes, and snippets.

@savetheclocktower
Forked from ZenCocoon/element_storage.js
Created January 28, 2009 12:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save savetheclocktower/53924 to your computer and use it in GitHub Desktop.
Save savetheclocktower/53924 to your computer and use it in GitHub Desktop.
Element.Storage = {
UID: 1
};
Element.addMethods({
getStorage: function(element) {
if (!(element = $(element))) return;
if (Object.isUndefined(element._prototypeUID))
element._prototypeUID = Element.Storage.UID++;
var uid = element._prototypeUID;
if (!Element.Storage[uid])
Element.Storage[uid] = $H();
return Element.Storage[uid];
},
store: function(element, key, value) {
if (!(element = $(element))) return;
element.getStorage().set(key, value);
return element;
},
retrieve: function(element, key, defaultValue) {
if (!(element = $(element))) return;
var hash = element.getStorage(), value = hash.get(key);
if (Object.isUndefined(value)) {
hash.set(key, defaultValue);
value = defaultValue;
}
return value;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment