On Aug 9, 2012, at 5:28 AM, Victor wrote:
> It may fail because this code may overwrite element's properties (and in some browsers like IE and Opera some attributes, mapped as element properties).
That's an excellent point.
> E.g. $("someInput").store("name", "foo").store("type", "bar"); Better will be some separate container to store values inside, but this leads to back-porting element storage back to Prototype 1.6:
>
> // storage container nested in each element
> if(typeof Element.store == 'undefined'){
> Element.addMethods({
> store: function(e, k, v){
> e._prototypeStorage = e._prototypeStorage || {};
> e._prototypeStorage[k] = v;
> },
> retrieve: function(e, k){
> e._prototypeStorage = e._prototypeStorage || {};
> return (e._prototypeStorage[k]);
> }
> });
> }
Would this construction:
e._prototypeStorage = e._prototypeStorage || {}
fall afoul of the issue that Jason pointed out? Would IE bork the assignment because the key wasn't in hash form and quoted?
Walter
>
> // storage container in closure
> (function(){
> if(typeof Element.store == 'undefined'){
> var storage = {};
> function uid(e) {
> // TODO return some uid for element like in Prototype 1.7
> }
> Element.addMethods({
> store: function(e, k, v){
> var id = uid(e);
> storage[id] = storage[id] || {};
> storage[id][k] = v;
> },
> retrieve: function(e, k){
> var id = uid(e);
> storage[id] = storage[id] || {};
> return (storage[id][k]);
> }
> });
> }
> })();
>
> --
> You received this message because you are subscribed to the Google Groups "Prototype &
script.aculo.us" group.
> To view this discussion on the web visit
https://groups.google.com/d/msg/prototype-scriptaculous/-/TH_WyncdHx0J.