Merge pull request #1135 from leduyquang753/custom-font-fix

Custom font fixes
This commit is contained in:
Jack 2021-03-24 12:58:02 +00:00 committed by GitHub
commit fff0839352
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -106,6 +106,12 @@ function hideTestConfig() {
$("#top .config").css("opacity", 0).addClass("hidden");
}
function isConfigKeyValid(name) {
if (name === null || name === undefined || name === "") return false;
if (name.length > 30) return false;
return /^[0-9a-zA-Z_.\-#+]+$/.test(name);
}
function setPlaySoundOnError(val, nosave) {
if (val == undefined) {
val = false;
@ -943,16 +949,37 @@ function previewFontFamily(font) {
if (font == undefined) {
font = "Roboto_Mono";
}
document.documentElement.style.setProperty("--font", font.replace(/_/g, " "));
document.documentElement.style.setProperty(
"--font",
'"' + font.replace(/_/g, " ") + '"'
);
}
//font family
function setFontFamily(font, nosave) {
if (font == undefined || font === "") {
font = "Roboto_Mono";
Notifications.add(
"Empty input received, reverted to the default font.",
0,
3,
"Custom font"
);
}
if (!isConfigKeyValid(font)) {
Notifications.add(
`Invalid font name value: "${font}".`,
-1,
3,
"Custom font"
);
return;
}
ConfigSet.fontFamily(font);
document.documentElement.style.setProperty("--font", font.replace(/_/g, " "));
document.documentElement.style.setProperty(
"--font",
'"' + font.replace(/_/g, " ") + '"'
);
Chart.defaults.global.defaultFontFamily = font.replace(/_/g, " ");
if (!nosave) saveConfigToCookie();
}