]> BookStack Code Mirror - bookstack/blob - resources/assets/js/global.js
Improved error messages for image uploads and formatted much js
[bookstack] / resources / assets / js / global.js
1 // Configure ZeroClipboard
2 window.ZeroClipboard = require('zeroclipboard');
3 window.ZeroClipboard.config({
4     swfPath: '/ZeroClipboard.swf'
5 });
6
7 // AngularJS - Create application and load components
8 var angular = require('angular');
9 var ngResource = require('angular-resource');
10 var ngAnimate = require('angular-animate');
11 var ngSanitize = require('angular-sanitize');
12
13 var ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize']);
14 var services = require('./services')(ngApp);
15 var directives = require('./directives')(ngApp);
16 var controllers = require('./controllers')(ngApp);
17
18 //Global jQuery Config & Extensions
19
20 // Smooth scrolling
21 jQuery.fn.smoothScrollTo = function () {
22     if (this.length === 0) return;
23     $('body').animate({
24         scrollTop: this.offset().top - 60 // Adjust to change final scroll position top margin
25     }, 800); // Adjust to change animations speed (ms)
26     return this;
27 };
28
29 // Making contains text expression not worry about casing
30 $.expr[":"].contains = $.expr.createPseudo(function (arg) {
31     return function (elem) {
32         return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
33     };
34 });
35
36 // Global jQuery Elements
37 $(function () {
38
39     // Notification hiding
40     $('.notification').click(function () {
41         $(this).fadeOut(100);
42     });
43
44     // Chapter page list toggles
45     $('.chapter-toggle').click(function (e) {
46         e.preventDefault();
47         $(this).toggleClass('open');
48         $(this).closest('.chapter').find('.inset-list').slideToggle(180);
49     });
50
51 });
52
53
54 function elemExists(selector) {
55     return document.querySelector(selector) !== null;
56 }
57
58 // TinyMCE editor
59 if (elemExists('#html-editor')) {
60     var tinyMceOptions = require('./pages/page-form');
61     tinymce.init(tinyMceOptions);
62 }