Fix defaulting of prefs

This commit is contained in:
Jason Barnabe 2015-02-17 13:50:51 -06:00
parent 4dca2e8e33
commit a6616e5637
3 changed files with 8 additions and 7 deletions

View File

@ -19,7 +19,7 @@ function setupCodeMirror(textarea) {
mode: 'css', mode: 'css',
lineNumbers: true, lineNumbers: true,
lineWrapping: 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); editors.push(cm);
} }
@ -125,7 +125,7 @@ window.addEventListener("load", init, false);
function init() { function init() {
tE("sections-help", "helpAlt", "alt"); tE("sections-help", "helpAlt", "alt");
loadPrefs(["smart-indent"]); loadPrefs({"smart-indent": "true"});
var params = getParams(); var params = getParams();
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses
// This is an add // This is an add

View File

@ -15,7 +15,7 @@ function showStyles(styles) {
styles.map(createStyleElement).forEach(function(e) { styles.map(createStyleElement).forEach(function(e) {
installed.appendChild(e); installed.appendChild(e);
}); });
loadPrefs(["show-badge"]); loadPrefs({"show-badge": "true"});
} }
function createStyleElement(style) { function createStyleElement(style) {

View File

@ -153,9 +153,10 @@ function changePref(event) {
notifyAllTabs({method: "prefChanged", prefName: el.id, value: value}); notifyAllTabs({method: "prefChanged", prefName: el.id, value: value});
} }
function loadPrefs(prefNames) { // Accepts a hash of pref name to default value
prefNames.forEach(function(id) { function loadPrefs(prefs) {
var value = localStorage[id]; for (var id in prefs) {
var value = typeof localStorage[id] == "undefined" ? prefs[id] : localStorage[id];
var el = document.getElementById(id); var el = document.getElementById(id);
if (isCheckbox(el)) { if (isCheckbox(el)) {
if (value == "true") { if (value == "true") {
@ -165,5 +166,5 @@ function loadPrefs(prefNames) {
el.value = value; el.value = value;
} }
el.addEventListener("change", changePref); el.addEventListener("change", changePref);
}); }
} }