From 3af6d9131f6dfc138856d718ec96626344095ec8 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Mon, 22 May 2023 23:24:44 -0700 Subject: Optimizations and Fixes --- static/js/theme_button.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 static/js/theme_button.js (limited to 'static/js/theme_button.js') diff --git a/static/js/theme_button.js b/static/js/theme_button.js new file mode 100644 index 0000000..34d1d78 --- /dev/null +++ b/static/js/theme_button.js @@ -0,0 +1,7 @@ +// Set lightmode +if (document.getElementById('mode')) { + document.getElementById('mode').addEventListener('click', () => { + document.documentElement.classList.toggle('light'); + localStorage.setItem('theme', document.documentElement.classList.contains('light') ? 'light' : 'dark'); + }); +} -- cgit v1.3.1 From cd71559564732e4f2b4752560ff1b6de6f737a79 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Wed, 19 Jul 2023 13:32:33 -0700 Subject: nojs configurable default switcher theme --- COPY-TO-ROOT-SASS/abridge.scss | 2 ++ config.toml | 2 ++ package.json | 20 +++++++++++--------- sass/abridge.scss | 17 +++++++++++++---- static/js/abridge.min.js | 2 +- static/js/theme.js | 4 ++-- static/js/theme.min.js | 2 +- static/js/theme_button.js | 4 ++-- static/js/theme_light.js | 4 ++++ static/js/theme_light.min.js | 1 + templates/macros/head.html | 9 +++++++-- 11 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 static/js/theme_light.js create mode 100644 static/js/theme_light.min.js (limited to 'static/js/theme_button.js') diff --git a/COPY-TO-ROOT-SASS/abridge.scss b/COPY-TO-ROOT-SASS/abridge.scss index 0fd51e9..a680fdd 100644 --- a/COPY-TO-ROOT-SASS/abridge.scss +++ b/COPY-TO-ROOT-SASS/abridge.scss @@ -10,8 +10,10 @@ $abridgeMode: "switcher",//valid values: switcher, auto, dark, light $syntax-mode: "auto",// Force syntax mode: auto, dark, light + $switcherDefault: "dark",// default for nojs switcher: dark, light $color: "orange",// color template to use/override: orange, blue, blueshade + $color-syntax: "abridge",// syntax color template to use/override: abridge, $syntax: true,//syntax highlighting for Code Blocks. diff --git a/config.toml b/config.toml index d5ab0c3..46acb10 100644 --- a/config.toml +++ b/config.toml @@ -202,6 +202,8 @@ integrity = true # increases site security, should normally be true. (setting to js_bundle = true # multiple javascript files combined into a single file (setting to false is useful during js development) js_switcher = true # The button that allows manually changing between light/dark mode. +js_switcher_default = "dark" # default switcher mode: dark, light + js_copycode = true # The copy button on code blocks that allows you to copy them to the clipboard. search_library = 'elasticlunr' diff --git a/package.json b/package.json index e376c3d..9514ab9 100644 --- a/package.json +++ b/package.json @@ -6,20 +6,22 @@ "license": "MIT", "homepage": "https://github.com/Jieiku/abridge", "scripts": { + "all": "npm run theme && npm run theme-light && npm run katex-bundle && npm run search-elasticlunr && npm run search-stork && npm run search-tinysearch && npm run abridge-bundle-elasticlunr", + "nonbundles": "npm run theme && npm run theme-light && npm run katex-bundle && npm run search-elasticlunr && npm run search-stork && npm run search-tinysearch", "theme": "uglifyjs static/js/theme.js -c -m -o static/js/theme.min.js", + "theme-light": "uglifyjs static/js/theme_light.js -c -m -o static/js/theme_light.min.js", "katex-bundle": "uglifyjs static/js/katex.min.js static/js/mathtex-script-type.min.js static/js/katex-auto-render.min.js static/js/katexoptions.js -c -m -o static/js/katexbundle.min.js", "search-elasticlunr": "uglifyjs static/js/elasticlunr.min.js static/js/search.js -c -m -o static/js/search_elasticlunr.min.js", "search-stork": "uglifyjs static/js/stork.js static/js/stork_config.js -c -m -o static/js/search_stork.min.js", "search-tinysearch": "uglifyjs static/js/tinysearch.js -c -m -o static/js/search_tinysearch.min.js", - "all": "npm run theme && npm run katex-bundle && npm run search-elasticlunr && npm run search-stork && npm run search-tinysearch", - "abridge-bundle-nosearch": "npm run all && uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", - "abridge-bundle-elasticlunr": "npm run all && uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/search_elasticlunr.min.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", - "abridge-bundle-tinysearch": "npm run all && uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/search_tinysearch.min.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", - "abridge-bundle-stork": "npm run all && uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/search_stork.min.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", - "nosearch": "npm run abridge-bundle-nosearch && sed -i \"s|^build_search_index.*|build_search_index = false|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = false|\" 'config.toml' && sed -i \"s|^draft.*|draft = true|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = true|\" 'content/static/stork_toml.md' && zola build", - "elasticlunr": "npm run abridge-bundle-elasticlunr && sed -i \"s|^build_search_index.*|build_search_index = true|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = 'elasticlunr'|\" 'config.toml' && sed -i \"s|^draft.*|draft = true|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = true|\" 'content/static/stork_toml.md' && zola build", - "tinysearch": "npm run abridge-bundle-tinysearch && sed -i \"s|^build_search_index.*|build_search_index = true|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = 'tinysearch'|\" 'config.toml' && sed -i \"s|^draft.*|draft = false|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = true|\" 'content/static/stork_toml.md' && zola build && mkdir -p tmp && tinysearch --optimize --path tmp public/data_tinysearch/index.html && rsync -avz tmp/*.wasm static/ && rm -rf tmp", - "stork": "npm run abridge-bundle-stork && sed -i \"s|^build_search_index.*|build_search_index = true|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = 'stork'|\" 'config.toml' && sed -i \"s|^draft.*|draft = true|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = false|\" 'content/static/stork_toml.md' && zola build && stork build --input public/data_stork/index.html --output static/stork.st" + "abridge-bundle-nosearch": "uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", + "abridge-bundle-elasticlunr": "uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/search_elasticlunr.min.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", + "abridge-bundle-tinysearch": "uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/search_tinysearch.min.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", + "abridge-bundle-stork": "uglifyjs static/js/prestyle.js static/js/theme_button.js static/js/search_stork.min.js static/js/email.js static/js/codecopy.js -c -m -o static/js/abridge.min.js", + "nosearch": "npm run nonbundles && npm run abridge-bundle-nosearch && sed -i \"s|^build_search_index.*|build_search_index = false|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = false|\" 'config.toml' && sed -i \"s|^draft.*|draft = true|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = true|\" 'content/static/stork_toml.md' && zola build", + "elasticlunr": "npm run nonbundles && npm run abridge-bundle-elasticlunr && sed -i \"s|^build_search_index.*|build_search_index = true|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = 'elasticlunr'|\" 'config.toml' && sed -i \"s|^draft.*|draft = true|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = true|\" 'content/static/stork_toml.md' && zola build", + "tinysearch": "npm run nonbundles && npm run abridge-bundle-tinysearch && sed -i \"s|^build_search_index.*|build_search_index = true|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = 'tinysearch'|\" 'config.toml' && sed -i \"s|^draft.*|draft = false|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = true|\" 'content/static/stork_toml.md' && zola build && mkdir -p tmp && tinysearch --optimize --path tmp public/data_tinysearch/index.html && rsync -avz tmp/*.wasm static/ && rm -rf tmp", + "stork": "npm run nonbundles && npm run abridge-bundle-stork && sed -i \"s|^build_search_index.*|build_search_index = true|\" 'config.toml' && sed -i \"s|^search_library.*|search_library = 'stork'|\" 'config.toml' && sed -i \"s|^draft.*|draft = true|\" 'content/static/tinysearch_json.md' && sed -i \"s|^draft.*|draft = false|\" 'content/static/stork_toml.md' && zola build && stork build --input public/data_stork/index.html --output static/stork.st" }, "dependencies": { "uglify-js": "^3.15.4" diff --git a/sass/abridge.scss b/sass/abridge.scss index 539e377..ac01c1a 100644 --- a/sass/abridge.scss +++ b/sass/abridge.scss @@ -17,6 +17,7 @@ $mb: 1200px !default;// value at which to switch from fluid layout to max-width $abridgeMode: "switcher" !default;//valid values: switcher, auto, dark, light $syntax-mode: "auto" !default;// Force syntax mode: auto, dark, light +$switcherDefault: "dark" !default;// default for nojs switcher: dark, light $color: "orange" !default;// color template to use/override: orange, blue, blueshade @@ -342,16 +343,24 @@ $syntax: true !default;//syntax highlighting for code blocks } } } - :root:not(.light) { - @include colors.dark($dark...); + :root:not(.switch) { + @if $switcherDefault == "light" { + @include colors.dark($light...); + } @else { + @include colors.dark($dark...); + } @if $syntax { @if $syntax-mode == "auto" { @include colors-syntax.syndark($syntax-dark...); } } } - :root.light { - @include colors.light($light...); + :root.switch { + @if $switcherDefault == "light" { + @include colors.dark($dark...); + } @else { + @include colors.dark($light...); + } @if $syntax { @if $syntax-mode == "auto" { @include colors-syntax.synlight($syntax-light...); diff --git a/static/js/abridge.min.js b/static/js/abridge.min.js index 4cfe749..4126e25 100644 --- a/static/js/abridge.min.js +++ b/static/js/abridge.min.js @@ -1 +1 @@ -const items=document.querySelectorAll(".preStyle"),changeIcon=(items.forEach(e=>{e.rel="stylesheet"}),document.getElementById("mode")&&document.getElementById("mode").addEventListener("click",()=>{document.documentElement.classList.toggle("light"),localStorage.setItem("theme",document.documentElement.classList.contains("light")?"light":"dark")}),!function(){function g(e){var t=new g.Index;return t.pipeline.add(g.trimmer,g.stopWordFilter,g.stemmer),e&&e.call(t,t),t}var a,c,e,t,d,h,f,p,m,v,y,S,x,b,w,I,E,C,D,F,k,L,_,N,n;g.version="0.9.5",((lunr=g).utils={}).warn=(n=this,function(e){n.console&&console.warn&&console.warn(e)}),g.utils.toString=function(e){return null==e?"":e.toString()},(g.EventEmitter=function(){this.events={}}).prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop();if("function"!=typeof t)throw new TypeError("last argument must be a function");e.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},g.EventEmitter.prototype.removeListener=function(e,t){this.hasHandler(e)&&-1!==(t=this.events[e].indexOf(t))&&(this.events[e].splice(t,1),0==this.events[e].length)&&delete this.events[e]},g.EventEmitter.prototype.emit=function(e){var t;this.hasHandler(e)&&(t=Array.prototype.slice.call(arguments,1),this.events[e].forEach(function(e){e.apply(void 0,t)},this))},g.EventEmitter.prototype.hasHandler=function(e){return e in this.events},(g.tokenizer=function(e){var t,n;return arguments.length&&null!=e?Array.isArray(e)?(t=(t=e.filter(function(e){return null!=e})).map(function(e){return g.utils.toString(e).toLowerCase()}),n=[],t.forEach(function(e){e=e.split(g.tokenizer.seperator),n=n.concat(e)},this),n):e.toString().trim().toLowerCase().split(g.tokenizer.seperator):[]}).defaultSeperator=/[\s\-]+/,g.tokenizer.seperator=g.tokenizer.defaultSeperator,g.tokenizer.setSeperator=function(e){null!=e&&"object"==typeof e&&(g.tokenizer.seperator=e)},g.tokenizer.resetSeperator=function(){g.tokenizer.seperator=g.tokenizer.defaultSeperator},g.tokenizer.getSeperator=function(){return g.tokenizer.seperator},(g.Pipeline=function(){this._queue=[]}).registeredFunctions={},g.Pipeline.registerFunction=function(e,t){t in g.Pipeline.registeredFunctions&&g.utils.warn("Overwriting existing registered function: "+t),e.label=t,g.Pipeline.registeredFunctions[t]=e},g.Pipeline.getRegisteredFunction=function(e){return e in g.Pipeline.registeredFunctions!=1?null:g.Pipeline.registeredFunctions[e]},g.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions||g.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},g.Pipeline.load=function(e){var n=new g.Pipeline;return e.forEach(function(e){var t=g.Pipeline.getRegisteredFunction(e);if(!t)throw new Error("Cannot load un-registered function: "+e);n.add(t)}),n},g.Pipeline.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(e){g.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},g.Pipeline.prototype.after=function(e,t){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e+1,0,t)},g.Pipeline.prototype.before=function(e,t){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e,0,t)},g.Pipeline.prototype.remove=function(e){-1!==(e=this._queue.indexOf(e))&&this._queue.splice(e,1)},g.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,o=this._queue.length,i=0;iu[o]&&o++:(t.add(s[n]),n++,o++);return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){for(var t,e=this.length>=e.length?(t=this,e):(t=e,this),n=t.clone(),o=0,i=e.toArray();o",a=n.querySelector("a"),t=n.querySelector("span:first-child"),d=n.querySelector("span:nth-child(2)"),a.href=e.ref,t.textContent=e.doc.title,d.innerHTML=function(e){var t=x.map(function(e){return elasticlunr.stemmer(e.toLowerCase())}),n=!1,o=0,i=[],r=e.toLowerCase().split(". ");for(f in r){var s,u=r[f].split(/[\s\n]/),l=8;for(s in u){if(0<(g=u[s]).length){for(var a in t)elasticlunr.stemmer(g).startsWith(t[a])&&(l=40,n=!0);i.push([g,l,o]),l=2}o=o+g.length+1}o+=1}if(0===i.length)return void 0!==e.length&&300"),S=g[2]+g[0].length,40!==g[1]&&12<=g[0].length&&!/^[\x00-\xff]+$/.test(g[0])?(v=function(e){for(var t="",n=!1,o=0,i=0,r=0,s=0;s");return y.push("…"),y.join("")}(e.doc.body),s.appendChild(n))});i.length>r;)s.removeChild(i[0])},!0),s.addEventListener("click",function(){for(;s.lastChild;)s.removeChild(s.lastChild);return!1},!0),document.goSearch.onsubmit=function(){var e=document.querySelector("main"),t=(window.main||(window.main=e.innerHTML),document.getElementById("suggestions")),n=t.cloneNode(!0),o=(n.id="results",document.createElement("div")),i='

Results For: '.concat(document.getElementById("searchinput").value,"

");return o.innerHTML=i,n.insertBefore(o,n.firstChild),e.innerHTML=n.outerHTML,t.innerHTML="",document.getElementById("searchinput").value="",document.body.contains(document.closeSearch)&&(document.closeSearch.onsubmit=function(){document.querySelector("main").innerHTML=window.main}),!1})},!function(){for(var e=document.getElementsByClassName("m-protected"),t=0;t{e.classList.add(t),setTimeout(()=>e.classList.remove(t),2500)}),copyCodeAndChangeIcon=async(t,e)=>{e=(e.querySelector("table")?getTableCode:getNonTableCode)(e);try{await navigator.clipboard.writeText(e),changeIcon(t,"yes")}catch(e){changeIcon(t,"err")}},getNonTableCode=e=>[...e.querySelectorAll("code")].map(e=>e.textContent).join(""),getTableCode=e=>[...e.querySelectorAll("tr")].map(e=>e.querySelector("td:last-child")?.innerText??"").join("");document.querySelectorAll("pre").forEach(e=>{const t=document.createElement("div");t.className="cc svgs svgh copy",t.innerHTML=" ",e.prepend(t),t.addEventListener("click",()=>copyCodeAndChangeIcon(t,e))}); \ No newline at end of file +const items=document.querySelectorAll(".preStyle"),changeIcon=(items.forEach(e=>{e.rel="stylesheet"}),document.getElementById("mode")&&document.getElementById("mode").addEventListener("click",()=>{document.documentElement.classList.toggle("switch"),localStorage.setItem("theme",document.documentElement.classList.contains("switch")?"switch":"default")}),!function(){function g(e){var t=new g.Index;return t.pipeline.add(g.trimmer,g.stopWordFilter,g.stemmer),e&&e.call(t,t),t}var a,c,e,t,d,h,f,p,m,v,y,S,x,w,b,I,E,C,D,F,k,L,_,N,n;g.version="0.9.5",((lunr=g).utils={}).warn=(n=this,function(e){n.console&&console.warn&&console.warn(e)}),g.utils.toString=function(e){return null==e?"":e.toString()},(g.EventEmitter=function(){this.events={}}).prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop();if("function"!=typeof t)throw new TypeError("last argument must be a function");e.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},g.EventEmitter.prototype.removeListener=function(e,t){this.hasHandler(e)&&-1!==(t=this.events[e].indexOf(t))&&(this.events[e].splice(t,1),0==this.events[e].length)&&delete this.events[e]},g.EventEmitter.prototype.emit=function(e){var t;this.hasHandler(e)&&(t=Array.prototype.slice.call(arguments,1),this.events[e].forEach(function(e){e.apply(void 0,t)},this))},g.EventEmitter.prototype.hasHandler=function(e){return e in this.events},(g.tokenizer=function(e){var t,n;return arguments.length&&null!=e?Array.isArray(e)?(t=(t=e.filter(function(e){return null!=e})).map(function(e){return g.utils.toString(e).toLowerCase()}),n=[],t.forEach(function(e){e=e.split(g.tokenizer.seperator),n=n.concat(e)},this),n):e.toString().trim().toLowerCase().split(g.tokenizer.seperator):[]}).defaultSeperator=/[\s\-]+/,g.tokenizer.seperator=g.tokenizer.defaultSeperator,g.tokenizer.setSeperator=function(e){null!=e&&"object"==typeof e&&(g.tokenizer.seperator=e)},g.tokenizer.resetSeperator=function(){g.tokenizer.seperator=g.tokenizer.defaultSeperator},g.tokenizer.getSeperator=function(){return g.tokenizer.seperator},(g.Pipeline=function(){this._queue=[]}).registeredFunctions={},g.Pipeline.registerFunction=function(e,t){t in g.Pipeline.registeredFunctions&&g.utils.warn("Overwriting existing registered function: "+t),e.label=t,g.Pipeline.registeredFunctions[t]=e},g.Pipeline.getRegisteredFunction=function(e){return e in g.Pipeline.registeredFunctions!=1?null:g.Pipeline.registeredFunctions[e]},g.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions||g.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},g.Pipeline.load=function(e){var n=new g.Pipeline;return e.forEach(function(e){var t=g.Pipeline.getRegisteredFunction(e);if(!t)throw new Error("Cannot load un-registered function: "+e);n.add(t)}),n},g.Pipeline.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(e){g.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},g.Pipeline.prototype.after=function(e,t){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e+1,0,t)},g.Pipeline.prototype.before=function(e,t){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e,0,t)},g.Pipeline.prototype.remove=function(e){-1!==(e=this._queue.indexOf(e))&&this._queue.splice(e,1)},g.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,o=this._queue.length,i=0;iu[o]&&o++:(t.add(s[n]),n++,o++);return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){for(var t,e=this.length>=e.length?(t=this,e):(t=e,this),n=t.clone(),o=0,i=e.toArray();o",a=n.querySelector("a"),t=n.querySelector("span:first-child"),d=n.querySelector("span:nth-child(2)"),a.href=e.ref,t.textContent=e.doc.title,d.innerHTML=function(e){var t=x.map(function(e){return elasticlunr.stemmer(e.toLowerCase())}),n=!1,o=0,i=[],r=e.toLowerCase().split(". ");for(f in r){var s,u=r[f].split(/[\s\n]/),l=8;for(s in u){if(0<(g=u[s]).length){for(var a in t)elasticlunr.stemmer(g).startsWith(t[a])&&(l=40,n=!0);i.push([g,l,o]),l=2}o=o+g.length+1}o+=1}if(0===i.length)return void 0!==e.length&&300"),S=g[2]+g[0].length,40!==g[1]&&12<=g[0].length&&!/^[\x00-\xff]+$/.test(g[0])?(v=function(e){for(var t="",n=!1,o=0,i=0,r=0,s=0;s");return y.push("…"),y.join("")}(e.doc.body),s.appendChild(n))});i.length>r;)s.removeChild(i[0])},!0),s.addEventListener("click",function(){for(;s.lastChild;)s.removeChild(s.lastChild);return!1},!0),document.goSearch.onsubmit=function(){var e=document.querySelector("main"),t=(window.main||(window.main=e.innerHTML),document.getElementById("suggestions")),n=t.cloneNode(!0),o=(n.id="results",document.createElement("div")),i='

Results For: '.concat(document.getElementById("searchinput").value,"

");return o.innerHTML=i,n.insertBefore(o,n.firstChild),e.innerHTML=n.outerHTML,t.innerHTML="",document.getElementById("searchinput").value="",document.body.contains(document.closeSearch)&&(document.closeSearch.onsubmit=function(){document.querySelector("main").innerHTML=window.main}),!1})},!function(){for(var e=document.getElementsByClassName("m-protected"),t=0;t{e.classList.add(t),setTimeout(()=>e.classList.remove(t),2500)}),copyCodeAndChangeIcon=async(t,e)=>{e=(e.querySelector("table")?getTableCode:getNonTableCode)(e);try{await navigator.clipboard.writeText(e),changeIcon(t,"yes")}catch(e){changeIcon(t,"err")}},getNonTableCode=e=>[...e.querySelectorAll("code")].map(e=>e.textContent).join(""),getTableCode=e=>[...e.querySelectorAll("tr")].map(e=>e.querySelector("td:last-child")?.innerText??"").join("");document.querySelectorAll("pre").forEach(e=>{const t=document.createElement("div");t.className="cc svgs svgh copy",t.innerHTML=" ",e.prepend(t),t.addEventListener("click",()=>copyCodeAndChangeIcon(t,e))}); \ No newline at end of file diff --git a/static/js/theme.js b/static/js/theme.js index 5f6f0f6..ec10638 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -1,4 +1,4 @@ // enforce local storage setting but also fallback to user-agent preferences -if (localStorage.getItem('theme') === 'light' || (!localStorage.getItem('theme') && !window.matchMedia("(prefers-color-scheme: dark)").matches)) { - document.documentElement.classList.add('light'); +if (localStorage.getItem('theme') === 'switch' || (!localStorage.getItem('theme') && !window.matchMedia("(prefers-color-scheme: dark)").matches)) { + document.documentElement.classList.add('switch'); } diff --git a/static/js/theme.min.js b/static/js/theme.min.js index 612895e..8804552 100644 --- a/static/js/theme.min.js +++ b/static/js/theme.min.js @@ -1 +1 @@ -"light"!==localStorage.getItem("theme")&&(localStorage.getItem("theme")||window.matchMedia("(prefers-color-scheme: dark)").matches)||document.documentElement.classList.add("light"); \ No newline at end of file +"switch"!==localStorage.getItem("theme")&&(localStorage.getItem("theme")||window.matchMedia("(prefers-color-scheme: dark)").matches)||document.documentElement.classList.add("switch"); \ No newline at end of file diff --git a/static/js/theme_button.js b/static/js/theme_button.js index 34d1d78..b03f17f 100644 --- a/static/js/theme_button.js +++ b/static/js/theme_button.js @@ -1,7 +1,7 @@ // Set lightmode if (document.getElementById('mode')) { document.getElementById('mode').addEventListener('click', () => { - document.documentElement.classList.toggle('light'); - localStorage.setItem('theme', document.documentElement.classList.contains('light') ? 'light' : 'dark'); + document.documentElement.classList.toggle('switch'); + localStorage.setItem('theme', document.documentElement.classList.contains('switch') ? 'switch' : 'default'); }); } diff --git a/static/js/theme_light.js b/static/js/theme_light.js new file mode 100644 index 0000000..cea48ac --- /dev/null +++ b/static/js/theme_light.js @@ -0,0 +1,4 @@ +// enforce local storage setting but also fallback to user-agent preferences +if (localStorage.getItem('theme') === 'switch' || (!localStorage.getItem('theme') && !window.matchMedia("(prefers-color-scheme: light)").matches)) { + document.documentElement.classList.add('switch'); +} diff --git a/static/js/theme_light.min.js b/static/js/theme_light.min.js new file mode 100644 index 0000000..fca2f11 --- /dev/null +++ b/static/js/theme_light.min.js @@ -0,0 +1 @@ +"switch"!==localStorage.getItem("theme")&&(localStorage.getItem("theme")||window.matchMedia("(prefers-color-scheme: light)").matches)||document.documentElement.classList.add("switch"); \ No newline at end of file diff --git a/templates/macros/head.html b/templates/macros/head.html index 6bc0275..25e981d 100644 --- a/templates/macros/head.html +++ b/templates/macros/head.html @@ -1,8 +1,13 @@ {#- Theme Switcher Button to toggle between dark/light #} {%- macro theme(config) %} {%- if config.extra.js_switcher | default(value=true) %} - {%- set js_theme=config.extra.js_theme | default(value="js/theme.min.js") -%} - {%- if js_theme %} + {%- set js_theme=config.extra.js_theme | default(value="") -%} + {%- if not js_theme %} + {%- if config.extra.js_switcher_default %}{%- if config.extra.js_switcher_default == "light" %} + {%- set js_theme="js/theme_light.min.js" -%} + {%- else %} + {%- set js_theme="js/theme.min.js" -%} + {%- endif %}{%- endif %} {%- endif %} {%- endif %} -- cgit v1.3.1