Alter element storage API to handle the window object gracefully.

This commit is contained in:
Andrew Dupont 2008-12-14 01:35:12 -06:00
parent 3977e66796
commit 77b9a2614a
2 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,4 @@
* Added Element#store and Element#retrieve for safe, hash-backed storage of element metadata (no memory leaks). Also added Element#getStorage for working with the element's storage hash directly. Hat tip: Mootools. (ZenCocoon, Andrew Dupont)
* Add Element#store and Element#retrieve for safe, hash-backed storage of element metadata (no memory leaks). Also add Element#getStorage for working with the element's storage hash directly. Hat tip: Mootools. (ZenCocoon, Andrew Dupont)
* Fix issue where certain versions of Safari treat class names case-insensitively in Selector/$$ queries. (Andrew Dupont, kangax, Brice)

View File

@ -1214,11 +1214,15 @@ Element.addMethods({
getStorage: function(element) {
if (!(element = $(element))) return;
if (Object.isUndefined(element._prototypeUID))
element._prototypeUID = [Element.Storage.UID++];
var uid = element._prototypeUID[0];
var uid;
if (element === window) {
uid = 0;
} else {
if (Object.isUndefined(element._prototypeUID))
element._prototypeUID = [Element.Storage.UID++];
uid = element._prototypeUID[0];
}
if (!Element.Storage[uid])
Element.Storage[uid] = $H();
@ -1232,8 +1236,7 @@ Element.addMethods({
retrieve: function(element, key, defaultValue) {
if (!(element = $(element))) return;
var hash = element.getStorage(), value = hash.get(key);
var hash = Element.getStorage(element), value = hash.get(key);
if (Object.isUndefined(value)) {
hash.set(key, defaultValue);