diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/js/script.js | 11 | ||||
-rw-r--r-- | source/js/script.min.js | 2 | ||||
-rw-r--r-- | source/js/script.ts | 13 |
3 files changed, 25 insertions, 1 deletions
diff --git a/source/js/script.js b/source/js/script.js index ae91858..8a3daa5 100644 --- a/source/js/script.js +++ b/source/js/script.js @@ -31,6 +31,17 @@ window.addEventListener("load", function () { }); }; darklistener.add(colorman); + // Add logo color selector + var logoman = function (mode) { + var logo = document.getElementById("logo"); + var darksrc = logo === null || logo === void 0 ? void 0 : logo.getAttribute("data-src-darkmode"); + var lightsrc = logo === null || logo === void 0 ? void 0 : logo.getAttribute("data-src-lightmode"); + if (!logo || !darksrc || !lightsrc) + return; + var src = (mode === SystemDarkmodePrefrence.dark) ? darksrc : lightsrc; + logo.setAttribute("src", src); + }; + darklistener.add(logoman); }); /* Darkmode listener */ var SystemDarkmodePrefrence; diff --git a/source/js/script.min.js b/source/js/script.min.js index 078e42b..487569f 100644 --- a/source/js/script.min.js +++ b/source/js/script.min.js @@ -1 +1 @@ -"use strict"; window.addEventListener("load", function () { var a = Array.prototype.slice.call(document.querySelectorAll(".navbar-burger"), 0); if (a.length > 0) { a.forEach(function (c) { c.addEventListener("click", function () { var e = c.getAttribute("data-target"); c.classList.toggle("is-active"); if (!e) { return } var d = document.getElementById(e); d === null || d === void 0 ? void 0 : d.classList.toggle("is-active") }, false) }) } var b = function (e) { var d = ".auto-dark"; var c = Array.prototype.slice.call(document.querySelectorAll(d), 0); c.forEach(function (f) { if (e === SystemDarkmodePrefrence.dark) { f === null || f === void 0 ? void 0 : f.classList.add("is-dark"); f === null || f === void 0 ? void 0 : f.classList.remove("is-light") } else { f === null || f === void 0 ? void 0 : f.classList.add("is-light"); f === null || f === void 0 ? void 0 : f.classList.remove("is-dark") } }) }; darklistener.add(b) }); var SystemDarkmodePrefrence; (function (a) { a[a["dark"] = 0] = "dark"; a[a["light"] = 1] = "light" })(SystemDarkmodePrefrence || (SystemDarkmodePrefrence = {})); var DarkmodeListener = (function () { function a() { var b = window.matchMedia("(prefers-color-scheme: dark)").matches; this._mode = b ? SystemDarkmodePrefrence.dark : SystemDarkmodePrefrence.light; this._handlers = []; this._listen() } a.prototype._listen = function () { var d = this; var b = window.matchMedia("(prefers-color-scheme: dark)"); var c = function (e) { var f = e.matches ? SystemDarkmodePrefrence.dark : SystemDarkmodePrefrence.light; d._handlers.forEach(function (g) { g(f) }); d._mode = f }; b.addEventListener("change", c) }; a.prototype.add = function (b) { b(this._mode); this._handlers.push(b) }; a.prototype.mode = function () { return this._mode }; return a }()); var darklistener = new DarkmodeListener();
\ No newline at end of file +"use strict"; window.addEventListener("load", function () { var a = Array.prototype.slice.call(document.querySelectorAll(".navbar-burger"), 0); if (a.length > 0) { a.forEach(function (d) { d.addEventListener("click", function () { var f = d.getAttribute("data-target"); d.classList.toggle("is-active"); if (!f) { return } var e = document.getElementById(f); e === null || e === void 0 ? void 0 : e.classList.toggle("is-active") }, false) }) } var c = function (f) { var e = ".auto-dark"; var d = Array.prototype.slice.call(document.querySelectorAll(e), 0); d.forEach(function (g) { if (f === SystemDarkmodePrefrence.dark) { g === null || g === void 0 ? void 0 : g.classList.add("is-dark"); g === null || g === void 0 ? void 0 : g.classList.remove("is-light") } else { g === null || g === void 0 ? void 0 : g.classList.add("is-light"); g === null || g === void 0 ? void 0 : g.classList.remove("is-dark") } }) }; darklistener.add(c); var b = function (h) { var e = document.getElementById("logo"); var g = e === null || e === void 0 ? void 0 : e.getAttribute("data-src-darkmode"); var d = e === null || e === void 0 ? void 0 : e.getAttribute("data-src-lightmode"); if (!e || !g || !d) { return } var f = (h === SystemDarkmodePrefrence.dark) ? g : d; e.setAttribute("src", f) }; darklistener.add(b) }); var SystemDarkmodePrefrence; (function (a) { a[a["dark"] = 0] = "dark"; a[a["light"] = 1] = "light" })(SystemDarkmodePrefrence || (SystemDarkmodePrefrence = {})); var DarkmodeListener = (function () { function a() { var b = window.matchMedia("(prefers-color-scheme: dark)").matches; this._mode = b ? SystemDarkmodePrefrence.dark : SystemDarkmodePrefrence.light; this._handlers = []; this._listen() } a.prototype._listen = function () { var d = this; var b = window.matchMedia("(prefers-color-scheme: dark)"); var c = function (e) { var f = e.matches ? SystemDarkmodePrefrence.dark : SystemDarkmodePrefrence.light; d._handlers.forEach(function (g) { g(f) }); d._mode = f }; b.addEventListener("change", c) }; a.prototype.add = function (b) { b(this._mode); this._handlers.push(b) }; a.prototype.mode = function () { return this._mode }; return a }()); var darklistener = new DarkmodeListener();
\ No newline at end of file diff --git a/source/js/script.ts b/source/js/script.ts index e6a2155..912c1d9 100644 --- a/source/js/script.ts +++ b/source/js/script.ts @@ -32,6 +32,19 @@ window.addEventListener("load", () => { }) } darklistener.add(colorman); + + // Add logo color selector + const logoman = (mode: SystemDarkmodePrefrence) => { + const logo = document.getElementById("logo"); + const darksrc = logo?.getAttribute("data-src-darkmode"); + const lightsrc = logo?.getAttribute("data-src-lightmode"); + if (!logo || !darksrc || !lightsrc) + return; + let src = (mode === SystemDarkmodePrefrence.dark) ? darksrc : lightsrc; + logo.setAttribute("src", src); + } + darklistener.add(logoman); + }); /* Darkmode listener */ |