diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 4ea59264..a5b09863 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -104,9 +104,9 @@
"message": "An error has occurred using the Stylish database. Would you like to visit a web page with possible solutions?",
"description": "Prompt when a DB error is encountered"
},
- "default": {
+ "defaultTheme": {
"message": "default",
- "description": "Default item in various lists"
+ "description": "Default CodeMirror CSS theme option on the edit style page"
},
"deleteStyleLabel": {
"message": "Delete",
diff --git a/apply.js b/apply.js
index 6d31bf5a..cc8fc8a0 100644
--- a/apply.js
+++ b/apply.js
@@ -1,6 +1,10 @@
requestStyles();
function requestStyles() {
+ // If this is a Stylish page (Edit Style or Manage Styles),
+ // we'll request the styles directly to minimize delay and flicker,
+ // unless Chrome still starts up and the background page isn't fully loaded.
+ // (Note: in this case the function may be invoked again from applyStyles.)
var request = {method: "getStyles", matchUrl: location.href, enabled: true, asHash: true};
if (location.href.indexOf(chrome.extension.getURL("")) == 0) {
var bg = chrome.extension.getBackgroundPage();
diff --git a/edit.js b/edit.js
index 64cb30ba..aa957415 100644
--- a/edit.js
+++ b/edit.js
@@ -176,22 +176,22 @@ function initCodeMirror() {
// initialize global editor controls
document.addEventListener("DOMContentLoaded", function() {
- function concatOption(html, option) {
- return html + "";
+ function optionsHtmlFromArray(options) {
+ return options.map(function(opt) { return ""; }).join("");
}
- var bg = chrome.extension.getBackgroundPage();
var themeControl = document.getElementById("editor.theme");
+ var bg = chrome.extension.getBackgroundPage();
if (bg && bg.codeMirrorThemes) {
- themeControl.innerHTML = bg.codeMirrorThemes.reduce(concatOption, "");
+ themeControl.innerHTML = optionsHtmlFromArray(bg.codeMirrorThemes);
} else {
// Chrome is starting up and shows our edit.html, but the background page isn't loaded yet
- themeControl.innerHTML = concatOption("", theme == "default" ? t(theme) : theme);
+ themeControl.innerHTML = optionsHtmlFromArray([theme == "default" ? t("defaultTheme") : theme]);
getCodeMirrorThemes(function(themes) {
- themeControl.innerHTML = themes.reduce(concatOption, "");
+ themeControl.innerHTML = optionsHtmlFromArray(themes);
themeControl.selectedIndex = Math.max(0, themes.indexOf(theme));
});
}
- document.getElementById("editor.keyMap").innerHTML = Object.keys(CM.keyMap).sort().reduce(concatOption, "");
+ document.getElementById("editor.keyMap").innerHTML = optionsHtmlFromArray(Object.keys(CM.keyMap).sort());
var controlPrefs = {};
document.querySelectorAll("#options *[data-option][id^='editor.']").forEach(function(option) {
controlPrefs[option.id] = CM.defaults[option.dataset.option];
@@ -218,7 +218,7 @@ function acmeEventListener(event) {
case "theme":
var themeLink = document.getElementById("cm-theme");
// use non-localized "default" internally
- if (!value || value == "default" || value == t("default")) {
+ if (!value || value == "default" || value == t("defaultTheme")) {
value = "default";
if (prefs.getPref(el.id) != value) {
prefs.setPref(el.id, value);
diff --git a/storage.js b/storage.js
index 945c4632..6e03b152 100644
--- a/storage.js
+++ b/storage.js
@@ -228,7 +228,7 @@ function getCodeMirrorThemes(callback) {
chrome.runtime.getPackageDirectoryEntry(function(rootDir) {
rootDir.getDirectory("codemirror/theme", {create: false}, function(themeDir) {
themeDir.createReader().readEntries(function(entries) {
- var themes = [chrome.i18n.getMessage("default")];
+ var themes = [chrome.i18n.getMessage("defaultTheme")];
entries
.filter(function(entry) { return entry.isFile })
.sort(function(a, b) { return a.name < b.name ? -1 : 1 })