public
Last active — forked from ZenCocoon/element_storage.js

  • Download Gist
element_storage.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
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;
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.