Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 14... Línea 14...
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 15... Línea 15...
15
 
15
 
16
/**
16
/**
17
 * Template renderer for Moodle. Load and render Moodle templates with Mustache.
17
 * Template renderer for Moodle. Load and render Moodle templates with Mustache.
18
 *
18
 *
19
 * @module     theme_universe/loader
19
 * @module     theme_boost/loader
20
 * @copyright  2015 Damyon Wiese <damyon@moodle.com>
20
 * @copyright  2015 Damyon Wiese <damyon@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @since      2.9
22
 * @since      2.9
Línea 23... Línea -...
23
 */
-
 
24
 
23
 */
25
import $ from 'jquery';
24
 
26
import * as Aria from './aria';
25
import * as Aria from './aria';
27
import Bootstrap from './index';
26
import * as Bootstrap from './index';
28
import Pending from 'core/pending';
27
import Pending from 'core/pending';
-
 
28
import {DefaultAllowlist} from './bootstrap/util/sanitizer';
Línea 29... Línea 29...
29
import {DefaultWhitelist} from './bootstrap/tools/sanitizer';
29
import setupBootstrapPendingChecks from './pending';
30
import setupBootstrapPendingChecks from './pending';
30
import EventHandler from './bootstrap/dom/event-handler';
31
 
31
 
32
/**
32
/**
-
 
33
 * Rember the last visited tabs.
33
 * Rember the last visited tabs.
34
 */
34
 */
35
const rememberTabs = () => {
35
const rememberTabs = () => {
36
    const tabTriggerList = document.querySelectorAll('a[data-bs-toggle="tab"]');
36
    $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
37
    [...tabTriggerList].map(tabTriggerEl => tabTriggerEl.addEventListener('shown.bs.tab', (e) => {
37
        var hash = $(e.target).attr('href');
38
        var hash = e.target.getAttribute('href');
38
        if (history.replaceState) {
39
        if (history.replaceState) {
39
            history.replaceState(null, null, hash);
40
            history.replaceState(null, null, hash);
40
        } else {
41
        } else {
41
            location.hash = hash;
42
            location.hash = hash;
42
        }
43
        }
43
    });
44
    }));
44
    const hash = window.location.hash;
45
    const hash = window.location.hash;
