Code review & cosmetics
This commit is contained in:
parent
a0c5674f6f
commit
539be4ce43
|
@ -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",
|
||||
|
|
4
apply.js
4
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();
|
||||
|
|
16
edit.js
16
edit.js
|
@ -176,22 +176,22 @@ function initCodeMirror() {
|
|||
|
||||
// initialize global editor controls
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
function concatOption(html, option) {
|
||||
return html + "<option>" + option + "</option>";
|
||||
function optionsHtmlFromArray(options) {
|
||||
return options.map(function(opt) { return "<option>" + opt + "</option>"; }).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);
|
||||
|
|
|
@ -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 })
|
||||
|
|
Loading…
Reference in New Issue
Block a user