MDL-67149 Accessibility: Help popups fail WCAG 1.4.13 (Dismissable)
[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 */
81305c3b 26define(['jquery', './tether', 'core/event', 'core/custom_interaction_events'], function(jQuery, Tether, Event, customEvents) {
d2645a6a 27
d2645a6a
DW
28 window.jQuery = jQuery;
29 window.Tether = Tether;
5034f0a1 30 M.util.js_pending('theme_boost/loader:children');
d2645a6a 31
191a1c7c 32 require(['theme_boost/aria',
d27ac462 33 'theme_boost/pending',
191a1c7c 34 'theme_boost/util',
2ede86d7
DW
35 'theme_boost/alert',
36 'theme_boost/button',
37 'theme_boost/carousel',
38 'theme_boost/collapse',
39 'theme_boost/dropdown',
40 'theme_boost/modal',
41 'theme_boost/scrollspy',
42 'theme_boost/tab',
43 'theme_boost/tooltip',
44 'theme_boost/popover'],
191a1c7c 45 function(Aria) {
52a51514 46
facf039a 47 // We do twice because: https://github.com/twbs/bootstrap/issues/10547
52a51514 48 jQuery('body').popover({
77f59183 49 trigger: 'focus',
facf039a
DP
50 selector: "[data-toggle=popover][data-trigger!=hover]"
51 });
52
81305c3b 53 // Popovers must close on Escape for accessibility reasons.
54 customEvents.define(jQuery('body'), [
55 customEvents.events.escape,
56 ]);
57 jQuery('body').on(customEvents.events.escape, '[data-toggle=popover]', function() {
58 jQuery(this).popover('hide');
59 });
60
facf039a
DP
61 jQuery("html").popover({
62 container: "body",
63 selector: "[data-toggle=popover][data-trigger=hover]",
77f59183
RW
64 trigger: "hover",
65 delay: {
66 hide: 500
67 }
52a51514
DW
68 });
69
060da692
RW
70 jQuery("html").tooltip({
71 container: "body",
72 selector: '[data-toggle="tooltip"]'
73 });
74
9f08292f
BB
75 // Disables flipping the dropdowns up and getting hidden behind the navbar.
76 jQuery.fn.dropdown.Constructor.Default.flip = false;
77
fbd99bbb
BB
78 jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
79 var hash = jQuery(e.target).attr('href');
80 if (history.replaceState) {
81 history.replaceState(null, null, hash);
82 } else {
83 location.hash = hash;
84 }
85 });
86
87 var hash = window.location.hash;
88 if (hash) {
89 jQuery('.nav-link[href="' + hash + '"]').tab('show');
90 }
91
52a51514
DW
92 // We need to call popover automatically if nodes are added to the page later.
93 Event.getLegacyEvents().done(function(events) {
94 jQuery(document).on(events.FILTER_CONTENT_UPDATED, function() {
8712a50e
CB
95 jQuery('body').popover({
96 selector: '[data-toggle="popover"]',
97 trigger: 'focus'
98 });
191a1c7c 99
52a51514
DW
100 });
101 });
191a1c7c
DW
102
103 Aria.init();
5034f0a1 104 M.util.js_complete('theme_boost/loader:children');
d2645a6a
DW
105 });
106
52a51514 107
d2645a6a
DW
108 return {};
109});