1 |
efrain |
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 |
* Shows the footer content in a popover.
|
|
|
18 |
*
|
|
|
19 |
* @module theme_monocolor/footer-popover
|
|
|
20 |
* @copyright 2021 Bas Brands
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import $ from 'jquery';
|
|
|
25 |
import Popover from './popover';
|
|
|
26 |
|
|
|
27 |
const SELECTORS = {
|
|
|
28 |
FOOTERCONTAINER: '[data-region="footer-container-popover"]',
|
|
|
29 |
FOOTERCONTENT: '[data-region="footer-content-popover"]',
|
|
|
30 |
FOOTERBUTTON: '[data-action="footer-popover"]'
|
|
|
31 |
};
|
|
|
32 |
|
|
|
33 |
let footerIsShown = false;
|
|
|
34 |
|
|
|
35 |
export const init = () => {
|
|
|
36 |
const container = document.querySelector(SELECTORS.FOOTERCONTAINER);
|
|
|
37 |
const footerButton = document.querySelector(SELECTORS.FOOTERBUTTON);
|
|
|
38 |
|
|
|
39 |
// All jQuery in this code can be replaced when MDL-71979 is integrated.
|
|
|
40 |
$(footerButton).popover({
|
|
|
41 |
content: getFooterContent,
|
|
|
42 |
container: container,
|
|
|
43 |
html: true,
|
|
|
44 |
placement: 'top',
|
|
|
45 |
customClass: 'footer',
|
|
|
46 |
trigger: 'click',
|
|
|
47 |
boundary: 'viewport',
|
|
|
48 |
popperConfig: {
|
|
|
49 |
modifiers: {
|
|
|
50 |
preventOverflow: {
|
|
|
51 |
boundariesElement: 'viewport',
|
|
|
52 |
padding: 48
|
|
|
53 |
},
|
|
|
54 |
offset: {},
|
|
|
55 |
flip: {
|
|
|
56 |
behavior: 'flip'
|
|
|
57 |
},
|
|
|
58 |
arrow: {
|
|
|
59 |
element: '.arrow'
|
|
|
60 |
},
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
});
|
|
|
64 |
|
|
|
65 |
document.addEventListener('click', e => {
|
|
|
66 |
if (footerIsShown && !e.target.closest(SELECTORS.FOOTERCONTAINER)) {
|
|
|
67 |
$(footerButton).popover('hide');
|
|
|
68 |
}
|
|
|
69 |
},
|
|
|
70 |
true);
|
|
|
71 |
|
|
|
72 |
document.addEventListener('keydown', e => {
|
|
|
73 |
if (footerIsShown && e.key === 'Escape') {
|
|
|
74 |
$(footerButton).popover('hide');
|
|
|
75 |
footerButton.focus();
|
|
|
76 |
}
|
|
|
77 |
});
|
|
|
78 |
|
|
|
79 |
document.addEventListener('focus', e => {
|
|
|
80 |
if (footerIsShown && !e.target.closest(SELECTORS.FOOTERCONTAINER)) {
|
|
|
81 |
$(footerButton).popover('hide');
|
|
|
82 |
}
|
|
|
83 |
},
|
|
|
84 |
true);
|
|
|
85 |
|
|
|
86 |
$(footerButton).on('show.bs.popover', () => {
|
|
|
87 |
footerIsShown = true;
|
|
|
88 |
});
|
|
|
89 |
|
|
|
90 |
$(footerButton).on('hide.bs.popover', () => {
|
|
|
91 |
footerIsShown = false;
|
|
|
92 |
});
|
|
|
93 |
};
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Get the footer content for popover.
|
|
|
97 |
*
|
|
|
98 |
* @returns {String} HTML string
|
|
|
99 |
* @private
|
|
|
100 |
*/
|
|
|
101 |
const getFooterContent = () => {
|
|
|
102 |
return document.querySelector(SELECTORS.FOOTERCONTENT).innerHTML;
|
|
|
103 |
};
|
|
|
104 |
|
|
|
105 |
export {
|
|
|
106 |
Popover
|
|
|
107 |
};
|