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

feat: simplify theme creation through file-based save/load

parent 997a90b9
Branches main
No related tags found
No related merge requests found
Pipeline #2600 passed
...@@ -307,8 +307,8 @@ ...@@ -307,8 +307,8 @@
<div class="container control"> <div class="container control">
<div class="controls"> <div class="controls">
<div class="io"> <div class="io">
<input id="data" /> <button id="save">Save Theme</button><button><label for="load">Load Theme</label></button>
<button id="copy">Copy</button> <input id="load" type="file" accept=".json,application/json"/>
</div> </div>
<div class="io"> <div class="io">
<button id="loadMaterialLight">Load Material Light</button> <button id="loadMaterialLight">Load Material Light</button>
......
...@@ -55,9 +55,6 @@ function updateColor(id, skipSave) { ...@@ -55,9 +55,6 @@ function updateColor(id, skipSave) {
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) {
...@@ -115,37 +112,34 @@ function save() { ...@@ -115,37 +112,34 @@ function save() {
return json; return json;
} }
function download(filename, content) {
const element = document.createElement("a");
const data = new Blob([content], {type : 'application/json'});
element.setAttribute("href", URL.createObjectURL(data));
element.setAttribute("download", filename);
element.style.display = "none";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
const data = document.getElementById("data"); const data = document.getElementById("data");
const buttonCopy = document.getElementById("copy"); const buttonSave = document.getElementById("save");
const inputLoad = document.getElementById("load");
data.addEventListener("keyup", () => { buttonSave.addEventListener("click", () => {
try { download("quasseldroid-theme.json", JSON.stringify(save()));
load(JSON.parse(data.value));
} catch (_) {
// ignore
}
}); });
inputLoad.addEventListener("change", () => {
data.addEventListener("blur", () => { if (inputLoad.files) {
try { inputLoad.files[0].text().then(raw => load(JSON.parse(raw)));
load(JSON.parse(data.value));
data.value = JSON.stringify(save());
} catch (_) {
// ignore
} }
}); });
buttonCopy.addEventListener("click", () => {
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);
button.addEventListener("click", () => { button.addEventListener("click", () => {
load(themeData[theme]); load(themeData[theme]);
data.value = JSON.stringify(save());
}); });
}); });
...@@ -156,9 +150,6 @@ function updateOption(option, skipSave) { ...@@ -156,9 +150,6 @@ function updateOption(option, skipSave) {
} else { } else {
delete cssRoot.dataset[option]; delete cssRoot.dataset[option];
} }
if (skipSave !== true) {
data.value = JSON.stringify(save());
}
} }
options.forEach((option) => { options.forEach((option) => {
...@@ -168,4 +159,3 @@ options.forEach((option) => { ...@@ -168,4 +159,3 @@ options.forEach((option) => {
}); });
updateOption(option, true); updateOption(option, true);
}); });
data.value = JSON.stringify(save());
...@@ -11,6 +11,10 @@ body { ...@@ -11,6 +11,10 @@ body {
align-items: center; align-items: center;
} }
input#load {
display: none;
}
.column { .column {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment