diff --git a/html/js/keks.js b/html/js/keks.js
index 0412130..f55a833 100644
--- a/html/js/keks.js
+++ b/html/js/keks.js
@@ -3,6 +3,15 @@ switchcb.ads = (s) => {
console.log("settings ads setting to "+s)
}
switchcb.the = (s) => {
+ switch ( s ) {
+ case "on":
+ themes.set($(".themeselect").val())
+ break
+
+ case "off":
+ setCookie("theme", "", 1)
+ break
+ }
console.log("themes "+s)
}
switchcb.oth = (s) => {
@@ -13,7 +22,7 @@ toggler = new class {
constructor() {
}
- toggle( jtag, s ) {
+ toggle( jtag, s, cb ) {
if ( !s ) {
s = $(jtag).attr("state")
if ( s == "on") {
@@ -25,27 +34,42 @@ toggler = new class {
}
}
- let je = $(jtag).attr("state", s)
+ let je = $(jtag)
+ je.attr("state", s)
let classes = je.attr("class").split(" ")
switch ( s ) {
case "noff":
- classes.splice(2,2)
+ classes.splice(2,-1)
classes[2] = "noff"
break
case "on":
- classes.splice(2,2)
+ classes.splice(2,-1)
classes[2] = "on"
break
case "off":
- classes.splice(2,2)
+ classes.splice(2,-1)
classes[2] = "off"
break
}
je.attr("class", classes.join(" "))
- switchcb[je.attr("cb")](s)
+ if ( !cb ) eval(`s="${s}";`+je.attr("cb"))
return s
}
}
+// readout theme and create selector
+$(document).ready(() => {
+let c = getCookie("theme")
+if ( !c )
+ toggler.toggle(".cookie.setting.theme", "noff", true)
+else
+ toggler.toggle(".cookie.setting.theme", "on", true)
+
+$(".cookiesetting.theme").append(``)
+})
diff --git a/html/js/themes.js b/html/js/themes.js
index c7d3236..f94e801 100644
--- a/html/js/themes.js
+++ b/html/js/themes.js
@@ -1,21 +1,50 @@
-class themes {
+function setCookie(cname, cvalue, exdays) {
+ if ( !exdays ) {
+ exdays = 10**20
+ }
+ const d = new Date();
+ d.setTime(d.getTime() + (exdays*24*60*60*1000));
+ let expires = "expires="+ d.toUTCString();
+ document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
+}
+
+function getCookie(cname) {
+ let name = cname + "=";
+ let decodedCookie = decodeURIComponent(document.cookie);
+ let ca = decodedCookie.split(';');
+ for(let i = 0; i d.json()).then( d => {
- if ( d.type == "s" )
- this.loadstyle( d.style )
- else
- console.error("Couldnt read user style")
- })
+ this.theme = getCookie("theme")
+
+ if( !this.theme ) {
+ this.theme = "light"
+ }
+
+ this.loadstyle(this.theme)
}
loadstyle( style ) {
+ this.theme = style
$.get( "/static/style/" + style + ".css" , css => {
$('')
.html(css).appendTo("head")
})
}
-}
-// static until cookie model implemented / user / idk preferences
-new themes("light")
+ set( style ) {
+ setCookie( "theme", style )
+ location = location
+ }
+}
diff --git a/html/keks.html b/html/keks.html
index 77d53bd..3f0d44d 100644
--- a/html/keks.html
+++ b/html/keks.html
@@ -30,13 +30,13 @@
Here you can change your cookie settings:
+ Other:
(does nothing)
+
+
+
diff --git a/html/style/light.css b/html/style/light.css
index 87f8be7..2d71adf 100644
--- a/html/style/light.css
+++ b/html/style/light.css
@@ -164,3 +164,14 @@
.footer > a.text {
font-size: 0.7em;
}
+
+/* cookie settings */
+.cookiesetting > * {
+ margin-right: 0px;
+ margin-left: 0.5em;
+}
+.cookiesetting {
+ display: flex;
+ justify-content: left;
+}
+