diff options
| author | Jez Ng | 2012-01-18 14:45:11 +0800 |
|---|---|---|
| committer | Jez Ng | 2012-01-26 02:48:00 -0500 |
| commit | 4ad21d921120dba576a75d432b1e2bf4d42f51e3 (patch) | |
| tree | ad703e66a5b61e32c2ae6b357e6de5663ed97345 /options.html | |
| parent | 42bb33d427e3d8c36c31753bd0c0a81bf330e4ce (diff) | |
| download | vimium-4ad21d921120dba576a75d432b1e2bf4d42f51e3.tar.bz2 | |
Refactor settings storage and make it support empty strings.
It appears that localStorage keys with the empty string as their value
will have their values changed to undefined after a browser restart. The
DOM Inspector shows that the keys are still present, but '{{key}} in
localStorage' returns false. Convert all localStorage values to JSON as
a workaround.
This allows us to store null, numerical etc values seamlessly.
Closes #434.
Disable Vimium in the options page, due to a name collision.
Diffstat (limited to 'options.html')
| -rw-r--r-- | options.html | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/options.html b/options.html index 3d4033e3..e4142b4d 100644 --- a/options.html +++ b/options.html @@ -1,11 +1,7 @@ <html> <head> <title>Vimium Options</title> - <script src="lib/utils.js"></script> - <script src="lib/keyboardUtils.js"></script> - <script src="linkHints.js"></script> - <script src="lib/clipboard.js"></script> - <script src="vimiumFrontend.js"></script> + <script src="background/settings.js"></script> <style type="text/css" media="screen"> body { font-family:"helvetica neue", "helvetica", "arial", "sans"; @@ -142,18 +138,12 @@ field.value = fieldValue; } - var defaultFieldValue = (defaultSettings[fieldName] != null) ? - defaultSettings[fieldName].toString() : ""; - - // Don't save to storage if it's equal to the default - if (fieldValue == defaultFieldValue) - delete localStorage[fieldName]; - // ..or if it's empty and not a field that we allow to be empty. - else if (!fieldValue && canBeEmptyFields.indexOf(fieldName) == -1) { - delete localStorage[fieldName]; - fieldValue = defaultFieldValue; + // If it's empty and not a field that we allow to be empty, restore to the default value + if (!fieldValue && canBeEmptyFields.indexOf(fieldName) == -1) { + settings.clear(fieldName); + fieldValue = settings.get(fieldName); } else - localStorage[fieldName] = fieldValue; + settings.set(fieldName, fieldValue); $(fieldName).value = fieldValue; $(fieldName).setAttribute("savedValue", fieldValue); @@ -166,13 +156,8 @@ // Restores select box state to saved value from localStorage. function populateOptions() { for (var i = 0; i < editableFields.length; i++) { - // If it's null or undefined, let's go to the default. We want to allow empty strings in certain cases. - if (localStorage[editableFields[i]] != "" && !localStorage[editableFields[i]]) { - var val = defaultSettings[editableFields[i]] || ""; - } else { - var val = localStorage[editableFields[i]]; - } - setFieldValue($(editableFields[i]), val); + var val = settings.get(editableFields[i]) || ""; + setFieldValue($(editableFields[i]), val); } onDataLoaded(); } |