45
    if (hash) {
46
    if (hash) {
Línea 53... Línea 54...
53
/**
54
/**
54
 * Enable all popovers
55
 * Enable all popovers
55
 *
56
 *
56
 */
57
 */
57
const enablePopovers = () => {
58
const enablePopovers = () => {
-
 
59
    const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]');
58
    $('body').popover({
60
    const popoverConfig = {
59
        container: 'body',
61
        container: 'body',
60
        selector: '[data-toggle="popover"]',
-
 
61
        trigger: 'focus',
62
        trigger: 'focus',
62
        whitelist: Object.assign(DefaultWhitelist, {
63
        allowList: Object.assign(DefaultAllowlist, {table: [], thead: [], tbody: [], tr: [], th: [], td: []}),
63
            table: [],
64
    };
-
 
65
    [...popoverTriggerList].map(popoverTriggerEl => new Bootstrap.Popover(popoverTriggerEl, popoverConfig));
-
 
66
 
64
            thead: [],
67
    // Enable dynamically created popovers inside modals.
65
            tbody: [],
68
    document.addEventListener('core/modal:bodyRendered', (e) => {
66
            tr: [],
69
        const modal = e.target;
67
            th: [],
70
        const popoverTriggerList = modal.querySelectorAll('[data-bs-toggle="popover"]');
68
            td: [],
71
        [...popoverTriggerList].map(popoverTriggerEl => new Bootstrap.Popover(popoverTriggerEl, popoverConfig));
69
        }),
-
 
70
    });
72
    });
Línea 71... Línea 73...
71
 
73
 
72
    document.addEventListener('keydown', e => {
74
    document.addEventListener('keydown', e => {
-
 
75
        const popoverTrigger = e.target.closest('[data-bs-toggle="popover"]');
-
 
76
        if (e.key === 'Escape' && popoverTrigger) {
-
 
77
            Bootstrap.Popover.getOrCreateInstance(popoverTrigger).hide();
-
 
78
        }
-
 
79
        if (e.key === 'Enter' && popoverTrigger) {
-
 
80
            Bootstrap.Popover.getOrCreateInstance(popoverTrigger).show();
-
 
81
        }
-
 
82
    });
-
 
83
    document.addEventListener('click', e => {
-
 
84
        const popoverTrigger = e.target.closest('[data-bs-toggle="popover"]');
-
 
85
        if (!popoverTrigger) {
-
 
86
            return;
-
 
87
        }
-
 
88
        const popover = Bootstrap.Popover.getOrCreateInstance(popoverTrigger);
73
        if (e.key === 'Escape' && e.target.closest('[data-toggle="popover"]')) {
89
        if (!popover._isShown()) {
74
            $(e.target).popover('hide');
90
            popover.show();
75
        }
91
        }
76
    });
92
    });
Línea 77... Línea 93...
77
};
93
};
78
 
94
 
79
/**
95
/**
80
 * Enable tooltips
96
 * Enable tooltips
81
 *
97
 *
82
 */
-
 
83
const enableTooltips = () => {
98
 */
84
    $('body').tooltip({
99
const enableTooltips = () => {
85
        container: 'body',
-
 
86
        selector: '[data-toggle="tooltip"]',
100
    const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
Línea -... Línea 101...
-
 
101
    [...tooltipTriggerList].map(tooltipTriggerEl => new Bootstrap.Tooltip(tooltipTriggerEl));
-
 
102
};
-
 
103
 
-
 
104
/**
-
 
105
 * Realocate Bootstrap events to the body element.
-
 
106
 *
-
 
107
 * Bootstrap 5 has a unique event handling mechanism that attaches all event handlers at the document level
-
 
108
 * during the capture phase, rather than the usual bubbling phase. As a result, original Bootstrap events
-
 
109
 * cannot be stopped or prevented, since the document is the first node executed in the capture phase.
-
 
110
 * For certain advanced UI elements, such as form autocomplete, it is important to capture key-down events before
-
 
111
 * Bootstrap's handlers to prevent unintended closures of elements. Therefore, we need to change the Bootstrap handler
-
 
112
 * so that it operates one level lower, specifically at the body level.
-
 
113
 */
-
 
114
const realocateBootstrapEvents = () => {
-
 
115
    EventHandler.off(document, 'keydown.bs.dropdown.data-api', '.dropdown-menu', Bootstrap.Dropdown.dataApiKeydownHandler);
87
    });
116
    EventHandler.on(document.body, 'keydown.bs.dropdown.data-api', '.dropdown-menu', Bootstrap.Dropdown.dataApiKeydownHandler);
Línea 88... Línea 117...
88
};
117
};
89
 
118
 
Línea 90... Línea 119...
90
const pendingPromise = new Pending('theme_universe/loader:init');
119
const pendingPromise = new Pending('theme_boost/loader:init');
Línea 102... Línea 131...
102
enablePopovers();
131
enablePopovers();
Línea 103... Línea 132...
103
 
132
 
104
// Enable all tooltips.
133
// Enable all tooltips.
Línea 105... Línea -...
105
enableTooltips();
-
 
106
 
-
 
107
// Disables flipping the dropdowns up or dynamically repositioning them along the Y-axis (based on the viewport)
-
 
108
// to prevent the dropdowns getting hidden behind the navbar or them covering the trigger element.
-
 
109
$.fn.dropdown.Constructor.Default.popperConfig = {
-
 
110
    modifiers: {
-
 
111
        flip: {
-
 
112
            enabled: false,
-
 
113
        },
-
 
114
        storeTopPosition: {
134
enableTooltips();
115
            enabled: true,
-
 
116
            // eslint-disable-next-line no-unused-vars
-
 
117
            fn(data, options) {
-
 
118
                data.storedTop = data.offsets.popper.top;
-
 
119
                return data;
-
 
120
            },
-
 
121
            order: 299
135
 
122
        },
-
 
123
        restoreTopPosition: {
-
 
124
            enabled: true,
-
 
125
            // eslint-disable-next-line no-unused-vars
-
 
126
            fn(data, options) {
-
 
127
                data.offsets.popper.top = data.storedTop;
-
 
128
                return data;
-
 
129
            },
-
 
130
            order: 301
-
 
131
        }
-
 
Línea 132... Línea 136...
132
    },
136
// Realocate Bootstrap events to the body element.
Línea 133... Línea 137...
133
};
137
realocateBootstrapEvents();
134
 
138