diff --git a/app/asset/app.js b/app/asset/app.js index c2fbb496..31f572aa 100644 --- a/app/asset/app.js +++ b/app/asset/app.js @@ -4,38 +4,38 @@ */ /* Color schemes, mobile, panel */ const setup = () => { - const getTheme = () => { - if (window.localStorage.getItem('dark')) { - return JSON.parse(window.localStorage.getItem('dark')) - } - - return !!window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches - } - - const setTheme = (value) => { - window.localStorage.setItem('dark', value) - } - - const getColor = () => { - if (window.localStorage.getItem('color')) { - return window.localStorage.getItem('color') - } - return 'blue' - } - - const setColors = (color) => { - const root = document.documentElement - root.style.setProperty('--color-primary', `var(--color-${color})`) - root.style.setProperty('--color-primary-50', `var(--color-${color}-50)`) - root.style.setProperty('--color-primary-100', `var(--color-${color}-100)`) - root.style.setProperty('--color-primary-light', `var(--color-${color}-light)`) - root.style.setProperty('--color-primary-lighter', `var(--color-${color}-lighter)`) - root.style.setProperty('--color-primary-dark', `var(--color-${color}-dark)`) - root.style.setProperty('--color-primary-darker', `var(--color-${color}-darker)`) - this.selectedColor = color - window.localStorage.setItem('color', color) - } - return { + const getTheme = () => { + if (window.localStorage.getItem('dark')) { + return JSON.parse(window.localStorage.getItem('dark')) + } + + return !!window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches + } + + const setTheme = (value) => { + window.localStorage.setItem('dark', value) + } + + const getColor = () => { + if (window.localStorage.getItem('color')) { + return window.localStorage.getItem('color') + } + return 'blue' + } + + const setColors = (color) => { + const root = document.documentElement + root.style.setProperty('--color-primary', `var(--color-${color})`) + root.style.setProperty('--color-primary-50', `var(--color-${color}-50)`) + root.style.setProperty('--color-primary-100', `var(--color-${color}-100)`) + root.style.setProperty('--color-primary-light', `var(--color-${color}-light)`) + root.style.setProperty('--color-primary-lighter', `var(--color-${color}-lighter)`) + root.style.setProperty('--color-primary-dark', `var(--color-${color}-dark)`) + root.style.setProperty('--color-primary-darker', `var(--color-${color}-darker)`) + this.selectedColor = color + window.localStorage.setItem('color', color) + } + return { loading: true, isDark: getTheme(), toggleTheme() { @@ -80,13 +80,9 @@ const setup = () => { this.$nextTick(() => { this.$refs.mobileMainMenu.focus()}) } - } + } } -/* global LinkPreviewer */ -const linkPreviewer = new LinkPreviewer(); -linkPreviewer.attach('td a.preview'); - /* Search palette */ document.addEventListener('alpine:init', () => { Alpine.data('spotlight', () => ({ @@ -202,6 +198,7 @@ document.addEventListener('alpine:init', () => { hiding the address bar for security reasons (phishing) */ function openWithSelfMain(url, title, w, h) { + e.preventDefault(); // Fixes dual-screen position Most browsers Firefox var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX; var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY; @@ -222,6 +219,10 @@ function openWithSelfMain(url, title, w, h) { } } +/* global LinkPreviewer */ +const linkPreviewer = new LinkPreviewer(); +linkPreviewer.attach('td a.preview'); + /* GitHub Fetch Repo Commits */ function commitsData() { return { @@ -267,5 +268,5 @@ function commitsData() { }; } /*! fetch */ -var _htmlToElements=function(e){var t=document.createElement("template");t.innerHTML=e;const n=t.content.childNodes,o=[],a=[];for(var d in n)1==n[d].nodeType&&("SCRIPT"===n[d].nodeName?a.push(n[d]):o.push(n[d]));return o.concat(a)},_loadContent=function(e,t,n,o){if(0!==t||o||(document.querySelector(n).innerHTML=""),!(t<=e.length))return!0;var a=e[t];if(void 0!==a&&"SCRIPT"===a.nodeName){var d=document.createElement("script");a.type&&(d.type=a.type),Array.prototype.forEach.call(a.attributes,(function(e){d.setAttribute(e.nodeName,e.nodeValue)})),""!=a.src?(d.src=a.src,d.onload=function(){_loadContent(e,t+1,n)},document.head.appendChild(d)):(d.text=a.text,document.body.appendChild(d),_loadContent(e,t+1,n))}else void 0!==a&&document.querySelector(n).appendChild(a),_loadContent(e,t+1,n)},loadData=async function(e,t,n=!1){return _loadContent(_htmlToElements(e),0,t,n)}; +// var _htmlToElements=function(e){var t=document.createElement("template");t.innerHTML=e;const n=t.content.childNodes,o=[],a=[];for(var d in n)1==n[d].nodeType&&("SCRIPT"===n[d].nodeName?a.push(n[d]):o.push(n[d]));return o.concat(a)},_loadContent=function(e,t,n,o){if(0!==t||o||(document.querySelector(n).innerHTML=""),!(t<=e.length))return!0;var a=e[t];if(void 0!==a&&"SCRIPT"===a.nodeName){var d=document.createElement("script");a.type&&(d.type=a.type),Array.prototype.forEach.call(a.attributes,(function(e){d.setAttribute(e.nodeName,e.nodeValue)})),""!=a.src?(d.src=a.src,d.onload=function(){_loadContent(e,t+1,n)},document.head.appendChild(d)):(d.text=a.text,document.body.appendChild(d),_loadContent(e,t+1,n))}else void 0!==a&&document.querySelector(n).appendChild(a),_loadContent(e,t+1,n)},loadData=async function(e,t,n=!1){return _loadContent(_htmlToElements(e),0,t,n)}; \ No newline at end of file