From 02c3891865c7741b8f772aea75cc01564d2f0ff4 Mon Sep 17 00:00:00 2001 From: amzrk2 Date: Mon, 1 Jun 2020 15:44:04 +0800 Subject: Remove jQuery --- static/assets/js/fuji.js | 127 --------------------------------------- static/assets/js/fuji.min.js | 2 + static/assets/js/fuji.min.js.map | 1 + 3 files changed, 3 insertions(+), 127 deletions(-) delete mode 100644 static/assets/js/fuji.js create mode 100644 static/assets/js/fuji.min.js create mode 100644 static/assets/js/fuji.min.js.map (limited to 'static/assets/js') diff --git a/static/assets/js/fuji.js b/static/assets/js/fuji.js deleted file mode 100644 index 0a81db2..0000000 --- a/static/assets/js/fuji.js +++ /dev/null @@ -1,127 +0,0 @@ -'use strict'; - -// toggle theme -function toggleTheme() { - $('body').attr('data-theme', (index, attr) => { - if (attr === 'light') { - localStorage.setItem('fuji_theme', 'dark'); - return 'dark'; - } else { - localStorage.setItem('fuji_theme', 'light'); - return 'light'; - } - }); -} - -// update medium-zoom theme -// @params targetTheme, mediumInst -function updateMeidumTheme(targetTheme, mediumInst) { - if (targetTheme && mediumInst) { - mediumInst.detach(); - if (targetTheme === 'dark') { - mediumInst = mediumZoom('.img-zoomable', { - background: '#2f3136', - }); - } else { - mediumInst = mediumZoom('.img-zoomable', { - background: '#fffffd', - }); - } - } -} - -// update utterances theme -// @params targetTheme, utterancesFrame -function updateUtterancesTheme(targetTheme, utterancesFrame) { - if (targetTheme && 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' - ); - } - } -} - -// to-top button -$('.btn .btn-scroll-top').on('click', () => { - $('html, body').animate({ - scrollTop: 0, - }); -}); - -// toc anchors -$('.sidebar-toc a').on('click', (event) => { - $('html, body').animate({ - scrollTop: $($(event.currentTarget).attr('href')).offset().top, - }); -}); - -// remove empty ul in toc if article only have ## and ### -if ($('.sidebar-toc ul ul').length > 0 && $('.sidebar-toc ul ul li').text() === '') { - $('.sidebar-toc ul ul').hide(); -} - -// init medium-zoom -var mediumInst; // medium-zoom instance -if ($('body').attr('data-theme') === 'dark') { - mediumInst = mediumZoom('.img-zoomable', { - background: '#2f3136', - }); -} else { - mediumInst = mediumZoom('.img-zoomable', { - background: '#fffffd', - }); -} - -// if in post page and using utterances -// add utterances comment loading indicator -if ($('.post-loading').length >= 1) { - var commentStatus; // utterence status - var commentLoadingTime = 0; // loading time passed - var commentCheckInterval = self.setInterval(checkUtterances, 500); - - function checkUtterances() { - commentStatus = $('.post-comment .utterances').attr('style'); - if (commentStatus) { - clearInterval(commentCheckInterval); - updateUtterancesTheme($('body').attr('data-theme'), $('.post-comment iframe')[0]); - $('.post-loading').hide(); - } else { - if (++commentLoadingTime > 20) { - clearInterval(commentCheckInterval); - $('.post-comment').hide(); - $('.post-loading i').attr('class', 'far fa-times-circle'); - } - } - } -} - -// init theme switch button -$('.btn .btn-toggle-mode').on('click', () => { - // toggle theme - toggleTheme(); - // update medium background - updateMeidumTheme($('body').attr('data-theme'), mediumInst); - // switch comment area theme - // only works after comment area are initialized - if ($('.post-loading').length >= 1 && commentStatus) { - updateUtterancesTheme($('body').attr('data-theme'), $('.post-comment iframe')[0]); - } - if ($('#disqus_thread').length >= 1 && typeof DISQUS !== 'undefined') { - DISQUS.reset({ - reload: true, - }); - } -}); diff --git a/static/assets/js/fuji.min.js b/static/assets/js/fuji.min.js new file mode 100644 index 0000000..474d550 --- /dev/null +++ b/static/assets/js/fuji.min.js @@ -0,0 +1,2 @@ +"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,checkUtterances,commentStatus,commentLoadingTime,commentCheckInterval;0 0) {\r\n document.querySelectorAll('.sidebar-toc ul ul').forEach((value, key, parent) => {\r\n value.setAttribute('style', 'display: none;');\r\n });\r\n}\r\n\r\n// to-top button\r\ndocument.querySelector('.btn .btn-scroll-top').addEventListener('click', () => {\r\n document.documentElement.scrollTop = 0;\r\n});\r\n\r\n// init medium-zoom\r\nvar mediumInst; // medium-zoom instance\r\nif (getNowTheme() === 'dark') {\r\n mediumInst = mediumZoom('.img-zoomable', {\r\n background: '#2f3136',\r\n });\r\n} else {\r\n mediumInst = mediumZoom('.img-zoomable', {\r\n background: '#fffffd',\r\n });\r\n}\r\n\r\n// if in post page and using utterances\r\n// add utterances comment loading indicator\r\nif (document.querySelector('.post-loading')) {\r\n var commentStatus; // utterence status\r\n var commentLoadingTime = 0; // loading time passed\r\n var commentCheckInterval = self.setInterval(checkUtterances, 500);\r\n\r\n function checkUtterances() {\r\n if (document.querySelector('.post-comment .utterances')) {\r\n commentStatus = document.querySelector('.post-comment .utterances').getAttribute('style');\r\n }\r\n if (commentStatus) {\r\n clearInterval(commentCheckInterval);\r\n updateUtterancesTheme(document.querySelector('.post-comment iframe'));\r\n document.querySelector('.post-loading').setAttribute('style', 'display: none;');\r\n } else {\r\n if (++commentLoadingTime > 20) {\r\n clearInterval(commentCheckInterval);\r\n document.querySelector('.post-comment').setAttribute('style', 'display: none;');\r\n document.querySelector('.post-loading i').className = 'far fa-times-circle';\r\n }\r\n }\r\n }\r\n}\r\n\r\n// theme switch button\r\ndocument.querySelector('.btn .btn-toggle-mode').addEventListener('click', () => {\r\n let nowTheme = getNowTheme();\r\n let domTheme = document.body.getAttribute('data-theme');\r\n let systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\r\n\r\n if (domTheme === 'auto') {\r\n // if now in auto mode, switch to user mode\r\n document.body.setAttribute('data-theme', nowTheme === 'light' ? 'dark' : 'light');\r\n localStorage.setItem('fuji_data-theme', nowTheme === 'light' ? 'dark' : 'light');\r\n } else if (domTheme === 'light') {\r\n // if now in user mode and light mode\r\n document.body.setAttribute('data-theme', 'dark');\r\n // if the theme want to switch is system theme\r\n localStorage.setItem('fuji_data-theme', systemTheme === 'dark' ? 'auto' : 'dark');\r\n } else {\r\n // if now in user mode and dark mode\r\n document.body.setAttribute('data-theme', 'light');\r\n // if the theme want to switch is system theme\r\n localStorage.setItem('fuji_data-theme', systemTheme === 'light' ? 'auto' : 'light');\r\n }\r\n\r\n // update medium background\r\n updateMeidumTheme(mediumInst);\r\n // switch comment area theme\r\n // only works after comment area are initialized\r\n if (document.querySelector('.post-loading') && commentStatus) {\r\n updateUtterancesTheme(document.querySelector('.post-comment iframe'));\r\n }\r\n if (document.querySelector('#disqus_thread') && typeof DISQUS !== 'undefined') {\r\n DISQUS.reset({\r\n reload: true,\r\n });\r\n }\r\n});\r\n"]} \ No newline at end of file -- cgit v1.2.3