2 require("babel-polyfill");
4 // Url retrieval function
5 window.baseUrl = function(path) {
6 let basePath = document.querySelector('meta[name="base-url"]').getAttribute('content');
7 if (basePath[basePath.length-1] === '/') basePath = basePath.slice(0, basePath.length-1);
8 if (path[0] === '/') path = path.slice(1);
9 return basePath + '/' + path;
12 // Global Event System
18 emit(eventName, eventData) {
19 if (typeof this.listeners[eventName] === 'undefined') return this;
20 let eventsToStart = this.listeners[eventName];
21 for (let i = 0; i < eventsToStart.length; i++) {
22 let event = eventsToStart[i];
28 listen(eventName, callback) {
29 if (typeof this.listeners[eventName] === 'undefined') this.listeners[eventName] = [];
30 this.listeners[eventName].push(callback);
35 window.Events = new EventManager();
37 const Vue = require("vue");
38 const axios = require("axios");
40 let axiosInstance = axios.create({
42 'X-CSRF-TOKEN': document.querySelector('meta[name=token]').getAttribute('content'),
43 'baseURL': window.baseUrl('')
46 axiosInstance.interceptors.request.use(resp => {
49 if (typeof err.response === "undefined" || typeof err.response.data === "undefined") return Promise.reject(err);
50 if (typeof err.response.data.error !== "undefined") window.Events.emit('error', err.response.data.error);
51 if (typeof err.response.data.message !== "undefined") window.Events.emit('error', err.response.data.message);
53 window.$http = axiosInstance;
55 Vue.prototype.$http = axiosInstance;
56 Vue.prototype.$events = window.Events;
59 // AngularJS - Create application and load components
60 const angular = require("angular");
61 require("angular-resource");
62 require("angular-animate");
63 require("angular-sanitize");
64 require("angular-ui-sortable");
66 let ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize', 'ui.sortable']);
69 // Creates a global function with name 'trans' to be used in the same way as Laravel's translation system
70 const Translations = require("./translations");
71 let translator = new Translations(window.translations);
72 window.trans = translator.get.bind(translator);
75 require("./vues/vues");
76 require("./components");
78 // Load in angular specific items
79 const Directives = require('./directives');
80 const Controllers = require('./controllers');
81 Directives(ngApp, window.Events);
82 Controllers(ngApp, window.Events);
84 //Global jQuery Config & Extensions
87 jQuery.fn.smoothScrollTo = function () {
88 if (this.length === 0) return;
89 $('html, body').animate({
90 scrollTop: this.offset().top - 60 // Adjust to change final scroll position top margin
91 }, 300); // Adjust to change animations speed (ms)
95 // Making contains text expression not worry about casing
96 jQuery.expr[":"].contains = $.expr.createPseudo(function (arg) {
97 return function (elem) {
98 return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
103 if(navigator.userAgent.indexOf('MSIE')!==-1
104 || navigator.appVersion.indexOf('Trident/') > 0
105 || navigator.userAgent.indexOf('Safari') !== -1){
106 document.body.classList.add('flexbox-support');
109 // Page specific items
110 require("./pages/page-show");