You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
7.3 KiB
1 line
7.3 KiB
2 years ago
|
define(["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core/event","core/modal_events"],function(a,b,c,d,e,f,g,h){var i,j={CONTAINER:'[data-region="modal-container"]',MODAL:'[data-region="modal"]',HEADER:'[data-region="header"]',TITLE:'[data-region="title"]',BODY:'[data-region="body"]',FOOTER:'[data-region="footer"]',HIDE:'[data-action="hide"]',DIALOG:"[role=dialog]",FORM:"form",MENU_BAR:"[role=menubar]",HAS_Z_INDEX:".moodle-has-zindex",CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]'},k={LOADING:"core/loading",BACKDROP:"core/modal_backdrop"},l=0,m=function(b){this.root=a(b),this.modal=this.root.find(j.MODAL),this.header=this.modal.find(j.HEADER),this.title=this.header.find(j.TITLE),this.body=this.modal.find(j.BODY),this.footer=this.modal.find(j.FOOTER),this.hiddenSiblings=[],this.isAttached=!1,this.bodyJS=null,this.footerJS=null,this.modalCount=l++,this.root.is(j.CONTAINER)||c.exception({message:"Element is not a modal container"}),this.modal.length||c.exception({message:"Container does not contain a modal"}),this.header.length||c.exception({message:"Modal is missing a header region"}),this.title.length||c.exception({message:"Modal header is missing a title region"}),this.body.length||c.exception({message:"Modal is missing a body region"}),this.footer.length||c.exception({message:"Modal is missing a footer region"}),this.registerEventListeners()};return m.prototype.attachToDOM=function(){this.isAttached||(a("body").append(this.root),this.bodyJS&&(b.runTemplateJS(this.bodyJS),this.bodyJS=null),this.footerJS&&(b.runTemplateJS(this.footerJS),this.footerJS=null),this.isAttached=!0)},m.prototype.countOtherVisibleModals=function(){var b=0;return a("body").find(j.CONTAINER).each(function(c,d){d=a(d),!this.root.is(d)&&d.hasClass("show")&&b++}.bind(this)),b},m.prototype.getBackdrop=function(){return i||(i=b.render(k.BACKDROP,{}).then(function(b){var c=a(b);return new f(c)}).fail(c.exception)),i},m.prototype.getRoot=function(){return this.root},m.prototype.getModal=function(){return this.modal},m.prototype.getTitle=function(){return this.title},m.prototype.getBody=function(){return this.body},m.prototype.getFooter=function(){return this.footer},m.prototype.getModalCount=function(){return this.modalCount},m.prototype.setTitle=function(a){var b=this.getTitle();this.asyncSet(a,b.html.bind(b))},m.prototype.setBody=function(d){var e=this.getBody();if("string"==typeof d)e.html(d),g.notifyFilterContentUpdated(e),this.getRoot().trigger(h.bodyRendered,this);else{var f="amd-modal-js-pending-id-"+this.getModalCount();M.util.js_pending(f);var i=null;if(e.css("overflow","hidden"),"pending"==d.state()){var j=e.innerHeight();j<100&&(j=100),e.animate({height:j+"px"},150),e.html(""),i=b.render(k.LOADING,{}).then(function(b){var c=a(b).hide();return e.html(c),c.fadeIn(150),a.when(c.promise(),d)}).then(function(a){return a.fadeOut(100).promise()}).then(function(){return d})}else i=d;i.then(function(a,c){var d=null;if(this.isVisible()){e.css("opacity",0);var f=e.innerHeight();e.html(a),e.css("height","");var i=e.innerHeight();e.css("height",f+"px"),d=e.animate({height:i+"px",opacity:1},{duration:150,queue:!1}).promise()}else e.html(a);return c&&(this.isAttached?b.runTemplateJS(c):this.bodyJS=c),g.notifyFilterContentUpdated(e),this.getRoot().trigger(h.bodyRendered,this),d}.bind(this)).fail(c.exception).always(function(){e.css("height",""),e.css("overflow",""),e.css("opacity",""),M.util.js_complete(f)}).fail(c.exception)}},m.prototype.setFooter=function(a){this.showFooter();var c=this.getFooter();"string"==typeof a?c.html(a):b.render(k.LOADING,{}).done(function(d){c.html(d),a.done(function(a,d){c.html(a),d&&(this.isAttached?b.runTemplateJS(d):this.footerJS=d)}.bind(this))}.bind(this))},m.prototype.hasFooterContent=function(){return!!this.getFooter().children().length},m.prototype.hideFooter=function(){this.getFooter().addClass("hidden")},m.prototype.showFooter=function(){this.getFooter().removeClass("hidden")},m.prototype.setLarge=func
|