From 546638dd268c4c4338079cb87f0183bd706fea05 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 11 Feb 2011 12:16:07 -0800 Subject: Fix a bug where you can't save empty fields if there's a non-empty default. Also made the option saving code more robust to similar scenarios --- options.html | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'options.html') diff --git a/options.html b/options.html index bfa01450..f52cb6ec 100644 --- a/options.html +++ b/options.html @@ -80,7 +80,9 @@ var defaultSettings = chrome.extension.getBackgroundPage().defaultSettings; var editableFields = ["scrollStepSize", "defaultZoomLevel", "excludedUrls", "linkHintCharacters", - "userDefinedLinkHintCss", "keyMappings"]; + "userDefinedLinkHintCss", "keyMappings"]; + + var canBeEmptyFields = ["excludedUrls", "keyMappings", "userDefinedLinkHintCss"]; var postSaveHooks = { keyMappings: function (value) { @@ -118,10 +120,17 @@ var fieldValue = $(fieldName).value.trim(); 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]; - else + // ..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; + } else localStorage[fieldName] = fieldValue; + $(fieldName).value = fieldValue; $(fieldName).setAttribute("savedValue", fieldValue); @@ -133,7 +142,12 @@ // Restores select box state to saved value from localStorage. function populateOptions() { for (var i = 0; i < editableFields.length; i++) { - $(editableFields[i]).value = localStorage[editableFields[i]] || defaultSettings[editableFields[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]]) { + $(editableFields[i]).value = defaultSettings[editableFields[i]] || ""; + } else { + $(editableFields[i]).value = localStorage[editableFields[i]]; + } $(editableFields[i]).setAttribute("savedValue", $(editableFields[i]).value); } } -- cgit v1.2.3 From c65e85a840ba25ee59141b8ae1c424ec804c81f9 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 11 Feb 2011 18:27:09 -0800 Subject: Make the options page use the normal help dialog code path when its showing the command view. This fixes a regression with the new advanced commands functionality -- the command view wasn't showing at all. --- options.html | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'options.html') diff --git a/options.html b/options.html index f52cb6ec..4e2f6ecc 100644 --- a/options.html +++ b/options.html @@ -75,8 +75,6 @@ -- cgit v1.2.3