Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 33... Línea 33...
33
import * as FilterEvents from 'core_filters/events';
33
import * as FilterEvents from 'core_filters/events';
34
import * as FocusLock from 'core/local/aria/focuslock';
34
import * as FocusLock from 'core/local/aria/focuslock';
35
import * as Aria from 'core/aria';
35
import * as Aria from 'core/aria';
36
import * as Fullscreen from 'core/fullscreen';
36
import * as Fullscreen from 'core/fullscreen';
37
import {removeToastRegion} from './toast';
37
import {removeToastRegion} from './toast';
-
 
38
import {dispatchEvent} from 'core/event_dispatcher';
Línea 38... Línea 39...
38
 
39
 
39
/**
40
/**
40
 * A configuration to provide to the modal.
41
 * A configuration to provide to the modal.
41
 *
42
 *
Línea 129... Línea 130...
129
        this.footerJS = null;
130
        this.footerJS = null;
130
        this.modalCount = Modal.modalCounter++;
131
        this.modalCount = Modal.modalCounter++;
131
        this.attachmentPoint = document.createElement('div');
132
        this.attachmentPoint = document.createElement('div');
132
        document.body.append(this.attachmentPoint);
133
        document.body.append(this.attachmentPoint);
133
        this.focusOnClose = null;
134
        this.focusOnClose = null;
-
 
135
        this.templateJS = null;
Línea 134... Línea 136...
134
 
136
 
135
        if (!this.root.is(SELECTORS.CONTAINER)) {
137
        if (!this.root.is(SELECTORS.CONTAINER)) {
136
            Notification.exception({message: 'Element is not a modal container'});
138
            Notification.exception({message: 'Element is not a modal container'});
Línea 192... Línea 194...
192
        const pendingModalPromise = new Pending('core/modal_factory:create');
194
        const pendingModalPromise = new Pending('core/modal_factory:create');
193
        modalConfig.type = this.TYPE;
195
        modalConfig.type = this.TYPE;
Línea 194... Línea 196...
194
 
196
 
195
        const templateName = this._getTemplateName(modalConfig);
197
        const templateName = this._getTemplateName(modalConfig);
196
        const templateContext = modalConfig.templateContext || {};
198
        const templateContext = modalConfig.templateContext || {};
Línea 197... Línea 199...
197
        const {html} = await Templates.renderForPromise(templateName, templateContext);
199
        const {html, js} = await Templates.renderForPromise(templateName, templateContext);
-
 
200
 
-
 
201
        const modal = new this(html);
-
 
202
        if (js) {
198
 
203
            modal.setTemplateJS(js);
Línea 199... Línea 204...
199
        const modal = new this(html);
204
        }
Línea 200... Línea 205...
200
        modal.configure(modalConfig);
205
        modal.configure(modalConfig);
Línea 301... Línea 306...
301
 
306
 
Línea 302... Línea 307...
302
        FocusLock.trapFocus(this.root[0]);
307
        FocusLock.trapFocus(this.root[0]);
303
 
308
 
-
 
309
        // If we'd cached any JS then we can run it how that the modal is
-
 
310
        // attached to the DOM.
-
 
311
        if (this.templateJS) {
-
 
312
            Templates.runTemplateJS(this.templateJS);
-
 
313
            this.templateJS = null;
304
        // If we'd cached any JS then we can run it how that the modal is
314
        }
305
        // attached to the DOM.
315
 
306
        if (this.bodyJS) {
316
        if (this.bodyJS) {
307
            Templates.runTemplateJS(this.bodyJS);
317
            Templates.runTemplateJS(this.bodyJS);
Línea 571... Línea 581...
571
                return result;
581
                return result;
572
            })
582
            })
573
            .then((result) => {
583
            .then((result) => {
574
                FilterEvents.notifyFilterContentUpdated(body);
584
                FilterEvents.notifyFilterContentUpdated(body);
575
                this.getRoot().trigger(ModalEvents.bodyRendered, this);
585
                this.getRoot().trigger(ModalEvents.bodyRendered, this);
-
 
586
                dispatchEvent('core/modal:bodyRendered', this, this.modal[0]);
576
                return result;
587
                return result;
577
            })
588
            })
578
            .then(() => {
589
            .then(() => {
579
                this.bodyPromise.resolve(body);
590
                this.bodyPromise.resolve(body);
580
                return;
591
                return;
Línea 885... Línea 896...
885
 
896
 
886
            this.root.removeClass('hide').addClass('show');
897
            this.root.removeClass('hide').addClass('show');
887
            this.accessibilityShow();
898
            this.accessibilityShow();
888
            this.getModal().focus();
899
            this.getModal().focus();
-
 
900
            $('body').addClass('modal-open');
-
 
901
            const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
889
            $('body').addClass('modal-open');
902
            $('body').css({overflow: "hidden", paddingRight: `${scrollbarWidth}px`});
-
 
903
            this.root.trigger(ModalEvents.shown, this);
Línea 890... Línea 904...
890
            this.root.trigger(ModalEvents.shown, this);
904
            dispatchEvent('core/modal:shown', this, this.modal[0]);
891
 
905
 
892
            return;
906
            return;
893
        })
907
        })
Línea 917... Línea 931...
917
 
931
 
918
            if (!this.countOtherVisibleModals()) {
932
            if (!this.countOtherVisibleModals()) {
919
                // Hide the backdrop if we're the last open modal.
933
                // Hide the backdrop if we're the last open modal.
920
                backdrop.hide();
934
                backdrop.hide();
-
 
935
                $('body').removeClass('modal-open');
921
                $('body').removeClass('modal-open');
936
                $('body').css({overflow: "", paddingRight: ""});
Línea 922... Línea 937...
922
            }
937
            }
923
 
938
 
924
            const currentIndex = parseInt(this.root.css('z-index'));
939
            const currentIndex = parseInt(this.root.css('z-index'));
Línea 940... Línea 955...
940
            if ($(document.body).find(this.getRoot()).length) {
955
            if ($(document.body).find(this.getRoot()).length) {
941
                $(document.body).append(this.getRoot());
956
                $(document.body).append(this.getRoot());
942
            }
957
            }
Línea 943... Línea 958...
943
 
958
 
944
            // Closes popover elements that are inside the modal at the time the modal is closed.
959
            // Closes popover elements that are inside the modal at the time the modal is closed.
945
            this.getRoot().find('[data-toggle="popover"]').each(function() {
960
            this.getRoot().find('[data-bs-toggle="popover"]').each(function() {
946
                document.getElementById(this.getAttribute('aria-describedby'))?.remove();
961
                document.getElementById(this.getAttribute('aria-describedby'))?.remove();
Línea 947... Línea 962...
947
            });
962
            });
948
 
963
 
Línea 1210... Línea 1225...
1210
            button.attr('disabled', '');
1225
            button.attr('disabled', '');
1211
        } else {
1226
        } else {
1212
            button.removeAttr('disabled');
1227
            button.removeAttr('disabled');
1213
        }
1228
        }
1214
    }
1229
    }
-
 
1230
 
-
 
1231
    /**
-
 
1232
     * Set the template JS for this modal.
-
 
1233
     * @param {String} js The JavaScript to run when the modal is attached to the DOM.
-
 
1234
     */
-
 
1235
    setTemplateJS(js) {
-
 
1236
        this.templateJS = js;
-
 
1237
    }
1215
}
1238
}