]> BookStack Code Mirror - bookstack/blob - resources/assets/js/index.js
Fixes undefined error when clicking on page navigation links.
[bookstack] / resources / assets / js / index.js
1 // Global Polyfills
2 import "@babel/polyfill"
3 import "./services/dom-polyfills"
4
5 // Url retrieval function
6 window.baseUrl = function(path) {
7     let basePath = document.querySelector('meta[name="base-url"]').getAttribute('content');
8     if (basePath[basePath.length-1] === '/') basePath = basePath.slice(0, basePath.length-1);
9     if (path[0] === '/') path = path.slice(1);
10     return basePath + '/' + path;
11 };
12
13 // Set events and http services on window
14 import Events from "./services/events"
15 import Http from "./services/http"
16 let httpInstance = Http();
17 window.$http = httpInstance;
18 window.$events = new Events();
19
20 // Translation setup
21 // Creates a global function with name 'trans' to be used in the same way as Laravel's translation system
22 import Translations from "./services/translations"
23 let translator = new Translations(window.translations);
24 window.trans = translator.get.bind(translator);
25 window.trans_choice = translator.getPlural.bind(translator);
26
27 // Load in global UI helpers and libraries including jQuery
28 import "./services/global-ui"
29
30 // Set services on Vue
31 import Vue from "vue"
32 Vue.prototype.$http = httpInstance;
33 Vue.prototype.$events = window.$events;
34
35 // Load vues and components
36 import vues from "./vues/vues"
37 import components from "./components"
38 vues();
39 components();