Skip to content

Instantly share code, notes, and snippets.

@DimitarChristoff
Created February 18, 2011 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DimitarChristoff/833584 to your computer and use it in GitHub Desktop.
Save DimitarChristoff/833584 to your computer and use it in GitHub Desktop.
making cloning element storage in mootools possible
(function() {
var eliminateOrig = Element.prototype.eliminate;
var localStorage = {};
var get = function(uid){
return (localStorage[uid] || (localStorage[uid] = [])); // converted to an array to store keys stored
};
Element.implement({
lstore: function(property, value) {
// use this instead of Element.store
var storage = get(this.uid);
// store the key so we can clone it after
if (!storage[property])
storage.push(property);
return this.store.apply(this, arguments);
},
eliminate: function(property) {
var storage = get(this.uid);
storage.erase(property);
return eliminateOrig.apply(this, arguments);
},
cloneStorage: function(from) {
// new prototype to clone
var other = get(from.uid);
other.each(function(el) {
this.lstore(el, from.retrieve(el));
}, this);
return this;
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment