3 // AngularJS - Create application and load components
4 var angular = require('angular');
5 var ngResource = require('angular-resource');
6 var ngAnimate = require('angular-animate');
7 var ngSanitize = require('angular-sanitize');
9 var ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize']);
12 // Global Event System
15 emit: function (eventName, eventData) {
16 if (typeof this.listeners[eventName] === 'undefined') return this;
17 var eventsToStart = this.listeners[eventName];
18 for (let i = 0; i < eventsToStart.length; i++) {
19 var event = eventsToStart[i];
24 listen: function (eventName, callback) {
25 if (typeof this.listeners[eventName] === 'undefined') this.listeners[eventName] = [];
26 this.listeners[eventName].push(callback);
30 window.Events = Events;
32 var services = require('./services')(ngApp, Events);
33 var directives = require('./directives')(ngApp, Events);
34 var controllers = require('./controllers')(ngApp, Events);
36 //Global jQuery Config & Extensions
39 jQuery.fn.smoothScrollTo = function () {
40 if (this.length === 0) return;
42 scrollTop: this.offset().top - 60 // Adjust to change final scroll position top margin
43 }, 800); // Adjust to change animations speed (ms)
47 // Making contains text expression not worry about casing
48 $.expr[":"].contains = $.expr.createPseudo(function (arg) {
49 return function (elem) {
50 return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
54 // Global jQuery Elements
58 var notifications = $('.notification');
59 var successNotification = notifications.filter('.pos');
60 var errorNotification = notifications.filter('.neg');
61 // Notification Events
62 window.Events.listen('success', function (text) {
63 successNotification.hide();
64 successNotification.find('span').text(text);
66 successNotification.show();
69 window.Events.listen('error', function (text) {
70 errorNotification.find('span').text(text);
71 errorNotification.show();
74 // Notification hiding
75 notifications.click(function () {
79 // Chapter page list toggles
80 $('.chapter-toggle').click(function (e) {
82 $(this).toggleClass('open');
83 $(this).closest('.chapter').find('.inset-list').slideToggle(180);
89 function elemExists(selector) {
90 return document.querySelector(selector) !== null;
94 if (elemExists('#html-editor')) {
95 var tinyMceOptions = require('./pages/page-form');
96 tinymce.init(tinyMceOptions);
99 // Page specific items
100 require('./pages/page-show');