Simplify storage checking/access
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2711 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -43,7 +43,8 @@ svgEditor.addExtension('storage', function() {
|
||||
// or adding of new storage takes place regardless of settings, set
|
||||
// the "noStorageOnLoad" config setting to true in config.js.
|
||||
noStorageOnLoad = svgEditor.curConfig.noStorageOnLoad,
|
||||
forceStorage = svgEditor.curConfig.forceStorage;
|
||||
forceStorage = svgEditor.curConfig.forceStorage,
|
||||
storage = svgEditor.storage;
|
||||
|
||||
function replaceStoragePrompt (val) {
|
||||
val = val ? 'storagePrompt=' + val : '';
|
||||
@@ -57,13 +58,13 @@ svgEditor.addExtension('storage', function() {
|
||||
}
|
||||
}
|
||||
function setSVGContentStorage (val) {
|
||||
if ('localStorage' in window) {
|
||||
if (storage) {
|
||||
var name = 'svgedit-' + svgEditor.curConfig.canvasName;
|
||||
if (!val) {
|
||||
window.localStorage.removeItem(name);
|
||||
storage.removeItem(name);
|
||||
}
|
||||
else {
|
||||
window.localStorage.setItem(name, val);
|
||||
storage.setItem(name, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,12 +79,12 @@ svgEditor.addExtension('storage', function() {
|
||||
|
||||
function emptyStorage() {
|
||||
setSVGContentStorage('');
|
||||
var name, hasStorage = 'localStorage' in window;
|
||||
var name;
|
||||
for (name in svgEditor.curPrefs) {
|
||||
if (svgEditor.curPrefs.hasOwnProperty(name)) {
|
||||
name = 'svg-edit-' + name;
|
||||
if (hasStorage) {
|
||||
window.localStorage.removeItem(name);
|
||||
if (storage) {
|
||||
storage.removeItem(name);
|
||||
}
|
||||
expireCookie(name);
|
||||
}
|
||||
@@ -115,10 +116,10 @@ svgEditor.addExtension('storage', function() {
|
||||
// svgEditor.showSaveWarning = false;
|
||||
|
||||
var curPrefs = svgEditor.curPrefs;
|
||||
|
||||
for (key in curPrefs) {
|
||||
if (curPrefs.hasOwnProperty(key)) { // It's our own config, so we don't need to iterate up the prototype chain
|
||||
var storage = svgEditor.storage,
|
||||
val = curPrefs[key],
|
||||
var val = curPrefs[key],
|
||||
store = (val != undefined);
|
||||
key = 'svg-edit-' + key;
|
||||
if (!store) {
|
||||
@@ -195,7 +196,7 @@ svgEditor.addExtension('storage', function() {
|
||||
)) {
|
||||
|
||||
var options = [];
|
||||
if ('localStorage' in window) {
|
||||
if (storage) {
|
||||
options.unshift(
|
||||
{value: 'prefsAndContent', text: uiStrings.confirmSetStorage.storagePrefsAndContent},
|
||||
{value: 'prefsOnly', text: uiStrings.confirmSetStorage.storagePrefsOnly},
|
||||
|
||||
@@ -237,34 +237,23 @@ TO-DOS
|
||||
}
|
||||
|
||||
// LOAD CONTENT
|
||||
if ('localStorage' in window && // Cookies do not have enough available memory to hold large documents
|
||||
if (editor.storage && // Cookies do not have enough available memory to hold large documents
|
||||
(curConfig.forceStorage || (!curConfig.noStorageOnLoad && document.cookie.match(/(?:^|;\s*)store=prefsAndContent/)))
|
||||
) {
|
||||
var name = 'svgedit-' + curConfig.canvasName;
|
||||
var cached = window.localStorage.getItem(name);
|
||||
var cached = editor.storage.getItem(name);
|
||||
if (cached) {
|
||||
editor.loadFromString(cached);
|
||||
}
|
||||
}
|
||||
|
||||
// LOAD PREFS
|
||||
var key, storage = false;
|
||||
// var host = location.hostname,
|
||||
// onWeb = host && host.indexOf('.') >= 0;
|
||||
|
||||
// Some FF versions throw security errors here
|
||||
try {
|
||||
if (window.localStorage) { // && onWeb removed so Webkit works locally
|
||||
storage = localStorage;
|
||||
}
|
||||
} catch(err) {}
|
||||
editor.storage = storage;
|
||||
|
||||
var key;
|
||||
for (key in defaultPrefs) {
|
||||
if (defaultPrefs.hasOwnProperty(key)) { // It's our own config, so we don't need to iterate up the prototype chain
|
||||
var storeKey = 'svg-edit-' + key;
|
||||
if (storage) {
|
||||
var val = storage.getItem(storeKey);
|
||||
if (editor.storage) {
|
||||
var val = editor.storage.getItem(storeKey);
|
||||
if (val) {
|
||||
defaultPrefs[key] = String(val); // Convert to string for FF (.value fails in Webkit)
|
||||
}
|
||||
@@ -409,6 +398,15 @@ TO-DOS
|
||||
};
|
||||
|
||||
editor.init = function () {
|
||||
// var host = location.hostname,
|
||||
// onWeb = host && host.indexOf('.') >= 0;
|
||||
// Some FF versions throw security errors here when directly accessing
|
||||
try {
|
||||
if ('localStorage' in window) { // && onWeb removed so Webkit works locally
|
||||
editor.storage = localStorage;
|
||||
}
|
||||
} catch(err) {}
|
||||
|
||||
// Todo: Avoid var-defined functions and group functions together, etc. where possible
|
||||
var good_langs = [];
|
||||
$('#lang_select option').each(function() {
|
||||
|
||||
Reference in New Issue
Block a user