~xdavidwu/xdavidwu.link

ba2873032f88651dc587706215d08709ab93e117 — xdavidwu 2 years ago 3ef14ae
light/dark: guard against missing disqus
2 files changed, 11 insertions(+), 7 deletions(-)

M assets/js/_main.js
M assets/js/main.min.js
M assets/js/_main.js => assets/js/_main.js +10 -6
@@ 91,13 91,17 @@ document.addEventListener('DOMContentLoaded', () => {
    midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
  })*/;

  document.getElementById('darkmode').addEventListener('click', () => {
    DISQUS.reset({reload: true});
    window.localStorage.setItem('darkmode', this.checked.toString());
  document.getElementById('darkmode').addEventListener('click', (e) => {
    if (typeof DISQUS !== 'undefined') {
      DISQUS.reset({reload: true});
    }
    window.localStorage.setItem('darkmode', e.currentTarget.checked.toString());
  });
  document.getElementById('lightmode').addEventListener('click', () => {
    DISQUS.reset({reload: true});
    window.localStorage.setItem('lightmode', this.checked.toString());
  document.getElementById('lightmode').addEventListener('click', (e) => {
    if (typeof DISQUS !== 'undefined') {
      DISQUS.reset({reload: true});
    }
    window.localStorage.setItem('lightmode', e.currentTarget.checked.toString());
  });

  if (window.localStorage.getItem('lightmode') === 'true') {

M assets/js/main.min.js => assets/js/main.min.js +1 -1
@@ 1,1 1,1 @@
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var d=t[o]={i:o,l:!1,exports:{}};return e[o].call(d.exports,d,d.exports,n),d.l=!0,d.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var d in e)n.d(o,d,function(t){return e[t]}.bind(null,d));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1),document.addEventListener("DOMContentLoaded",()=>{document.addEventListener("keyup",e=>{27===e.keyCode&&document.getElementsByClassName("initial-content")[0].classList.contains("is--hidden")&&(document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"))}),document.getElementsByClassName("search__toggle")[0].addEventListener("click",()=>{document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"),setTimeout((function(){document.querySelector(".search-content input").focus()}),400)}),document.getElementById("darkmode").addEventListener("click",()=>{DISQUS.reset({reload:!0}),window.localStorage.setItem("darkmode",this.checked.toString())}),document.getElementById("lightmode").addEventListener("click",()=>{DISQUS.reset({reload:!0}),window.localStorage.setItem("lightmode",this.checked.toString())}),"true"===window.localStorage.getItem("lightmode")&&(document.getElementById("lightmode").checked=!0),"true"===window.localStorage.getItem("darkmode")&&(document.getElementById("darkmode").checked=!0)})},function(e,t){const n=document.querySelector("nav.greedy-nav .greedy-nav__toggle"),o=document.querySelector("nav.greedy-nav .visible-links"),d=document.querySelector("nav.greedy-nav .hidden-links");var r,l,s=0,c=0,a=[];for(i of o.children)c+=i.offsetWidth,s+=1,a.push(c);function u(){r=o.offsetWidth,l=o.children.length,a[l-1]>r?(d.prepend(o.lastChild),l-=1,u()):r>a[l]&&(o.append(d.firstChild),l+=1,u()),l===s?n.classList.add("hidden"):n.classList.remove("hidden")}window.addEventListener("resize",()=>{u()}),n.addEventListener("click",()=>{d.classList.toggle("hidden"),n.classList.toggle("close")}),u()}]);
\ No newline at end of file
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var d=t[o]={i:o,l:!1,exports:{}};return e[o].call(d.exports,d,d.exports,n),d.l=!0,d.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var d in e)n.d(o,d,function(t){return e[t]}.bind(null,d));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1),document.addEventListener("DOMContentLoaded",()=>{document.addEventListener("keyup",e=>{27===e.keyCode&&document.getElementsByClassName("initial-content")[0].classList.contains("is--hidden")&&(document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"))}),document.getElementsByClassName("search__toggle")[0].addEventListener("click",()=>{document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"),setTimeout((function(){document.querySelector(".search-content input").focus()}),400)}),document.getElementById("darkmode").addEventListener("click",e=>{"undefined"!=typeof DISQUS&&DISQUS.reset({reload:!0}),window.localStorage.setItem("darkmode",e.currentTarget.checked.toString())}),document.getElementById("lightmode").addEventListener("click",e=>{"undefined"!=typeof DISQUS&&DISQUS.reset({reload:!0}),window.localStorage.setItem("lightmode",e.currentTarget.checked.toString())}),"true"===window.localStorage.getItem("lightmode")&&(document.getElementById("lightmode").checked=!0),"true"===window.localStorage.getItem("darkmode")&&(document.getElementById("darkmode").checked=!0)})},function(e,t){const n=document.querySelector("nav.greedy-nav .greedy-nav__toggle"),o=document.querySelector("nav.greedy-nav .visible-links"),d=document.querySelector("nav.greedy-nav .hidden-links");var r,l,c=0,s=0,a=[];for(i of o.children)s+=i.offsetWidth,c+=1,a.push(s);function u(){r=o.offsetWidth,l=o.children.length,a[l-1]>r?(d.prepend(o.lastChild),l-=1,u()):r>a[l]&&(o.append(d.firstChild),l+=1,u()),l===c?n.classList.add("hidden"):n.classList.remove("hidden")}window.addEventListener("resize",()=>{u()}),n.addEventListener("click",()=>{d.classList.toggle("hidden"),n.classList.toggle("close")}),u()}]);
\ No newline at end of file