implement wallpaper storage
This commit is contained in:
parent
0d732aa7d8
commit
891cb9ef7b
6 changed files with 73 additions and 12 deletions
|
@ -4,6 +4,9 @@
|
||||||
--main_color: #1f9b92;
|
--main_color: #1f9b92;
|
||||||
--sub_color: #00000000;
|
--sub_color: #00000000;
|
||||||
--err_color: #DC143C;
|
--err_color: #DC143C;
|
||||||
|
|
||||||
|
--main_bg: '/static/bg2.png';
|
||||||
|
--login_bg: '/static/bg.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
* { scrollbar-color:var(--main_color) var(--sub_color); }
|
* { scrollbar-color:var(--main_color) var(--sub_color); }
|
||||||
|
@ -21,6 +24,7 @@ body {
|
||||||
background: var(--bg_color);
|
background: var(--bg_color);
|
||||||
color: var(--fg_color);
|
color: var(--fg_color);
|
||||||
background: url('/static/bg2.png');
|
background: url('/static/bg2.png');
|
||||||
|
background: url(var(--main_bg));
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: top left;
|
background-position: top left;
|
||||||
background-attachment: fixed;
|
background-attachment: fixed;
|
||||||
|
@ -28,6 +32,7 @@ body {
|
||||||
|
|
||||||
.login-body {
|
.login-body {
|
||||||
background: url('/static/bg.png');
|
background: url('/static/bg.png');
|
||||||
|
background: url(var(--login_bg));
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: center center;
|
background-position: center center;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
const defaultTheme = [ "#000000cc", "#ffffffff", "#1f9b92ff", "#00000000", "#DC143Cff" ];
|
const defaultTheme = [ "#000000cc", "#ffffffff", "#1f9b92ff", "#00000000", "#DC143Cff" ];
|
||||||
|
const loginBgReader = new FileReader();
|
||||||
|
const mainBgReader = new FileReader();
|
||||||
|
|
||||||
const saveData = {
|
const saveData = {
|
||||||
theme: defaultTheme,
|
theme: defaultTheme,
|
||||||
|
@ -28,7 +30,7 @@ function toByte(v) {
|
||||||
).slice(-2);
|
).slice(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTheme(theme) {
|
function resetTheme(theme, bg = false) {
|
||||||
try{
|
try{
|
||||||
let bg_col = theme[0];
|
let bg_col = theme[0];
|
||||||
let fg_col = theme[1];
|
let fg_col = theme[1];
|
||||||
|
@ -58,6 +60,13 @@ function resetTheme(theme) {
|
||||||
$("err_col_input").value = err_col;
|
$("err_col_input").value = err_col;
|
||||||
$("err_col_opacity").value = err_opacity;
|
$("err_col_opacity").value = err_opacity;
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
|
if (bg) {
|
||||||
|
localStorage.setItem("loginScreen", '/static/bg.png');
|
||||||
|
localStorage.setItem("mainScreen", '/static/bg2.png');
|
||||||
|
resetBG("login");
|
||||||
|
resetBG("main");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTheme() {
|
function setTheme() {
|
||||||
|
@ -87,23 +96,65 @@ function setTheme() {
|
||||||
document.body.style.setProperty("--sub_color", saveData.theme[3]);
|
document.body.style.setProperty("--sub_color", saveData.theme[3]);
|
||||||
document.body.style.setProperty("--err_color", saveData.theme[4]);
|
document.body.style.setProperty("--err_color", saveData.theme[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setBG("login");
|
||||||
|
setBG("main");
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBG(screen) {
|
function setBG(screen) {
|
||||||
// get the input element based on screen
|
let reader = null;
|
||||||
// create the reader
|
switch(screen) {
|
||||||
// save dataURL into localstorage
|
case "login":
|
||||||
|
reader = loginBgReader;
|
||||||
// resetBG(screen)
|
break;
|
||||||
|
case "main":
|
||||||
|
reader = mainBgReader;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const imgPath = $(`${screen}_bg_upload`)?.files[0];
|
||||||
|
if (imgPath) {
|
||||||
|
reader.readAsDataURL(imgPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetBG(screen) {
|
function resetBG(screen) {
|
||||||
// set dataURL from localstorage to theme state
|
// set dataURL from localstorage to theme state
|
||||||
|
saveData[screen + "Screen"] = localStorage.getItem(screen + "Screen");
|
||||||
// bind reader load -> body background set dataURL
|
// bind reader load -> body background set dataURL
|
||||||
|
let selector = null;
|
||||||
|
switch (screen) {
|
||||||
|
case "login":
|
||||||
|
selector = ".login-body";
|
||||||
|
break;
|
||||||
|
case "main":
|
||||||
|
selector = "body";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const rules = document.styleSheets[0].cssRules;
|
||||||
|
let rule = null;
|
||||||
|
for (var i = 0; i < rules.length; i++) {
|
||||||
|
if (rules[i].selectorText == selector) {
|
||||||
|
rule = rules[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rule.style.setProperty("background", `url('${saveData[screen + "Screen"]}`);
|
||||||
|
rule.style.setProperty("background-size", "cover");
|
||||||
|
rule.style.setProperty("background-attachment", "fixed");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadStorage();
|
function initializeReaders() {
|
||||||
resetTheme(saveData.theme);
|
loginBgReader.addEventListener("load", () => {
|
||||||
setTheme();
|
localStorage.setItem("loginScreen", loginBgReader.result);
|
||||||
|
resetBG("login");
|
||||||
|
}, false);
|
||||||
|
mainBgReader.addEventListener("load", () => {
|
||||||
|
localStorage.setItem("mainScreen", mainBgReader.result);
|
||||||
|
resetBG("main");
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeReaders();
|
||||||
resetBG("login");
|
resetBG("login");
|
||||||
resetBG("main");
|
resetBG("main");
|
4
static/theme2.js
Normal file
4
static/theme2.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
loadStorage();
|
||||||
|
resetTheme(saveData.theme);
|
||||||
|
setTheme();
|
|
@ -28,7 +28,7 @@
|
||||||
<label for="main-upload">Set Main BG</label><br/>
|
<label for="main-upload">Set Main BG</label><br/>
|
||||||
<input type="file" id="main_bg_upload" name="file"/>
|
<input type="file" id="main_bg_upload" name="file"/>
|
||||||
</div>
|
</div>
|
||||||
<button onclick="setTheme()">Apply</button><button onclick="resetTheme(defaultTheme)">Reset</button>
|
<button onclick="setTheme()">Apply</button><button onclick="resetTheme(defaultTheme, true)">Reset</button>
|
||||||
</form>
|
</form>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{define "footer"}}
|
{{define "footer"}}
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script src="/static/theme.js" type="text/javascript"></script>
|
<script src="/static/theme2.js" type="text/javascript"></script>
|
||||||
</html>
|
</html>
|
||||||
{{end}}
|
{{end}}
|
|
@ -8,6 +8,7 @@
|
||||||
<link rel='stylesheet' type='text/css' href='/static/style.css'>
|
<link rel='stylesheet' type='text/css' href='/static/style.css'>
|
||||||
<link rel='shortcut icon' href='/static/favicon.png'>
|
<link rel='shortcut icon' href='/static/favicon.png'>
|
||||||
|
|
||||||
|
<script src="/static/theme.js" type="text/javascript"></script>
|
||||||
<title>Nirvash — CMS</title>
|
<title>Nirvash — CMS</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Loading…
Reference in a new issue