import Vue from 'vue' import Root from './Root.vue' import App from './App.vue' import About from './components/About.vue' import DictionaryView from './components/DictionaryView.vue' import VueRouter from 'vue-router' import { VuePlausible } from 'vue-plausible' import vuetify from './plugins/vuetify' import Vuex from 'vuex' import i18n from './i18n' Vue.config.productionTip = false Vue.use(Vuex) Vue.use(VueRouter) Vue.use(VuePlausible, { domain: 'beta.ordbok.uib.no' }) Vue.$plausible.enableAutoPageviews() const router = new VueRouter({ mode: 'history', base: __dirname, routes: [ { path: '/', component: App, children: [ { path: 'om', name: 'about', component: About }, { path: '', component: DictionaryView, children: [ { path: ':lang(bm|nn|bm,nn)', children: [ { path: 'search', name: 'query', params: {q: '', scope: 'w'} }, { name: 'word', path: 'w/:query' }, { name: 'lookup', path: ':id(\\d+)/:lemma?' }, { name: 'search', path: 'search/:query' } ] }, { path: 'bob/*', redirect: to => { return "bm/" + to.params.pathMatch } }, { path: 'nob/*', redirect: to => { return "nn/" + to.params.pathMatch } }, { path: 'bob,nob/*', redirect: to => { return "bm,nn/" + to.params.pathMatch } } ] } ] } ] }) // All interaction with local storage is encapsulated in vuex const store = new Vuex.Store({ strict: true, state: { showSearchToolbar: null, showInflectionNo: null, currentLocale: null, collapseArticles: null, defaultDict: null, menuOpen: false, noMouse: null, searchRoute: null, aboutOpen: false }, mutations: { initStore(state) { state.showSearchToolbar = localStorage.getItem('showSearchToolbar') || false state.showInflectionNo = localStorage.getItem('showInflectionNo') || false state.currentLocale = localStorage.getItem('currentLocale') state.defaultDict = localStorage.getItem('defaultDict') || 'bm,nn' state.collapseArticles = localStorage.getItem('collapseArticles') || window.innerWidth < 700 state.noMouse = window.matchMedia('(hover: none)').matches let locales = navigator.languages.map(l => l.split("-")[0]) if (!state.currentLocale) { if (locales.includes("nn")) state.currentLocale = "nno" else if (locales.includes("nb")) state.currentLocale = "nob" else if (locales.includes("no")) state.currentLocale = "nob" else state.currentLocale = "eng" } }, setLocale(state, payload) { state.currentLocale = payload.value payload.i18n.locale = payload.value localStorage.setItem("currentLocale", payload.value); }, toggle(state, setting) { let value = !state[setting] state[setting] = value localStorage.setItem(setting, value); }, setDefaultDict(state, value) { localStorage.setItem("defaultDict", value) state.defaultDict = value }, resetStore() { localStorage.removeItem("showSearchToolbar") localStorage.removeItem("showInflectionNo") localStorage.removeItem("currentLocale") localStorage.removeItem("collapseArticles") this.commit("initStore") }, setSearchRoute(state, path) { state.searchRoute = path } } }) new Vue({ router, vuetify, store, beforeCreate() { this.$store.commit('initStore'); }, i18n, render: h => h(Root ) }).$mount('#app')