Added fix to prevent some FF versions from throwing errors on localStorage check

git-svn-id: http://svg-edit.googlecode.com/svn/branches/transformlist@931 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2009-11-11 21:13:16 +00:00
parent c5467373ef
commit 7c8fafa9ee
1 changed files with 16 additions and 6 deletions

View File

@ -35,12 +35,22 @@ function svg_edit_setup() {
var host = location.hostname;
var onweb = host && host.indexOf('.') != -1;
var store = (val != undefined);
if(window.localStorage && onweb) {
if(store) localStorage.setItem(key, val);
else return localStorage.getItem(key);
} else if(window.globalStorage && onweb) {
if(store) globalStorage[host].setItem(key, val);
else return globalStorage[host].getItem(key);
var storage = false;
// Some FF versions throw security errors here
try {
if(window.localStorage && onweb) {
storage = localStorage;
}
} catch(e) {}
try {
if(window.globalStorage && onweb) {
storage = globalStorage[host];
}
} catch(e) {}
if(storage) {
if(store) storage.setItem(key, val);
else return storage.getItem(key);
} else if(window.widget) {
if(store) widget.setPreferenceForKey(val, key);
else return widget.preferenceForKey(key);