]> BookStack Code Mirror - bookstack/blob - resources/assets/js/services/global-ui.js
Add "register" to nav.
[bookstack] / resources / assets / js / services / global-ui.js
1 // Global jQuery Config & Extensions
2
3 import jQuery from "jquery"
4 window.jQuery = window.$ = jQuery;
5
6 /**
7  * Scroll the view to a specific element.
8  * @param {HTMLElement} element
9  */
10 window.scrollToElement = function(element) {
11     if (!element) return;
12     let offset = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
13     let top = element.getBoundingClientRect().top + offset;
14     $('html, body').animate({
15         scrollTop: top - 60 // Adjust to change final scroll position top margin
16     }, 300);
17 };
18
19 /**
20  * Scroll and highlight an element.
21  * @param {HTMLElement} element
22  */
23 window.scrollAndHighlight = function(element) {
24     if (!element) return;
25     window.scrollToElement(element);
26     let color = document.getElementById('custom-styles').getAttribute('data-color-light');
27     let initColor = window.getComputedStyle(element).getPropertyValue('background-color');
28     element.style.backgroundColor = color;
29     setTimeout(() => {
30         element.classList.add('selectFade');
31         element.style.backgroundColor = initColor;
32     }, 10);
33     setTimeout(() => {
34         element.classList.remove('selectFade');
35         element.style.backgroundColor = '';
36     }, 3000);
37 };
38
39 // Smooth scrolling
40 jQuery.fn.smoothScrollTo = function () {
41     if (this.length === 0) return;
42     window.scrollToElement(this[0]);
43     return this;
44 };
45
46 // Making contains text expression not worry about casing
47 jQuery.expr[":"].contains = $.expr.createPseudo(function (arg) {
48     return function (elem) {
49         return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
50     };
51 });
52
53 // Detect IE for css
54 if(navigator.userAgent.indexOf('MSIE')!==-1
55     || navigator.appVersion.indexOf('Trident/') > 0
56     || navigator.userAgent.indexOf('Safari') !== -1){
57     document.body.classList.add('flexbox-support');
58 }