]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/global.js
replace GPL diff lib with MIT lib
[bookstack] / resources / assets / js / global.js
index 00c5f13c2103a67f51923a654c12be5cdff008f5..44562abd03806b7742e49d29112c45e87d11ba40 100644 (file)
@@ -5,9 +5,9 @@ var angular = require('angular');
 var ngResource = require('angular-resource');
 var ngAnimate = require('angular-animate');
 var ngSanitize = require('angular-sanitize');
+require('angular-ui-sortable');
 
-var ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize']);
-
+var ngApp = angular.module('bookStack', ['ngResource', 'ngAnimate', 'ngSanitize', 'ui.sortable']);
 
 // Global Event System
 var Events = {
@@ -54,10 +54,10 @@ $.expr[":"].contains = $.expr.createPseudo(function (arg) {
 // Global jQuery Elements
 $(function () {
 
-
     var notifications = $('.notification');
     var successNotification = notifications.filter('.pos');
     var errorNotification = notifications.filter('.neg');
+    var warningNotification = notifications.filter('.warning');
     // Notification Events
     window.Events.listen('success', function (text) {
         successNotification.hide();
@@ -66,6 +66,10 @@ $(function () {
             successNotification.show();
         }, 1);
     });
+    window.Events.listen('warning', function (text) {
+        warningNotification.find('span').text(text);
+        warningNotification.show();
+    });
     window.Events.listen('error', function (text) {
         errorNotification.find('span').text(text);
         errorNotification.show();
@@ -83,18 +87,36 @@ $(function () {
         $(this).closest('.chapter').find('.inset-list').slideToggle(180);
     });
 
-});
+    // Back to top button
+    $('#back-to-top').click(function() {
+         $('#header').smoothScrollTo();
+    });
+    var scrollTopShowing = false;
+    var scrollTop = document.getElementById('back-to-top');
+    var scrollTopBreakpoint = 1200;
+    window.addEventListener('scroll', function() {
+        if (!scrollTopShowing && document.body.scrollTop > scrollTopBreakpoint) {
+            scrollTop.style.display = 'block';
+            scrollTopShowing = true;
+            setTimeout(() => {
+                scrollTop.style.opacity = 0.4;
+            }, 1);
+        } else if (scrollTopShowing && document.body.scrollTop < scrollTopBreakpoint) {
+            scrollTop.style.opacity = 0;
+            scrollTopShowing = false;
+            setTimeout(() => {
+                scrollTop.style.display = 'none';
+            }, 500);
+        }
+    });
 
+    // Common jQuery actions
+    $('[data-action="expand-entity-list-details"]').click(function() {
+        $('.entity-list.compact').find('p').not('.empty-text').slideToggle(240);
+    });
 
-function elemExists(selector) {
-    return document.querySelector(selector) !== null;
-}
 
-// TinyMCE editor
-if (elemExists('#html-editor')) {
-    var tinyMceOptions = require('./pages/page-form');
-    tinymce.init(tinyMceOptions);
-}
+});
 
 // Page specific items
-require('./pages/page-show');
\ No newline at end of file
+require('./pages/page-show');