@namelessmedia/tisc_nuxt
Version:
TISC NUXT Component Library
1 lines • 1.67 kB
JavaScript
import Vue from"vue";let newTheme,theme;process.browser&&(window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{theme=e.matches?"dark-theme":"light-theme",localStorage.setItem("color-theme",theme),document.documentElement.className=theme}),window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?(localStorage.setItem("color-theme","dark-theme"),document.documentElement.className="dark-theme"):(localStorage.setItem("color-theme","light-theme"),document.documentElement.className="light-theme"));export default({app:t},e)=>{e("tiscPlugin",Vue.observable({theme:"light-theme"})),process.browser&&(newTheme=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark-theme":"light-theme",t.$tiscPlugin.theme=newTheme,window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{newTheme=e.matches?"dark-theme":"light-theme",t.$tiscPlugin.theme=newTheme}))};Vue.directive("click-outside",{bind:function(t,m,o){document.body.addEventListener("click",function(e){t==e.target||t.contains(e.target)||o.context[m.expression](e)})},unbind:function(e){document.body.removeEventListener("click",event)}}),Vue.mixin({methods:{changeTheme(e){this.$tiscPlugin.theme=e,localStorage.setItem("color-theme",e),document.documentElement.className=e},getLogoImg(e,t,m=!1){return m?require(`@/node_modules/@namelessmedia/tisc_nuxt/img/logos/${e}.${t}?raw`):require(`@/node_modules/@namelessmedia/tisc_nuxt/img/logos/${e}.`+t)},getFlagImg(e,t=!1){return t?require(`@/node_modules/@namelessmedia/tisc_nuxt/img/flags/${e}.svg?raw`):require(`@/node_modules/@namelessmedia/tisc_nuxt/img/flags/${e}.svg`)}}});