MDL-68833 theme_boost: Add ./pending event checks back
[moodle.git] / theme / boost / amd / src / loader.js
CommitLineData
d2645a6a
DW
1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16/**
17 * Template renderer for Moodle. Load and render Moodle templates with Mustache.
18 *
19 * @module core/templates
20 * @package core
21 * @class templates
22 * @copyright 2015 Damyon Wiese <damyon@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * @since 2.9
25 */
d2645a6a 26
6a4ce7b0
BB
27import $ from 'jquery';
28import Aria from './aria';
6a4ce7b0
BB
29import Bootstrap from './bootstrap/index';
30import CustomEvents from 'core/custom_interaction_events';
721c29ff
AN
31import Pending from 'core/pending';
32import Scroll from './scroll';
33import setupBootstrapPendingChecks from './pending';
fbd99bbb 34
6a4ce7b0
BB
35/**
36 * Rember the last visited tabs.
37 */
38const rememberTabs = () => {
39 $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
40 var hash = $(e.target).attr('href');
41 if (history.replaceState) {
42 history.replaceState(null, null, hash);
43 } else {
44 location.hash = hash;
fbd99bbb 45 }
6a4ce7b0
BB
46 });
47 var hash = window.location.hash;
48 if (hash) {
49 $('.nav-link[href="' + hash + '"]').tab('show');
50 }
51};
fbd99bbb 52
6a4ce7b0
BB
53/**
54 * Enable all popovers
55 *
56 */
57const enablePopovers = () => {
58 $('body').popover({
59 selector: '[data-toggle="popover"]',
60 trigger: 'focus hover',
61 placement: 'auto'
62 });
191a1c7c 63
6a4ce7b0
BB
64 CustomEvents.define($('body'), [
65 CustomEvents.events.escape,
66 ]);
67 $('body').on(CustomEvents.events.escape, '[data-toggle=popover]', function() {
6a4ce7b0 68 $(this).trigger('blur');
d2645a6a 69 });
6a4ce7b0 70};
d2645a6a 71
6a4ce7b0
BB
72/**
73 * Enable tooltips
74 *
75 */
76const enableTooltips = () => {
77 $('body').tooltip({
78 container: 'body',
79 selector: '[data-toggle="tooltip"]'
80 });
721c29ff
AN
81};
82
83/**
84 * Bootstrap init function
85 */
86const init = () => {
87 const pendingPromise = new Pending('theme_boost/loader:init');
88
89 setupBootstrapPendingChecks();
90
91 // Remember the last visited tabs.
92 rememberTabs();
93
94 // Enable all popovers.
95 enablePopovers();
96
97 // Enable all tooltips.
98 enableTooltips();
99
100 // Add scroll handling.
101 (new Scroll()).init();
102
103 // Disables flipping the dropdowns up and getting hidden behind the navbar.
104 $.fn.dropdown.Constructor.Default.flip = false;
105
106 // Setup Aria helpers for Bootstrap features.
107 Aria.init();
108
109 pendingPromise.resolve();
110};
111
112/**
113 * Set up the search.
114 *
115 * @method init
116 */
117export {
118 init,
119 Bootstrap
120};