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 const Vue = require("vue");
13 const axios = require("axios");
15 let axiosInstance = axios.create({
17 'X-CSRF-TOKEN': document.querySelector('meta[name=token]').getAttribute('content'),
18 'baseURL': window.baseUrl('')
21 window.$http = axiosInstance;
22 Vue.prototype.$http = axiosInstance;
25 // AngularJS - Create application and load components
26 const angular = require("angular");
27 require("angular-resource");
28 require("angular-animate");
29 require("angular-sanitize");
30 require("angular-ui-sortable");
32 let ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize', 'ui.sortable']);
35 // Creates a global function with name 'trans' to be used in the same way as Laravel's translation system
36 const Translations = require("./translations");
37 let translator = new Translations(window.translations);
38 window.trans = translator.get.bind(translator);
40 // Global Event System
46 emit(eventName, eventData) {
47 if (typeof this.listeners[eventName] === 'undefined') return this;
48 let eventsToStart = this.listeners[eventName];
49 for (let i = 0; i < eventsToStart.length; i++) {
50 let event = eventsToStart[i];
56 listen(eventName, callback) {
57 if (typeof this.listeners[eventName] === 'undefined') this.listeners[eventName] = [];
58 this.listeners[eventName].push(callback);
63 window.Events = new EventManager();
64 Vue.prototype.$events = window.Events;
66 require("./vues/vues");
67 require("./components");
69 // Load in angular specific items
70 const Directives = require('./directives');
71 const Controllers = require('./controllers');
72 Directives(ngApp, window.Events);
73 Controllers(ngApp, window.Events);
75 //Global jQuery Config & Extensions
78 jQuery.fn.smoothScrollTo = function () {
79 if (this.length === 0) return;
80 $('html, body').animate({
81 scrollTop: this.offset().top - 60 // Adjust to change final scroll position top margin
82 }, 300); // Adjust to change animations speed (ms)
86 // Making contains text expression not worry about casing
87 jQuery.expr[":"].contains = $.expr.createPseudo(function (arg) {
88 return function (elem) {
89 return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
94 if(navigator.userAgent.indexOf('MSIE')!==-1
95 || navigator.appVersion.indexOf('Trident/') > 0
96 || navigator.userAgent.indexOf('Safari') !== -1){
97 document.body.classList.add('flexbox-support');
100 // Page specific items
101 require("./pages/page-show");