Created
February 18, 2011 11:57
-
-
Save DimitarChristoff/833584 to your computer and use it in GitHub Desktop.
making cloning element storage in mootools possible
This file contains 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 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