Skip to content
Snippets Groups Projects
Verified Commit 997a90b9 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Make it easier to create themes

parent 32f309db
Branches
No related tags found
No related merge requests found
Pipeline #2599 passed
...@@ -307,9 +307,8 @@ ...@@ -307,9 +307,8 @@
<div class="container control"> <div class="container control">
<div class="controls"> <div class="controls">
<div class="io"> <div class="io">
<button id="load">Load</button>
<button id="save">Save</button>
<input id="data" /> <input id="data" />
<button id="copy">Copy</button>
</div> </div>
<div class="io"> <div class="io">
<button id="loadMaterialLight">Load Material Light</button> <button id="loadMaterialLight">Load Material Light</button>
......
...@@ -45,15 +45,19 @@ colors.forEach((id) => { ...@@ -45,15 +45,19 @@ colors.forEach((id) => {
inputColor.addEventListener("change", change); inputColor.addEventListener("change", change);
inputOpacity.addEventListener("change", change); inputOpacity.addEventListener("change", change);
inputOpacity.addEventListener("mousemove", change); inputOpacity.addEventListener("mousemove", change);
updateColor(id, true);
}); });
function updateColor(id) { function updateColor(id, skipSave) {
const inputColor = document.getElementById(id+"-color"); const inputColor = document.getElementById(id+"-color");
const inputOpacity = document.getElementById(id+"-opacity"); const inputOpacity = document.getElementById(id+"-opacity");
const color = inputColor.value; const color = inputColor.value;
const opacity = inputOpacity.value / 255.0; const opacity = inputOpacity.value / 255.0;
cssRoot.style.setProperty("--"+id, hexToRgba(color, opacity)); cssRoot.style.setProperty("--"+id, hexToRgba(color, opacity));
if (skipSave !== true) {
data.value = JSON.stringify(save());
}
} }
function normalizeColor(value) { function normalizeColor(value) {
...@@ -88,7 +92,7 @@ function load(json) { ...@@ -88,7 +92,7 @@ function load(json) {
inputColor.value = data.color; inputColor.value = data.color;
inputOpacity.value = data.opacity; inputOpacity.value = data.opacity;
updateColor(id); updateColor(id, true);
}); });
} }
...@@ -112,18 +116,30 @@ function save() { ...@@ -112,18 +116,30 @@ function save() {
} }
const data = document.getElementById("data"); const data = document.getElementById("data");
const buttonSave = document.getElementById("save"); const buttonCopy = document.getElementById("copy");
const buttonLoad = document.getElementById("load");
buttonLoad.addEventListener("click", () => { data.addEventListener("keyup", () => {
try {
load(JSON.parse(data.value)); load(JSON.parse(data.value));
} catch (_) {
// ignore
}
}); });
buttonSave.addEventListener("click", () => { data.addEventListener("blur", () => {
try {
load(JSON.parse(data.value));
data.value = JSON.stringify(save()); data.value = JSON.stringify(save());
} catch (_) {
// ignore
}
}); });
buttonCopy.addEventListener("click", () => {
data.value = JSON.stringify(save()); data.value = JSON.stringify(save());
data.select();
document.execCommand("copy");
});
themes.forEach((theme) => { themes.forEach((theme) => {
const button = document.getElementById("load"+theme); const button = document.getElementById("load"+theme);
...@@ -133,13 +149,16 @@ themes.forEach((theme) => { ...@@ -133,13 +149,16 @@ themes.forEach((theme) => {
}); });
}); });
function updateOption(option) { function updateOption(option, skipSave) {
const input = document.getElementById(option); const input = document.getElementById(option);
if (input.checked) { if (input.checked) {
cssRoot.dataset[option] = undefined; cssRoot.dataset[option] = undefined;
} else { } else {
delete cssRoot.dataset[option]; delete cssRoot.dataset[option];
} }
if (skipSave !== true) {
data.value = JSON.stringify(save());
}
} }
options.forEach((option) => { options.forEach((option) => {
...@@ -147,7 +166,6 @@ options.forEach((option) => { ...@@ -147,7 +166,6 @@ options.forEach((option) => {
input.addEventListener("change", () => { input.addEventListener("change", () => {
updateOption(option); updateOption(option);
}); });
updateOption(option); updateOption(option, true);
}); });
data.value = JSON.stringify(save());
load(JSON.parse(data.value));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment