From 89fc2917985d3da944af8116e101748267d66104 Mon Sep 17 00:00:00 2001 From: amzrk2 Date: Sun, 14 Jun 2020 23:17:37 +0800 Subject: Remove medium-zoom --- static/assets/js/fuji.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'static/assets/js/fuji.min.js') diff --git a/static/assets/js/fuji.min.js b/static/assets/js/fuji.min.js index 90c27a6..b3940da 100644 --- a/static/assets/js/fuji.min.js +++ b/static/assets/js/fuji.min.js @@ -1 +1 @@ -"use strict";function getNowTheme(){var e=document.body.getAttribute("data-theme");return"auto"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===e?"dark":"light"}function updateMeidumTheme(e){var t=getNowTheme();e&&(e.detach(),e="dark"===t?mediumZoom(".img-zoomable",{background:"#2f3136"}):mediumZoom(".img-zoomable",{background:"#fffffd"}))}function updateUtterancesTheme(e){var t=getNowTheme();e&&("dark"===t?e.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):e.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}var mediumInst;document.querySelector("span.post-comment-notloaded")&&document.querySelector("span.post-comment-notloaded").addEventListener("click",loadComment),document.querySelector(".btn .btn-scroll-top").addEventListener("click",function(){document.documentElement.scrollTop=0}),mediumInst="dark"===getNowTheme()?mediumZoom(".img-zoomable",{background:"#2f3136"}):mediumZoom(".img-zoomable",{background:"#fffffd"}),document.querySelector(".btn .btn-toggle-mode").addEventListener("click",function(){var e=getNowTheme(),t=document.body.getAttribute("data-theme"),o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";"auto"===t?(document.body.setAttribute("data-theme","light"===e?"dark":"light"),localStorage.setItem("fuji_data-theme","light"===e?"dark":"light")):"light"===t?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("fuji_data-theme","dark"==o?"auto":"dark")):(document.body.setAttribute("data-theme","light"),localStorage.setItem("fuji_data-theme","light"==o?"auto":"light")),updateMeidumTheme(mediumInst);var m=document.querySelector(".post-comment");m&&document.querySelector("span.post-comment-notloaded").getAttribute("style")&&("utterances"===m.getAttribute("data-comment")&&updateUtterancesTheme(document.querySelector(".post-comment iframe")),"disqus"===m.getAttribute("data-comment")&&DISQUS.reset({reload:!0}))}); \ No newline at end of file +"use strict";function getNowTheme(){var t=document.body.getAttribute("data-theme");return"auto"===t?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===t?"dark":"light"}function updateUtterancesTheme(t){var e=getNowTheme();t&&("dark"===e?t.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):t.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}document.querySelector("span.post-comment-notloaded")&&document.querySelector("span.post-comment-notloaded").addEventListener("click",loadComment),document.querySelector(".btn .btn-scroll-top").addEventListener("click",function(){document.documentElement.scrollTop=0}),document.querySelector(".btn .btn-toggle-mode").addEventListener("click",function(){var t=getNowTheme(),e=document.body.getAttribute("data-theme"),o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";"auto"===e?(document.body.setAttribute("data-theme","light"===t?"dark":"light"),localStorage.setItem("fuji_data-theme","light"===t?"dark":"light")):"light"===e?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("fuji_data-theme","dark"==o?"auto":"dark")):(document.body.setAttribute("data-theme","light"),localStorage.setItem("fuji_data-theme","light"==o?"auto":"light"));var a=document.querySelector(".post-comment");a&&document.querySelector("span.post-comment-notloaded").getAttribute("style")&&("utterances"===a.getAttribute("data-comment")&&updateUtterancesTheme(document.querySelector(".post-comment iframe")),"disqus"===a.getAttribute("data-comment")&&DISQUS.reset({reload:!0}))}); \ No newline at end of file -- cgit v1.2.3 From a3376d1ad133455b73ca893e222c1aec89ae6d44 Mon Sep 17 00:00:00 2001 From: amzrk2 Date: Mon, 15 Jun 2020 23:50:54 +0800 Subject: Update searching based on Fuse.js --- static/assets/js/fuji.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'static/assets/js/fuji.min.js') diff --git a/static/assets/js/fuji.min.js b/static/assets/js/fuji.min.js index b3940da..c21a20f 100644 --- a/static/assets/js/fuji.min.js +++ b/static/assets/js/fuji.min.js @@ -1 +1 @@ -"use strict";function getNowTheme(){var t=document.body.getAttribute("data-theme");return"auto"===t?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===t?"dark":"light"}function updateUtterancesTheme(t){var e=getNowTheme();t&&("dark"===e?t.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):t.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}document.querySelector("span.post-comment-notloaded")&&document.querySelector("span.post-comment-notloaded").addEventListener("click",loadComment),document.querySelector(".btn .btn-scroll-top").addEventListener("click",function(){document.documentElement.scrollTop=0}),document.querySelector(".btn .btn-toggle-mode").addEventListener("click",function(){var t=getNowTheme(),e=document.body.getAttribute("data-theme"),o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";"auto"===e?(document.body.setAttribute("data-theme","light"===t?"dark":"light"),localStorage.setItem("fuji_data-theme","light"===t?"dark":"light")):"light"===e?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("fuji_data-theme","dark"==o?"auto":"dark")):(document.body.setAttribute("data-theme","light"),localStorage.setItem("fuji_data-theme","light"==o?"auto":"light"));var a=document.querySelector(".post-comment");a&&document.querySelector("span.post-comment-notloaded").getAttribute("style")&&("utterances"===a.getAttribute("data-comment")&&updateUtterancesTheme(document.querySelector(".post-comment iframe")),"disqus"===a.getAttribute("data-comment")&&DISQUS.reset({reload:!0}))}); \ No newline at end of file +"use strict";function getNowTheme(){var e=document.body.getAttribute("data-theme");return"auto"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===e?"dark":"light"}function updateUtterancesTheme(e){var t=getNowTheme();e&&("dark"===t?e.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):e.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}function searchAll(e,t){var o=new Fuse(t,{keys:["title","tags"]}).search(e);console.log(o),0NOT FOUND"}document.querySelector("span.post-comment-notloaded")&&document.querySelector("span.post-comment-notloaded").addEventListener("click",loadComment),document.querySelector(".btn .btn-scroll-top").addEventListener("click",function(){document.documentElement.scrollTop=0}),document.querySelector(".btn .btn-toggle-mode").addEventListener("click",function(){var e=getNowTheme(),t=document.body.getAttribute("data-theme"),o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";"auto"===t?(document.body.setAttribute("data-theme","light"===e?"dark":"light"),localStorage.setItem("fuji_data-theme","light"===e?"dark":"light")):"light"===t?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("fuji_data-theme","dark"==o?"auto":"dark")):(document.body.setAttribute("data-theme","light"),localStorage.setItem("fuji_data-theme","light"==o?"auto":"light"));var r=document.querySelector(".post-comment");r&&document.querySelector("span.post-comment-notloaded").getAttribute("style")&&("utterances"===r.getAttribute("data-comment")&&updateUtterancesTheme(document.querySelector(".post-comment iframe")),"disqus"===r.getAttribute("data-comment")&&DISQUS.reset({reload:!0}))});var key,xhr,urlParams=new URLSearchParams(window.location.search);urlParams.has("s")&&(key=urlParams.get("s"),document.querySelector(".search-input input").setAttribute("value",key),(xhr=new XMLHttpRequest).open("GET","/index.json",!0),xhr.responseType="json",xhr.onerror=function(e){console.error("".concat(xhr.status," ").concat(xhr.statusText))},xhr.onload=function(){4===xhr.readyState&&(200===xhr.status?(console.log(xhr.response),searchAll(key,xhr.response)):console.error("".concat(xhr.status," ").concat(xhr.statusText)))},xhr.send(null)); \ No newline at end of file -- cgit v1.2.3 From c42924047c6f654c4723746790e041f8907ed378 Mon Sep 17 00:00:00 2001 From: amzrk2 Date: Tue, 16 Jun 2020 14:00:53 +0800 Subject: Searching now works --- static/assets/js/fuji.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'static/assets/js/fuji.min.js') diff --git a/static/assets/js/fuji.min.js b/static/assets/js/fuji.min.js index 6044b49..79d66c5 100644 --- a/static/assets/js/fuji.min.js +++ b/static/assets/js/fuji.min.js @@ -1 +1 @@ -"use strict";function getNowTheme(){var e=document.body.getAttribute("data-theme");return"auto"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===e?"dark":"light"}function updateUtterancesTheme(e){var t=getNowTheme();e&&("dark"===t?e.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):e.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}function searchAll(e,t){var o=new Fuse(t,{keys:["title","tags"]}).search(e);console.log(o),0NOT FOUND"}document.querySelector("span.post-comment-notloaded")&&document.querySelector("span.post-comment-notloaded").addEventListener("click",loadComment),document.querySelector(".btn .btn-scroll-top").addEventListener("click",function(){document.documentElement.scrollTop=0}),document.querySelector(".btn .btn-toggle-mode").addEventListener("click",function(){var e=getNowTheme(),t=document.body.getAttribute("data-theme"),o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";"auto"===t?(document.body.setAttribute("data-theme","light"===e?"dark":"light"),localStorage.setItem("fuji_data-theme","light"===e?"dark":"light")):"light"===t?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("fuji_data-theme","dark"==o?"auto":"dark")):(document.body.setAttribute("data-theme","light"),localStorage.setItem("fuji_data-theme","light"==o?"auto":"light"));var r=document.querySelector(".post-comment");r&&document.querySelector("span.post-comment-notloaded").getAttribute("style")&&("utterances"===r.getAttribute("data-comment")&&updateUtterancesTheme(document.querySelector(".post-comment iframe")),"disqus"===r.getAttribute("data-comment")&&DISQUS.reset({reload:!0}))});var key,xhr,urlParams=new URLSearchParams(window.location.search);urlParams.has("s")&&(key=urlParams.get("s"),document.querySelector(".search-input input").setAttribute("value",key),(xhr=new XMLHttpRequest).open("GET","/index.json",!0),xhr.responseType="json",xhr.onerror=function(e){console.error("".concat(xhr.status," ").concat(xhr.statusText))},xhr.onload=function(){4===xhr.readyState&&(200===xhr.status?(console.log(xhr.response),searchAll(key,xhr.response)):console.error("".concat(xhr.status," ").concat(xhr.statusText)))},xhr.send(null)); \ No newline at end of file +"use strict";function getNowTheme(){var e=document.body.getAttribute("data-theme");return"auto"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===e?"dark":"light"}function updateUtterancesTheme(e){var t=getNowTheme();e&&("dark"===t?e.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):e.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}function searchAll(e,t,n){var o=new Fuse(t,{shouldSort:!0,distance:1e4,keys:[{name:"title",weight:2},{name:"tags",weight:1.5},{name:"content",weight:1}]}).search(e);return console.log(o),0 0) { + document.getElementById('search-result').innerHTML = template('search-result-template', result); + return [new Date().getTime() - counter, result.length]; + } else { + return 'notFound'; + } +} + +var urlParams = new URLSearchParams(window.location.search); // get params from URL + +if (urlParams.has('s')) { + var counter = new Date().getTime(); + var infoElements = document.querySelectorAll('.search-result-info'); + var key = urlParams.get('s'); // get search keyword, divided by space + + document.querySelector('.search-input input').setAttribute('value', key); // get search index from json + + var xhr = new XMLHttpRequest(); + xhr.open('GET', '/index.json', true); + xhr.responseType = 'json'; + + xhr.onerror = function (e) { + infoElements[2].removeAttribute('style'); + }; + + xhr.onload = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + // use index json to search + console.log(xhr.response); + counter = searchAll(key, xhr.response, counter); + console.log(counter); + + if (counter === 'notFound') { + infoElements[1].removeAttribute('style'); + } else { + infoElements[0].innerHTML = infoElements[0].innerHTML.replace('[TIME]', counter[0]); + infoElements[0].innerHTML = infoElements[0].innerHTML.replace('[NUM]', counter[1]); + infoElements[0].removeAttribute('style'); + } + } else { + console.error("Failed to get index.json, ".concat(xhr.status, " ").concat(xhr.statusText)); + infoElements[2].removeAttribute('style'); + } + } + }; + + xhr.send(null); +} +//# sourceMappingURL=fuji.min.js.map -- cgit v1.2.3 From f88c7b78f224bf746b831001ec8cef01693a4b3c Mon Sep 17 00:00:00 2001 From: amzrk2 Date: Tue, 16 Jun 2020 16:09:04 +0800 Subject: Search page i18n --- static/assets/js/fuji.min.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'static/assets/js/fuji.min.js') diff --git a/static/assets/js/fuji.min.js b/static/assets/js/fuji.min.js index 295ee61..6b0646d 100644 --- a/static/assets/js/fuji.min.js +++ b/static/assets/js/fuji.min.js @@ -95,8 +95,7 @@ function searchAll(key, index, counter) { weight: 1.0 }] }); - var result = fuse.search(key); - console.log(result); + var result = fuse.search(key); // console.log(result); if (result.length > 0) { document.getElementById('search-result').innerHTML = template('search-result-template', result); @@ -119,17 +118,20 @@ if (urlParams.has('s')) { xhr.open('GET', '/index.json', true); xhr.responseType = 'json'; - xhr.onerror = function (e) { + xhr.onerror = function () { infoElements[2].removeAttribute('style'); }; - xhr.onload = function () { + xhr.ontimeout = function () { + infoElements[2].removeAttribute('style'); + }; + + xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { // use index json to search - console.log(xhr.response); - counter = searchAll(key, xhr.response, counter); - console.log(counter); + // console.log(xhr.response); + counter = searchAll(key, xhr.response, counter); // console.log(counter); if (counter === 'notFound') { infoElements[1].removeAttribute('style'); @@ -139,7 +141,6 @@ if (urlParams.has('s')) { infoElements[0].removeAttribute('style'); } } else { - console.error("Failed to get index.json, ".concat(xhr.status, " ").concat(xhr.statusText)); infoElements[2].removeAttribute('style'); } } -- cgit v1.2.3 From 05dcb6fec60a71e7d88d86e6d1a0189abc01a9e7 Mon Sep 17 00:00:00 2001 From: amzrk2 Date: Tue, 16 Jun 2020 16:30:56 +0800 Subject: Clean resources --- static/assets/js/fuji.min.js | 152 +------------------------------------------ 1 file changed, 1 insertion(+), 151 deletions(-) (limited to 'static/assets/js/fuji.min.js') diff --git a/static/assets/js/fuji.min.js b/static/assets/js/fuji.min.js index 6b0646d..d7e8d68 100644 --- a/static/assets/js/fuji.min.js +++ b/static/assets/js/fuji.min.js @@ -1,151 +1 @@ -'use strict'; // get current theme - -function getNowTheme() { - var nowTheme = document.body.getAttribute('data-theme'); - - if (nowTheme === 'auto') { - return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; - } else { - return nowTheme === 'dark' ? 'dark' : 'light'; - } -} // update utterances theme - - -function updateUtterancesTheme(utterancesFrame) { - var targetTheme = getNowTheme(); - - if (utterancesFrame) { - if (targetTheme === 'dark') { - utterancesFrame.contentWindow.postMessage({ - type: 'set-theme', - theme: 'photon-dark' - }, 'https://utteranc.es'); - } else { - utterancesFrame.contentWindow.postMessage({ - type: 'set-theme', - theme: 'github-light' - }, 'https://utteranc.es'); - } - } -} // load comment button only when comment area exist - - -if (document.querySelector('span.post-comment-notloaded')) { - document.querySelector('span.post-comment-notloaded').addEventListener('click', loadComment); -} // to-top button - - -document.querySelector('.btn .btn-scroll-top').addEventListener('click', function () { - document.documentElement.scrollTop = 0; -}); // theme switch button - -document.querySelector('.btn .btn-toggle-mode').addEventListener('click', function () { - var nowTheme = getNowTheme(); - var domTheme = document.body.getAttribute('data-theme'); - var systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; - - if (domTheme === 'auto') { - // if now in auto mode, switch to user mode - document.body.setAttribute('data-theme', nowTheme === 'light' ? 'dark' : 'light'); - localStorage.setItem('fuji_data-theme', nowTheme === 'light' ? 'dark' : 'light'); - } else if (domTheme === 'light') { - // if now in user mode and light mode - document.body.setAttribute('data-theme', 'dark'); // if the theme want to switch is system theme - - localStorage.setItem('fuji_data-theme', systemTheme === 'dark' ? 'auto' : 'dark'); - } else { - // if now in user mode and dark mode - document.body.setAttribute('data-theme', 'light'); // if the theme want to switch is system theme - - localStorage.setItem('fuji_data-theme', systemTheme === 'light' ? 'auto' : 'light'); - } // switch comment area theme - // if this page has comment area - - - var commentArea = document.querySelector('.post-comment'); - - if (commentArea) { - // if comment area loaded - if (document.querySelector('span.post-comment-notloaded').getAttribute('style')) { - if (commentArea.getAttribute('data-comment') === 'utterances') { - updateUtterancesTheme(document.querySelector('.post-comment iframe')); - } - - if (commentArea.getAttribute('data-comment') === 'disqus') { - DISQUS.reset({ - reload: true - }); - } - } - } -}); // search by fuse.js - -function searchAll(key, index, counter) { - var fuse = new Fuse(index, { - shouldSort: true, - distance: 10000, - keys: [{ - name: 'title', - weight: 2.0 - }, { - name: 'tags', - weight: 1.5 - }, { - name: 'content', - weight: 1.0 - }] - }); - var result = fuse.search(key); // console.log(result); - - if (result.length > 0) { - document.getElementById('search-result').innerHTML = template('search-result-template', result); - return [new Date().getTime() - counter, result.length]; - } else { - return 'notFound'; - } -} - -var urlParams = new URLSearchParams(window.location.search); // get params from URL - -if (urlParams.has('s')) { - var counter = new Date().getTime(); - var infoElements = document.querySelectorAll('.search-result-info'); - var key = urlParams.get('s'); // get search keyword, divided by space - - document.querySelector('.search-input input').setAttribute('value', key); // get search index from json - - var xhr = new XMLHttpRequest(); - xhr.open('GET', '/index.json', true); - xhr.responseType = 'json'; - - xhr.onerror = function () { - infoElements[2].removeAttribute('style'); - }; - - xhr.ontimeout = function () { - infoElements[2].removeAttribute('style'); - }; - - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - // use index json to search - // console.log(xhr.response); - counter = searchAll(key, xhr.response, counter); // console.log(counter); - - if (counter === 'notFound') { - infoElements[1].removeAttribute('style'); - } else { - infoElements[0].innerHTML = infoElements[0].innerHTML.replace('[TIME]', counter[0]); - infoElements[0].innerHTML = infoElements[0].innerHTML.replace('[NUM]', counter[1]); - infoElements[0].removeAttribute('style'); - } - } else { - infoElements[2].removeAttribute('style'); - } - } - }; - - xhr.send(null); -} -//# sourceMappingURL=fuji.min.js.map +"use strict";function getNowTheme(){var e=document.body.getAttribute("data-theme");return"auto"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===e?"dark":"light"}function updateUtterancesTheme(e){var t=getNowTheme();e&&("dark"===t?e.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):e.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}function searchAll(e,t,n){var o=new Fuse(t,{shouldSort:!0,distance:1e4,keys:[{name:"title",weight:2},{name:"tags",weight:1.5},{name:"content",weight:1}]}).search(e);return 0