mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-59784 core: Modal factory should listen before fetching templates
This commit is contained in:
parent
e2b503043e
commit
728357707d
2
lib/amd/build/modal_factory.min.js
vendored
2
lib/amd/build/modal_factory.min.js
vendored
@ -1 +1 @@
|
|||||||
define(["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j){var k={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_confirm",CANCEL:"core/modal_cancel"},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"};c.register(l.DEFAULT,d,k.DEFAULT),c.register(l.SAVE_CANCEL,e,k.SAVE_CANCEL),c.register(l.CONFIRM,f,k.CONFIRM),c.register(l.CANCEL,g,k.CANCEL);var m=function(a,c){if("undefined"!=typeof c){if(Array.isArray(c)){var d=c[1];c=c[0],j.define(c,[j.events.activate]),c.on(j.events.activate,d,function(b,c){a.show(),c.originalEvent.preventDefault()})}else j.define(c,[j.events.activate]),c.on(j.events.activate,function(b,c){a.show(),c.originalEvent.preventDefault()});a.getRoot().on(b.hidden,function(){c.focus()})}},n=function(b,c,d){c=a(c);var e=b.module,f=new e(c);return m(f,d),f},o=function(b,c,d){var e=b.template;return h.render(e,c).then(function(c){var e=a(c);return n(b,e,d)}).fail(i.exception)},p=function(a,b){var d=a.type||l.DEFAULT,e=!!a.large,f=null,g={};return f=c.get(d),f||i.exception({message:"Unable to find modal of type: "+d}),"undefined"!=typeof a.templateContext&&(g=a.templateContext),o(f,g,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),e&&b.setLarge(),b})};return{create:p,types:l}});
|
define(["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j){var k={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_confirm",CANCEL:"core/modal_cancel"},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"};c.register(l.DEFAULT,d,k.DEFAULT),c.register(l.SAVE_CANCEL,e,k.SAVE_CANCEL),c.register(l.CONFIRM,f,k.CONFIRM),c.register(l.CANCEL,g,k.CANCEL);var m=function(a,c){if("undefined"!=typeof c){if(Array.isArray(c)){var d=c[1];c=c[0],j.define(c,[j.events.activate]),c.on(j.events.activate,d,function(b,c){a.then(function(a){return a.show(),a}),c.originalEvent.preventDefault()})}else j.define(c,[j.events.activate]),c.on(j.events.activate,function(b,c){a.then(function(a){return a.show(),a}),c.originalEvent.preventDefault()});a.then(function(a){return a.getRoot().on(b.hidden,function(){c.focus()}),a})}},n=function(b,c){c=a(c);var d=b.module,e=new d(c);return e},o=function(b,c,d){var e=b.template,f=h.render(e,c).then(function(c){var d=a(c);return n(b,d)}).fail(i.exception);return m(f,d),f},p=function(a,b){var d=a.type||l.DEFAULT,e=!!a.large,f=null,g={};return f=c.get(d),f||i.exception({message:"Unable to find modal of type: "+d}),"undefined"!=typeof a.templateContext&&(g=a.templateContext),o(f,g,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),e&&b.setLarge(),b})};return{create:p,types:l}});
|
@ -55,10 +55,10 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
|
|||||||
* is closed.
|
* is closed.
|
||||||
*
|
*
|
||||||
* @method setUpTrigger
|
* @method setUpTrigger
|
||||||
* @param {object} modal The modal instance
|
* @param {Promise} modalPromise The modal instance
|
||||||
* @param {object} triggerElement The jQuery element to open the modal
|
* @param {object} triggerElement The jQuery element to open the modal
|
||||||
*/
|
*/
|
||||||
var setUpTrigger = function(modal, triggerElement) {
|
var setUpTrigger = function(modalPromise, triggerElement) {
|
||||||
if (typeof triggerElement != 'undefined') {
|
if (typeof triggerElement != 'undefined') {
|
||||||
if (Array.isArray(triggerElement)) {
|
if (Array.isArray(triggerElement)) {
|
||||||
var selector = triggerElement[1];
|
var selector = triggerElement[1];
|
||||||
@ -66,19 +66,31 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
|
|||||||
|
|
||||||
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
|
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
|
||||||
triggerElement.on(CustomEvents.events.activate, selector, function(e, data) {
|
triggerElement.on(CustomEvents.events.activate, selector, function(e, data) {
|
||||||
modal.show();
|
modalPromise.then(function(modal) {
|
||||||
|
modal.show();
|
||||||
|
|
||||||
|
return modal;
|
||||||
|
});
|
||||||
data.originalEvent.preventDefault();
|
data.originalEvent.preventDefault();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
|
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
|
||||||
triggerElement.on(CustomEvents.events.activate, function(e, data) {
|
triggerElement.on(CustomEvents.events.activate, function(e, data) {
|
||||||
modal.show();
|
modalPromise.then(function(modal) {
|
||||||
|
modal.show();
|
||||||
|
|
||||||
|
return modal;
|
||||||
|
});
|
||||||
data.originalEvent.preventDefault();
|
data.originalEvent.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
modal.getRoot().on(ModalEvents.hidden, function() {
|
modalPromise.then(function(modal) {
|
||||||
triggerElement.focus();
|
modal.getRoot().on(ModalEvents.hidden, function() {
|
||||||
|
triggerElement.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
return modal;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -93,11 +105,10 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
|
|||||||
* @param {object} triggerElement The trigger HTML jQuery object
|
* @param {object} triggerElement The trigger HTML jQuery object
|
||||||
* @return {object} Modal instance
|
* @return {object} Modal instance
|
||||||
*/
|
*/
|
||||||
var createFromElement = function(registryConf, modalElement, triggerElement) {
|
var createFromElement = function(registryConf, modalElement) {
|
||||||
modalElement = $(modalElement);
|
modalElement = $(modalElement);
|
||||||
var module = registryConf.module;
|
var module = registryConf.module;
|
||||||
var modal = new module(modalElement);
|
var modal = new module(modalElement);
|
||||||
setUpTrigger(modal, triggerElement);
|
|
||||||
|
|
||||||
return modal;
|
return modal;
|
||||||
};
|
};
|
||||||
@ -115,12 +126,16 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
|
|||||||
var createFromType = function(registryConf, templateContext, triggerElement) {
|
var createFromType = function(registryConf, templateContext, triggerElement) {
|
||||||
var templateName = registryConf.template;
|
var templateName = registryConf.template;
|
||||||
|
|
||||||
return Templates.render(templateName, templateContext)
|
var modalPromise = Templates.render(templateName, templateContext)
|
||||||
.then(function(html) {
|
.then(function(html) {
|
||||||
var modalElement = $(html);
|
var modalElement = $(html);
|
||||||
return createFromElement(registryConf, modalElement, triggerElement);
|
return createFromElement(registryConf, modalElement);
|
||||||
})
|
})
|
||||||
.fail(Notification.exception);
|
.fail(Notification.exception);
|
||||||
|
|
||||||
|
setUpTrigger(modalPromise, triggerElement);
|
||||||
|
|
||||||
|
return modalPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user