2022-06-13 18:04:19 -04:00
|
|
|
// Import features from Vue
|
|
|
|
import { createApp, nextTick } from "vue";
|
|
|
|
|
2019-09-28 01:50:06 -04:00
|
|
|
// Initialize Vue
|
2022-06-13 18:04:19 -04:00
|
|
|
const Vue = createApp({});
|
2017-12-19 16:37:34 -05:00
|
|
|
|
2022-06-13 18:04:19 -04:00
|
|
|
// Import and configure axios
|
|
|
|
window.axios = require("axios");
|
2018-04-15 21:05:42 -04:00
|
|
|
|
2022-06-13 18:04:19 -04:00
|
|
|
window.axios.defaults.headers.common = {
|
|
|
|
"X-Requested-With": "XMLHttpRequest",
|
|
|
|
"X-CSRF-TOKEN": env.csrfToken
|
|
|
|
};
|
2018-04-15 21:05:42 -04:00
|
|
|
|
2022-06-13 18:04:19 -04:00
|
|
|
Vue.config.globalProperties.$http = window.axios;
|
|
|
|
|
|
|
|
// Import plugins
|
|
|
|
import { createRouter, createWebHistory } from "vue-router";
|
|
|
|
import { createStore } from "vuex";
|
2018-04-15 21:05:42 -04:00
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
// Import local javascript
|
|
|
|
import SupportsWebP from "imports/supports-webp.js";
|
|
|
|
|
|
|
|
// Import global mixins
|
|
|
|
import ImageType from "mixins/image-type.js";
|
|
|
|
|
|
|
|
// Register global mixins
|
|
|
|
Vue.mixin(ImageType);
|
|
|
|
|
2018-04-29 23:27:44 -04:00
|
|
|
// Import global components
|
2018-04-15 21:05:42 -04:00
|
|
|
import NavSection from "sections/nav.vue";
|
|
|
|
import FooterSection from "sections/footer.vue";
|
2018-04-29 23:27:44 -04:00
|
|
|
import Lang from "partials/lang.vue";
|
2018-04-15 21:05:42 -04:00
|
|
|
|
2018-04-29 23:27:44 -04:00
|
|
|
// Name the global components
|
2018-04-15 21:05:42 -04:00
|
|
|
Vue.component("nav-component", NavSection);
|
|
|
|
Vue.component("footer-component", FooterSection);
|
2018-04-29 23:27:44 -04:00
|
|
|
Vue.component("lang", Lang);
|
2018-04-15 21:05:42 -04:00
|
|
|
|
2018-05-10 23:00:06 -04:00
|
|
|
// Import page components
|
|
|
|
import HomePage from "pages/home.vue";
|
|
|
|
import BlogPage from "pages/blog.vue";
|
|
|
|
import ContactPage from "pages/contact.vue";
|
|
|
|
import Error404Page from "pages/error404.vue";
|
|
|
|
|
2018-04-15 21:05:42 -04:00
|
|
|
// Create a router instance
|
2022-06-13 18:04:19 -04:00
|
|
|
const router = new createRouter({
|
|
|
|
history: createWebHistory(),
|
2018-04-15 21:05:42 -04:00
|
|
|
linkActiveClass: "active",
|
|
|
|
|
|
|
|
routes: [
|
|
|
|
{ path: "/", component: HomePage },
|
2018-04-26 20:26:18 -04:00
|
|
|
{ path: "/blog", component: BlogPage },
|
2018-04-15 21:05:42 -04:00
|
|
|
{ path: "/contact", component: ContactPage },
|
|
|
|
{ path: "/*", component: Error404Page }
|
|
|
|
],
|
|
|
|
|
|
|
|
scrollBehavior(to, from, savedPosition) {
|
|
|
|
if (to.hash) {
|
|
|
|
return {
|
2022-07-12 00:16:46 -04:00
|
|
|
el: `[id='${to.hash.slice(1)}']`
|
2018-04-15 21:05:42 -04:00
|
|
|
};
|
|
|
|
} else {
|
2022-07-12 00:16:46 -04:00
|
|
|
return { top: 0 };
|
2018-04-15 21:05:42 -04:00
|
|
|
}
|
2016-01-26 23:20:08 -05:00
|
|
|
}
|
2016-01-03 19:08:53 -05:00
|
|
|
});
|
2018-04-15 21:05:42 -04:00
|
|
|
|
|
|
|
// Create a vuex store instance
|
2022-06-13 18:04:19 -04:00
|
|
|
const store = createStore({
|
2018-04-15 21:05:42 -04:00
|
|
|
state: {
|
|
|
|
appName: env.appName,
|
2018-04-29 23:27:44 -04:00
|
|
|
appLang: env.appLang,
|
|
|
|
appDefaultLang: env.appDefaultLang,
|
2018-04-15 21:05:42 -04:00
|
|
|
firstLoad: true,
|
2021-07-29 16:40:55 -04:00
|
|
|
lastPath: "",
|
|
|
|
supportsWebP: null
|
2018-04-15 21:05:42 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getters: {
|
|
|
|
getAppName: state => {
|
|
|
|
return state.appName;
|
|
|
|
},
|
|
|
|
|
2018-04-29 23:27:44 -04:00
|
|
|
getAppLang: state => {
|
|
|
|
return state.appLang;
|
|
|
|
},
|
|
|
|
|
|
|
|
getAppDefaultLang: state => {
|
|
|
|
return state.appDefaultLang;
|
|
|
|
},
|
|
|
|
|
2018-04-15 21:05:42 -04:00
|
|
|
getFirstLoad: state => {
|
|
|
|
return state.firstLoad;
|
|
|
|
},
|
|
|
|
|
|
|
|
getLastPath: state => {
|
|
|
|
return state.lastPath;
|
2021-07-29 16:40:55 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getSupportsWebP: state => {
|
|
|
|
return state.supportsWebP;
|
2018-04-15 21:05:42 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mutations: {
|
2018-04-29 23:27:44 -04:00
|
|
|
setAppLang(state, value) {
|
|
|
|
state.appLang = value;
|
|
|
|
Vue.http.get(`/language/${value}`);
|
|
|
|
},
|
|
|
|
|
2018-04-15 21:05:42 -04:00
|
|
|
setFirstLoad(state, value) {
|
|
|
|
state.firstLoad = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
setLastPath(state, value) {
|
|
|
|
state.lastPath = value;
|
2021-07-29 16:40:55 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
setSupportsWebP(state, value) {
|
|
|
|
state.supportsWebP = value;
|
2018-04-15 21:05:42 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-29 16:40:55 -04:00
|
|
|
// Detect webp support
|
|
|
|
SupportsWebP.detect(store);
|
|
|
|
|
2018-04-15 21:05:42 -04:00
|
|
|
// Functionality to run before page load and change
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.path !== store.getters.getLastPath) {
|
|
|
|
if (store.getters.getFirstLoad) {
|
|
|
|
next();
|
|
|
|
} else {
|
2019-05-10 23:38:27 -04:00
|
|
|
// Unfocused any focused elements
|
|
|
|
if ("activeElement" in document) {
|
|
|
|
document.activeElement.blur();
|
|
|
|
}
|
|
|
|
|
2018-04-15 21:05:42 -04:00
|
|
|
// Fade the page out and scroll when moving from one page to another
|
|
|
|
TweenMax.to("#router-view", 0.25, {
|
|
|
|
opacity: 0,
|
|
|
|
onComplete: next
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Functionality to run on page load and change
|
|
|
|
router.afterEach((to, from) => {
|
|
|
|
if (to.path !== store.getters.getLastPath) {
|
|
|
|
store.commit("setLastPath", to.path);
|
|
|
|
|
|
|
|
if (store.getters.getFirstLoad) {
|
|
|
|
// Set Page.firstLoad to false so we know the initial load has completed
|
|
|
|
store.commit("setFirstLoad", false);
|
|
|
|
} else {
|
2022-06-13 18:04:19 -04:00
|
|
|
nextTick(() => {
|
2018-04-15 21:05:42 -04:00
|
|
|
TweenMax.to("#router-view", 0.25, { opacity: 1 });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-13 18:04:19 -04:00
|
|
|
Vue.use(router).use(store).mount("#vue-container");
|