2018-04-15 21:05:42 -04:00
|
|
|
// Determine whether to use vue.js in debug or production mode
|
|
|
|
const Vue = env.debug ? require("vue/dist/vue.js") : require("vue/dist/vue.min.js");
|
2017-12-19 16:37:34 -05:00
|
|
|
|
2018-04-15 21:05:42 -04:00
|
|
|
// Import plugins
|
|
|
|
import VueRouter from "vue-router";
|
|
|
|
import VueResource from "vue-resource";
|
|
|
|
import Vuex from "vuex";
|
|
|
|
import { sync } from "vuex-router-sync";
|
|
|
|
|
|
|
|
// Load plugins
|
|
|
|
Vue.use(VueRouter);
|
|
|
|
Vue.use(VueResource);
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
|
|
|
// CSRF prevention header
|
|
|
|
Vue.http.headers.common["X-CSRF-TOKEN"] = env.csrfToken;
|
|
|
|
|
|
|
|
// Import page components
|
|
|
|
import HomePage from "pages/home.vue";
|
2018-04-26 20:26:18 -04:00
|
|
|
import BlogPage from "pages/blog.vue";
|
2018-04-15 21:05:42 -04:00
|
|
|
import ContactPage from "pages/contact.vue";
|
|
|
|
import Error404Page from "pages/error404.vue";
|
|
|
|
|
|
|
|
// Import section components
|
|
|
|
import NavSection from "sections/nav.vue";
|
|
|
|
import FooterSection from "sections/footer.vue";
|
|
|
|
|
|
|
|
// Name the nav and footer components so they can be used globally
|
|
|
|
Vue.component("nav-component", NavSection);
|
|
|
|
Vue.component("footer-component", FooterSection);
|
|
|
|
|
|
|
|
// Create a router instance
|
|
|
|
const router = new VueRouter({
|
|
|
|
mode: "history",
|
|
|
|
linkActiveClass: "active",
|
|
|
|
root: "/",
|
|
|
|
|
|
|
|
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 {
|
|
|
|
selector: `[id='${to.hash.slice(1)}']`
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return { x: 0, y: 0 };
|
|
|
|
}
|
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
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
appName: env.appName,
|
|
|
|
firstLoad: true,
|
|
|
|
lastPath: ""
|
|
|
|
},
|
|
|
|
|
|
|
|
getters: {
|
|
|
|
getAppName: state => {
|
|
|
|
return state.appName;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFirstLoad: state => {
|
|
|
|
return state.firstLoad;
|
|
|
|
},
|
|
|
|
|
|
|
|
getLastPath: state => {
|
|
|
|
return state.lastPath;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mutations: {
|
|
|
|
setFirstLoad(state, value) {
|
|
|
|
state.firstLoad = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
setLastPath(state, value) {
|
|
|
|
state.lastPath = value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Sync vue-router-sync with vuex store
|
|
|
|
sync(store, router);
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
// 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 {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
TweenMax.to("#router-view", 0.25, { opacity: 1 });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const App = new Vue({
|
|
|
|
router,
|
|
|
|
store
|
2018-04-24 20:38:04 -04:00
|
|
|
}).$mount("#vue-container");
|