From a6616e5637b74941194ade558a692edf847f7fc9 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Tue, 17 Feb 2015 13:50:51 -0600 Subject: [PATCH] Fix defaulting of prefs --- edit.js | 4 ++-- manage.js | 2 +- storage.js | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/edit.js b/edit.js index d6324f1c..a2ea306f 100644 --- a/edit.js +++ b/edit.js @@ -19,7 +19,7 @@ function setupCodeMirror(textarea) { mode: 'css', lineNumbers: true, lineWrapping: true, - smartIndent: localStorage["smart-indent"] == null || localStorage["smart-indent"] == "true" + smartIndent: (typeof localStorage["smart-indent"] == "undefined") || localStorage["smart-indent"] == "true" }); editors.push(cm); } @@ -125,7 +125,7 @@ window.addEventListener("load", init, false); function init() { tE("sections-help", "helpAlt", "alt"); - loadPrefs(["smart-indent"]); + loadPrefs({"smart-indent": "true"}); var params = getParams(); if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses // This is an add diff --git a/manage.js b/manage.js index 3d34c009..8551e408 100644 --- a/manage.js +++ b/manage.js @@ -15,7 +15,7 @@ function showStyles(styles) { styles.map(createStyleElement).forEach(function(e) { installed.appendChild(e); }); - loadPrefs(["show-badge"]); + loadPrefs({"show-badge": "true"}); } function createStyleElement(style) { diff --git a/storage.js b/storage.js index 7a3e3604..da7eb75e 100644 --- a/storage.js +++ b/storage.js @@ -153,9 +153,10 @@ function changePref(event) { notifyAllTabs({method: "prefChanged", prefName: el.id, value: value}); } -function loadPrefs(prefNames) { - prefNames.forEach(function(id) { - var value = localStorage[id]; +// Accepts a hash of pref name to default value +function loadPrefs(prefs) { + for (var id in prefs) { + var value = typeof localStorage[id] == "undefined" ? prefs[id] : localStorage[id]; var el = document.getElementById(id); if (isCheckbox(el)) { if (value == "true") { @@ -165,5 +166,5 @@ function loadPrefs(prefNames) { el.value = value; } el.addEventListener("change", changePref); - }); + } }