[refactor] improve theme font if display and ui font is the same

This commit is contained in:
zombieFox 2020-01-03 11:58:39 -07:00
parent 977f966021
commit ac8b56c838
2 changed files with 59 additions and 45 deletions

View File

@ -2563,6 +2563,7 @@ var control = (function() {
type: "text", type: "text",
func: function() { func: function() {
theme.render.font.delay.display(); theme.render.font.delay.display();
theme.render.font.delay.ui();
} }
}, { }, {
element: helper.e(".control-theme-font-display-name-default"), element: helper.e(".control-theme-font-display-name-default"),
@ -2619,6 +2620,7 @@ var control = (function() {
path: "theme.font.ui.name", path: "theme.font.ui.name",
type: "text", type: "text",
func: function() { func: function() {
theme.render.font.delay.display();
theme.render.font.delay.ui(); theme.render.font.delay.ui();
} }
}, { }, {

View File

@ -859,20 +859,23 @@ var theme = (function() {
}, },
display: { display: {
name: function() { name: function() {
var name = state.get.current().theme.font.display.name.trim().replace(/\s+/g, "+");
var html = helper.e("html"); var html = helper.e("html");
var link = helper.e(".theme-font-display-name-link"); var removeLink = function() {
var link = helper.e(".theme-font-display-name");
if (link) { if (link) {
link.remove(); link.remove();
}; };
html.style.removeProperty("--theme-font-display-name"); html.style.removeProperty("--theme-font-display-name");
};
var addLink = function() {
var name = state.get.current().theme.font.display.name.trim().replace(/\s+/g, "+");
if (name != "") { if (name != "") {
var head = helper.e("head"); var head = helper.e("head");
var link = helper.makeNode({ var link = helper.makeNode({
tag: "link", tag: "link",
attr: [{ attr: [{
key: "class", key: "class",
value: "theme-font-display-name-link" value: "theme-font-display-name"
}, { }, {
key: "href", key: "href",
value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap" value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap"
@ -884,6 +887,9 @@ var theme = (function() {
head.appendChild(link); head.appendChild(link);
html.style.setProperty("--theme-font-display-name", "\"" + state.get.current().theme.font.display.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Fjalla One\", sans-serif"); html.style.setProperty("--theme-font-display-name", "\"" + state.get.current().theme.font.display.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Fjalla One\", sans-serif");
}; };
};
removeLink();
addLink();
}, },
weight: function() { weight: function() {
var html = helper.e("html"); var html = helper.e("html");
@ -897,22 +903,24 @@ var theme = (function() {
}, },
ui: { ui: {
name: function() { name: function() {
var name = state.get.current().theme.font.ui.name.trim().replace(/\s+/g, "+");
var html = helper.e("html"); var html = helper.e("html");
var link = helper.eA(".theme-font-ui-name-link"); var removeLink = function() {
if (link.length > 0) { var link = helper.e(".theme-font-ui-name");
link.forEach(function(arrayItem, item) { if (link) {
arrayItem.remove(); link.remove();
}); };
html.style.removeProperty("--theme-font-ui-name"); html.style.removeProperty("--theme-font-ui-name");
}; };
var addLink = function() {
var name = state.get.current().theme.font.ui.name.trim().replace(/\s+/g, "+");
if (name != "") { if (name != "") {
if (name != state.get.current().theme.font.display.name) {
var head = helper.e("head"); var head = helper.e("head");
var link = helper.makeNode({ var link = helper.makeNode({
tag: "link", tag: "link",
attr: [{ attr: [{
key: "class", key: "class",
value: "theme-font-ui-name-link" value: "theme-font-ui-name"
}, { }, {
key: "href", key: "href",
value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap" value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap"
@ -922,8 +930,12 @@ var theme = (function() {
}] }]
}); });
head.appendChild(link); head.appendChild(link);
};
html.style.setProperty("--theme-font-ui-name", "\"" + state.get.current().theme.font.ui.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Open Sans\", sans-serif"); html.style.setProperty("--theme-font-ui-name", "\"" + state.get.current().theme.font.ui.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Open Sans\", sans-serif");
}; };
};
removeLink();
addLink();
}, },
weight: function() { weight: function() {
var html = helper.e("html"); var html = helper.e("html");