From fcb6fdf39316fae435ce6a822f8c7ec4f069fc01 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 18 May 2023 13:42:19 +0800 Subject: [PATCH] MDL-78306 core: Convert core/modal to ESM --- lib/amd/build/first.min.js | 26 +- lib/amd/build/first.min.js.map | 2 +- lib/amd/build/modal.min.js | 10 +- lib/amd/build/modal.min.js.map | 2 +- lib/amd/src/first.js | 15 +- lib/amd/src/modal.js | 440 ++++++++++++++++----------------- 6 files changed, 235 insertions(+), 260 deletions(-) diff --git a/lib/amd/build/first.min.js b/lib/amd/build/first.min.js index 0ea58150d29..159471424a8 100644 --- a/lib/amd/build/first.min.js +++ b/lib/amd/build/first.min.js @@ -1,16 +1,16 @@ +define("core/first",["jquery"],(function(_jquery){var obj; /** - * This is an empty module, that is required before all other modules. - * Because every module is returned from a request for any other module, this - * forces the loading of all modules with a single request. - * - * This function also sets up the listeners for ajax requests so we can tell - * if any requests are still in progress. - * - * @module core/first - * @copyright 2015 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since 2.9 - */ -define("core/first",["jquery"],(function($){$(document).bind("ajaxStart",(function(){M.util.js_pending("jq")})).bind("ajaxStop",(function(){M.util.js_complete("jq")}))})); + * This is an empty module, that is required before all other modules. + * Because every module is returned from a request for any other module, this + * forces the loading of all modules with a single request. + * + * This function also sets up the listeners for ajax requests so we can tell + * if any requests are still in progress. + * + * @module core/first + * @copyright 2015 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since 2.9 + */(0,(_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj}).default)(document).bind("ajaxStart",(function(){M.util.js_pending("jq")})).bind("ajaxStop",(function(){M.util.js_complete("jq")}))})); //# sourceMappingURL=first.min.js.map \ No newline at end of file diff --git a/lib/amd/build/first.min.js.map b/lib/amd/build/first.min.js.map index 7cd1860203b..3c44137db98 100644 --- a/lib/amd/build/first.min.js.map +++ b/lib/amd/build/first.min.js.map @@ -1 +1 @@ -{"version":3,"file":"first.min.js","sources":["../src/first.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This is an empty module, that is required before all other modules.\n * Because every module is returned from a request for any other module, this\n * forces the loading of all modules with a single request.\n *\n * This function also sets up the listeners for ajax requests so we can tell\n * if any requests are still in progress.\n *\n * @module core/first\n * @copyright 2015 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 2.9\n */\ndefine(['jquery'], function($) {\n $(document).bind(\"ajaxStart\", function() {\n M.util.js_pending('jq');\n }).bind(\"ajaxStop\", function() {\n M.util.js_complete('jq');\n });\n});\n"],"names":["define","$","document","bind","M","util","js_pending","js_complete"],"mappings":";;;;;;;;;;;;;AA4BAA,oBAAO,CAAC,WAAW,SAASC,GACxBA,EAAEC,UAAUC,KAAK,aAAa,WAC1BC,EAAEC,KAAKC,WAAW,SACnBH,KAAK,YAAY,WAChBC,EAAEC,KAAKE,YAAY"} \ No newline at end of file +{"version":3,"file":"first.min.js","sources":["../src/first.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This is an empty module, that is required before all other modules.\n * Because every module is returned from a request for any other module, this\n * forces the loading of all modules with a single request.\n *\n * This function also sets up the listeners for ajax requests so we can tell\n * if any requests are still in progress.\n *\n * @module core/first\n * @copyright 2015 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 2.9\n */\n\nimport $ from 'jquery';\n\n$(document)\n.bind(\"ajaxStart\", function() {\n M.util.js_pending('jq');\n})\n.bind(\"ajaxStop\", function() {\n M.util.js_complete('jq');\n});\n"],"names":["document","bind","M","util","js_pending","js_complete"],"mappings":";;;;;;;;;;;;;2EA+BEA,UACDC,KAAK,aAAa,WACfC,EAAEC,KAAKC,WAAW,SAErBH,KAAK,YAAY,WACdC,EAAEC,KAAKE,YAAY"} \ No newline at end of file diff --git a/lib/amd/build/modal.min.js b/lib/amd/build/modal.min.js index ae27c3efa97..3d182bab113 100644 --- a/lib/amd/build/modal.min.js +++ b/lib/amd/build/modal.min.js @@ -1,11 +1,3 @@ -/** - * Contain the logic for modals. - * - * @module core/modal - * @class core/modal - * @copyright 2016 Ryan Wyllie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("core/modal",["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core_filters/events","core/modal_events","core/local/aria/focuslock","core/pending","core/aria","core/fullscreen"],(function($,Templates,Notification,KeyCodes,CustomEvents,ModalBackdrop,FilterEvents,ModalEvents,FocusLock,Pending,Aria,Fullscreen){var backdropPromise,SELECTORS_CONTAINER='[data-region="modal-container"]',SELECTORS_MODAL='[data-region="modal"]',SELECTORS_HEADER='[data-region="header"]',SELECTORS_TITLE='[data-region="title"]',SELECTORS_BODY='[data-region="body"]',SELECTORS_FOOTER='[data-region="footer"]',SELECTORS_HIDE='[data-action="hide"]',SELECTORS_DIALOG="[role=dialog]",SELECTORS_FORM="form",SELECTORS_MENU_BAR="[role=menubar]",SELECTORS_HAS_Z_INDEX=".moodle-has-zindex",TEMPLATES_LOADING="core/loading",TEMPLATES_BACKDROP="core/modal_backdrop",modalCounter=0,Modal=function(root){this.root=$(root),this.modal=this.root.find(SELECTORS_MODAL),this.header=this.modal.find(SELECTORS_HEADER),this.headerPromise=$.Deferred(),this.title=this.header.find(SELECTORS_TITLE),this.titlePromise=$.Deferred(),this.body=this.modal.find(SELECTORS_BODY),this.bodyPromise=$.Deferred(),this.footer=this.modal.find(SELECTORS_FOOTER),this.footerPromise=$.Deferred(),this.hiddenSiblings=[],this.isAttached=!1,this.bodyJS=null,this.footerJS=null,this.modalCount=modalCounter++,this.attachmentPoint=document.createElement("div"),document.body.append(this.attachmentPoint),this.focusOnClose=null,this.root.is(SELECTORS_CONTAINER)||Notification.exception({message:"Element is not a modal container"}),this.modal.length||Notification.exception({message:"Container does not contain a modal"}),this.header.length||Notification.exception({message:"Modal is missing a header region"}),this.title.length||Notification.exception({message:"Modal header is missing a title region"}),this.body.length||Notification.exception({message:"Modal is missing a body region"}),this.footer.length||Notification.exception({message:"Modal is missing a footer region"}),this.registerEventListeners()};return Modal.prototype.attachToDOM=function(){this.getAttachmentPoint().append(this.root),this.isAttached||(FocusLock.trapFocus(this.root[0]),this.bodyJS&&(Templates.runTemplateJS(this.bodyJS),this.bodyJS=null),this.footerJS&&(Templates.runTemplateJS(this.footerJS),this.footerJS=null),this.isAttached=!0)},Modal.prototype.countOtherVisibleModals=function(){var count=0;return $("body").find(SELECTORS_CONTAINER).each(function(index,element){element=$(element),!this.root.is(element)&&element.hasClass("show")&&count++}.bind(this)),count},Modal.prototype.getBackdrop=function(){return backdropPromise||(backdropPromise=Templates.render(TEMPLATES_BACKDROP,{}).then((function(html){var element=$(html);return new ModalBackdrop(element)})).fail(Notification.exception)),backdropPromise},Modal.prototype.getRoot=function(){return this.root},Modal.prototype.getModal=function(){return this.modal},Modal.prototype.getTitle=function(){return this.title},Modal.prototype.getBody=function(){return this.body},Modal.prototype.getFooter=function(){return this.footer},Modal.prototype.getTitlePromise=function(){return this.titlePromise},Modal.prototype.getBodyPromise=function(){return this.bodyPromise},Modal.prototype.getFooterPromise=function(){return this.footerPromise},Modal.prototype.getModalCount=function(){return this.modalCount},Modal.prototype.setTitle=function(value){var title=this.getTitle();this.titlePromise=$.Deferred(),this.asyncSet(value,title.html.bind(title)).then(function(){this.titlePromise.resolve(title)}.bind(this)).catch(Notification.exception)},Modal.prototype.setBody=function(value){this.bodyPromise=$.Deferred();var body=this.getBody();if("string"==typeof value)body.html(value),FilterEvents.notifyFilterContentUpdated(body),this.getRoot().trigger(ModalEvents.bodyRendered,this),this.bodyPromise.resolve(body);else{var jsPendingId="amd-modal-js-pending-id-"+this.getModalCount();M.util.js_pending(jsPendingId);var contentPromise=null;if(body.css("overflow","hidden"),"pending"==(value=$.when(value)).state()){var height=body.innerHeight();height<100&&(height=100),body.animate({height:height+"px"},150),body.html(""),contentPromise=Templates.render(TEMPLATES_LOADING,{}).then((function(html){var loadingIcon=$(html).hide();return body.html(loadingIcon),loadingIcon.fadeIn(150),$.when(loadingIcon.promise(),value)})).then((function(loadingIcon){return loadingIcon.fadeOut(100).promise()})).then((function(){return value}))}else contentPromise=value;contentPromise.then(function(html,js){var result=null;if(this.isVisible()){body.css("opacity",0);var currentHeight=body.innerHeight();body.html(html),body.css("height","");var newHeight=body.innerHeight();body.css("height",currentHeight+"px"),result=body.animate({height:newHeight+"px",opacity:1},{duration:150,queue:!1}).promise()}else body.html(html);return js&&(this.isAttached?Templates.runTemplateJS(js):this.bodyJS=js),result}.bind(this)).then(function(result){return FilterEvents.notifyFilterContentUpdated(body),this.getRoot().trigger(ModalEvents.bodyRendered,this),result}.bind(this)).then(function(){this.bodyPromise.resolve(body)}.bind(this)).fail(Notification.exception).always((function(){body.css("height",""),body.css("overflow",""),body.css("opacity",""),M.util.js_complete(jsPendingId)})).fail(Notification.exception)}},Modal.prototype.setBodyContent=function(promise){return promise.then((_ref=>{let{html:html,js:js}=_ref;return this.setBody($.when(html,js))})).catch((exception=>{throw this.hide(),exception}))},Modal.prototype.setFooter=function(value){this.showFooter(),this.footerPromise=$.Deferred();var footer=this.getFooter();"string"==typeof value?(footer.html(value),this.footerPromise.resolve(footer)):Templates.render(TEMPLATES_LOADING,{}).then((function(html){return footer.html(html),value})).then(function(html,js){return footer.html(html),js&&(this.isAttached?Templates.runTemplateJS(js):this.footerJS=js),footer}.bind(this)).then(function(footer){this.footerPromise.resolve(footer)}.bind(this)).catch(Notification.exception)},Modal.prototype.hasFooterContent=function(){return!!this.getFooter().children().length},Modal.prototype.hideFooter=function(){this.getFooter().addClass("hidden")},Modal.prototype.showFooter=function(){this.getFooter().removeClass("hidden")},Modal.prototype.setLarge=function(){this.isLarge()||this.getModal().addClass("modal-lg")},Modal.prototype.isLarge=function(){return this.getModal().hasClass("modal-lg")},Modal.prototype.setSmall=function(){this.isSmall()||this.getModal().removeClass("modal-lg")},Modal.prototype.isSmall=function(){return!this.getModal().hasClass("modal-lg")},Modal.prototype.setScrollable=function(value){value?this.getModal()[0].classList.add("modal-dialog-scrollable"):this.getModal()[0].classList.remove("modal-dialog-scrollable")},Modal.prototype.calculateZIndex=function(){var items=$(SELECTORS_DIALOG+", "+SELECTORS_MENU_BAR+", "+SELECTORS_HAS_Z_INDEX),zIndex=parseInt(this.root.css("z-index"));return items.each((function(index,item){var itemZIndex=(item=$(item)).css("z-index")?parseInt(item.css("z-index")):0;itemZIndex>zIndex&&(zIndex=itemZIndex)})),zIndex},Modal.prototype.isVisible=function(){return this.root.hasClass("show")},Modal.prototype.hasFocus=function(){var target=$(document.activeElement);return this.root.is(target)||this.root.has(target).length},Modal.prototype.hasTransitions=function(){return this.getRoot().hasClass("fade")},Modal.prototype.getAttachmentPoint=function(){return $(Fullscreen.getElement()||this.attachmentPoint)},Modal.prototype.show=function(){if(this.isVisible())return $.Deferred().resolve();var pendingPromise=new Pending("core/modal:show");return this.hasFooterContent()?this.showFooter():this.hideFooter(),this.attachToDOM(),!this.focusOnClose&&document.activeElement&&(this.focusOnClose=document.activeElement),this.getBackdrop().then(function(backdrop){var newIndex=this.calculateZIndex()+2,newBackdropIndex=newIndex-1;this.root.css("z-index",newIndex),backdrop.setZIndex(newBackdropIndex),backdrop.show(),this.root.removeClass("hide").addClass("show"),this.accessibilityShow(),this.getModal().focus(),$("body").addClass("modal-open"),this.root.trigger(ModalEvents.shown,this)}.bind(this)).then(pendingPromise.resolve)},Modal.prototype.hideIfNotForm=function(){0==this.modal.find(SELECTORS_FORM).length&&this.hide()},Modal.prototype.hide=function(){this.getBackdrop().done(function(backdrop){FocusLock.untrapFocus(),this.countOtherVisibleModals()||(backdrop.hide(),$("body").removeClass("modal-open"));var currentIndex=parseInt(this.root.css("z-index"));this.root.css("z-index",""),backdrop.setZIndex(currentIndex-3),this.accessibilityHide(),this.hasTransitions()?this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",function(){this.getRoot().removeClass("show").addClass("hide")}.bind(this)):this.getRoot().removeClass("show").addClass("hide"),$(document.body).find(this.getRoot()).length&&$(document.body).append(this.getRoot()),this.root.trigger(ModalEvents.hidden,this)}.bind(this))},Modal.prototype.destroy=function(){this.hide(),this.root.remove(),this.root.trigger(ModalEvents.destroyed,this),this.attachmentPoint.remove()},Modal.prototype.accessibilityShow=function(){Aria.unhide(this.root.get()),Aria.hideSiblings(this.root.get()[0])},Modal.prototype.accessibilityHide=function(){Aria.unhideSiblings(this.root.get()[0]),Aria.hide(this.root.get())},Modal.prototype.registerEventListeners=function(){this.getRoot().on("keydown",function(e){this.isVisible()&&e.keyCode==KeyCodes.escape&&(this.removeOnClose?this.destroy():this.hide())}.bind(this)),this.getRoot().click(function(e){if(!$(e.target).closest(SELECTORS_MODAL).length&&$(e.target).closest(SELECTORS_CONTAINER).length){var outsideClickEvent=$.Event(ModalEvents.outsideClick);this.getRoot().trigger(outsideClickEvent,this),outsideClickEvent.isDefaultPrevented()||this.hideIfNotForm()}}.bind(this)),CustomEvents.define(this.getModal(),[CustomEvents.events.activate]),this.getModal().on(CustomEvents.events.activate,SELECTORS_HIDE,function(e,data){this.removeOnClose?this.destroy():this.hide(),data.originalEvent.preventDefault()}.bind(this)),this.getRoot().on(ModalEvents.hidden,(()=>{this.focusOnClose&&this.focusOnClose.focus()}))},Modal.prototype.registerCloseOnCancel=function(){this.getModal().on(CustomEvents.events.activate,this.getActionSelector("cancel"),function(e,data){var cancelEvent=$.Event(ModalEvents.cancel);this.getRoot().trigger(cancelEvent,this),cancelEvent.isDefaultPrevented()||(data.originalEvent.preventDefault(),this.removeOnClose?this.destroy():this.hide())}.bind(this))},Modal.prototype.registerCloseOnSave=function(){this.getModal().on(CustomEvents.events.activate,this.getActionSelector("save"),function(e,data){var saveEvent=$.Event(ModalEvents.save);this.getRoot().trigger(saveEvent,this),saveEvent.isDefaultPrevented()||(data.originalEvent.preventDefault(),this.removeOnClose?this.destroy():this.hide())}.bind(this))},Modal.prototype.registerCloseOnDelete=function(){this.getModal().on(CustomEvents.events.activate,this.getActionSelector("delete"),function(e,data){var deleteEvent=$.Event(ModalEvents.delete);this.getRoot().trigger(deleteEvent,this),deleteEvent.isDefaultPrevented()||(data.originalEvent.preventDefault(),this.removeOnClose?this.destroy():this.hide())}.bind(this))},Modal.prototype.asyncSet=function(value,setFunction){var p=value;return"object"==typeof value&&value.hasOwnProperty("then")||(p=$.Deferred()).resolve(value),p.then((function(content){setFunction(content)})).fail(Notification.exception),p},Modal.prototype.setButtonText=function(action,value){const button=this.getFooter().find(this.getActionSelector(action));if(!button)throw new Error("Unable to find the '"+action+"' button");return this.asyncSet(value,button.text.bind(button))},Modal.prototype.getActionSelector=function(action){return"[data-action='"+action+"']"},Modal.prototype.setRemoveOnClose=function(remove){this.removeOnClose=remove},Modal.prototype.setReturnElement=function(element){this.focusOnClose=element},Modal.prototype.setButtonDisabled=function(action,disabled){const button=this.getFooter().find(this.getActionSelector(action));if(!button)throw new Error("Unable to find the '"+action+"' button");disabled?button.attr("disabled",""):button.removeAttr("disabled")},Modal})); +define("core/modal",["exports","jquery","core/templates","core/notification","core/key_codes","core/modal_backdrop","core/modal_events","core/pending","core/custom_interaction_events","core_filters/events","core/local/aria/focuslock","core/aria","core/fullscreen"],(function(_exports,_jquery,Templates,Notification,KeyCodes,_modal_backdrop,_modal_events,_pending,CustomEvents,FilterEvents,FocusLock,Aria,Fullscreen){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_jquery=_interopRequireDefault(_jquery),Templates=_interopRequireWildcard(Templates),Notification=_interopRequireWildcard(Notification),KeyCodes=_interopRequireWildcard(KeyCodes),_modal_backdrop=_interopRequireDefault(_modal_backdrop),_modal_events=_interopRequireDefault(_modal_events),_pending=_interopRequireDefault(_pending),CustomEvents=_interopRequireWildcard(CustomEvents),FilterEvents=_interopRequireWildcard(FilterEvents),FocusLock=_interopRequireWildcard(FocusLock),Aria=_interopRequireWildcard(Aria),Fullscreen=_interopRequireWildcard(Fullscreen);const SELECTORS_CONTAINER='[data-region="modal-container"]',SELECTORS_MODAL='[data-region="modal"]',SELECTORS_HEADER='[data-region="header"]',SELECTORS_TITLE='[data-region="title"]',SELECTORS_BODY='[data-region="body"]',SELECTORS_FOOTER='[data-region="footer"]',SELECTORS_HIDE='[data-action="hide"]',SELECTORS_DIALOG="[role=dialog]",SELECTORS_FORM="form",SELECTORS_MENU_BAR="[role=menubar]",SELECTORS_HAS_Z_INDEX=".moodle-has-zindex",TEMPLATES_LOADING="core/loading",TEMPLATES_BACKDROP="core/modal_backdrop";class Modal{constructor(root){_defineProperty(this,"backdropPromise",null),this.root=(0,_jquery.default)(root),this.modal=this.root.find(SELECTORS_MODAL),this.header=this.modal.find(SELECTORS_HEADER),this.headerPromise=_jquery.default.Deferred(),this.title=this.header.find(SELECTORS_TITLE),this.titlePromise=_jquery.default.Deferred(),this.body=this.modal.find(SELECTORS_BODY),this.bodyPromise=_jquery.default.Deferred(),this.footer=this.modal.find(SELECTORS_FOOTER),this.footerPromise=_jquery.default.Deferred(),this.hiddenSiblings=[],this.isAttached=!1,this.bodyJS=null,this.footerJS=null,this.modalCount=this.modalCounter++,this.attachmentPoint=document.createElement("div"),document.body.append(this.attachmentPoint),this.focusOnClose=null,this.root.is(SELECTORS_CONTAINER)||Notification.exception({message:"Element is not a modal container"}),this.modal.length||Notification.exception({message:"Container does not contain a modal"}),this.header.length||Notification.exception({message:"Modal is missing a header region"}),this.title.length||Notification.exception({message:"Modal header is missing a title region"}),this.body.length||Notification.exception({message:"Modal is missing a body region"}),this.footer.length||Notification.exception({message:"Modal is missing a footer region"}),this.registerEventListeners()}attachToDOM(){this.getAttachmentPoint().append(this.root),this.isAttached||(FocusLock.trapFocus(this.root[0]),this.bodyJS&&(Templates.runTemplateJS(this.bodyJS),this.bodyJS=null),this.footerJS&&(Templates.runTemplateJS(this.footerJS),this.footerJS=null),this.isAttached=!0)}countOtherVisibleModals(){let count=0;return(0,_jquery.default)("body").find(SELECTORS_CONTAINER).each(((index,element)=>{element=(0,_jquery.default)(element),!this.root.is(element)&&element.hasClass("show")&&count++})),count}getBackdrop(){return Modal.backdropPromise||(Modal.backdropPromise=Templates.render(TEMPLATES_BACKDROP,{}).then((html=>new _modal_backdrop.default((0,_jquery.default)(html)))).catch(Notification.exception)),Modal.backdropPromise}getRoot(){return this.root}getModal(){return this.modal}getTitle(){return this.title}getBody(){return this.body}getFooter(){return this.footer}getTitlePromise(){return this.titlePromise}getBodyPromise(){return this.bodyPromise}getFooterPromise(){return this.footerPromise}getModalCount(){return this.modalCount}setTitle(value){const title=this.getTitle();this.titlePromise=_jquery.default.Deferred(),this.asyncSet(value,title.html.bind(title)).then((()=>{this.titlePromise.resolve(title)})).catch(Notification.exception)}setBody(value){this.bodyPromise=_jquery.default.Deferred();const body=this.getBody();if("string"==typeof value)body.html(value),FilterEvents.notifyFilterContentUpdated(body),this.getRoot().trigger(_modal_events.default.bodyRendered,this),this.bodyPromise.resolve(body);else{const modalPromise=new _pending.default("amd-modal-js-pending-id-".concat(this.getModalCount()));let contentPromise=null;if(body.css("overflow","hidden"),"pending"==(value=_jquery.default.when(value)).state()){let height=body.innerHeight();height<100&&(height=100),body.animate({height:"".concat(height,"px")},150),body.html(""),contentPromise=Templates.render(TEMPLATES_LOADING,{}).then((html=>{const loadingIcon=(0,_jquery.default)(html).hide();return body.html(loadingIcon),loadingIcon.fadeIn(150),_jquery.default.when(loadingIcon.promise(),value)})).then((loadingIcon=>loadingIcon.fadeOut(100).promise())).then((()=>value))}else contentPromise=value;contentPromise.then(((html,js)=>{let result=null;if(this.isVisible()){body.css("opacity",0);const currentHeight=body.innerHeight();body.html(html),body.css("height","");const newHeight=body.innerHeight();body.css("height","".concat(currentHeight,"px")),result=body.animate({height:"".concat(newHeight,"px"),opacity:1},{duration:150,queue:!1}).promise()}else body.html(html);return js&&(this.isAttached?Templates.runTemplateJS(js):this.bodyJS=js),result})).then((result=>(FilterEvents.notifyFilterContentUpdated(body),this.getRoot().trigger(_modal_events.default.bodyRendered,this),result))).then((()=>{this.bodyPromise.resolve(body)})).catch(Notification.exception).always((()=>{body.css("height",""),body.css("overflow",""),body.css("opacity",""),modalPromise.resolve()}))}}setBodyContent(promise){return promise.then((_ref=>{let{html:html,js:js}=_ref;return this.setBody(_jquery.default.when(html,js))})).catch((exception=>{throw this.hide(),exception}))}setFooter(value){this.showFooter(),this.footerPromise=_jquery.default.Deferred();const footer=this.getFooter();"string"==typeof value?(footer.html(value),this.footerPromise.resolve(footer)):Templates.render(TEMPLATES_LOADING,{}).then((html=>(footer.html(html),value))).then(((html,js)=>(footer.html(html),js&&(this.isAttached?Templates.runTemplateJS(js):this.footerJS=js),footer))).then((footer=>{this.footerPromise.resolve(footer)})).catch(Notification.exception)}hasFooterContent(){return!!this.getFooter().children().length}hideFooter(){this.getFooter().addClass("hidden")}showFooter(){this.getFooter().removeClass("hidden")}setLarge(){this.isLarge()||this.getModal().addClass("modal-lg")}isLarge(){return this.getModal().hasClass("modal-lg")}setSmall(){this.isSmall()||this.getModal().removeClass("modal-lg")}isSmall(){return!this.getModal().hasClass("modal-lg")}setScrollable(value){value?this.getModal()[0].classList.add("modal-dialog-scrollable"):this.getModal()[0].classList.remove("modal-dialog-scrollable")}calculateZIndex(){const items=(0,_jquery.default)("".concat(SELECTORS_DIALOG,", ").concat(SELECTORS_MENU_BAR,", ").concat(SELECTORS_HAS_Z_INDEX));let zIndex=parseInt(this.root.css("z-index"));return items.each(((index,item)=>{const itemZIndex=(item=(0,_jquery.default)(item)).css("z-index")?parseInt(item.css("z-index")):0;itemZIndex>zIndex&&(zIndex=itemZIndex)})),zIndex}isVisible(){return this.root.hasClass("show")}hasFocus(){const target=(0,_jquery.default)(document.activeElement);return this.root.is(target)||this.root.has(target).length}hasTransitions(){return this.getRoot().hasClass("fade")}getAttachmentPoint(){return(0,_jquery.default)(Fullscreen.getElement()||this.attachmentPoint)}show(){if(this.isVisible())return _jquery.default.Deferred().resolve();const pendingPromise=new _pending.default("core/modal:show");return this.hasFooterContent()?this.showFooter():this.hideFooter(),this.attachToDOM(),!this.focusOnClose&&document.activeElement&&(this.focusOnClose=document.activeElement),this.getBackdrop().then((backdrop=>{const newIndex=this.calculateZIndex()+2,newBackdropIndex=newIndex-1;this.root.css("z-index",newIndex),backdrop.setZIndex(newBackdropIndex),backdrop.show(),this.root.removeClass("hide").addClass("show"),this.accessibilityShow(),this.getModal().focus(),(0,_jquery.default)("body").addClass("modal-open"),this.root.trigger(_modal_events.default.shown,this)})).then(pendingPromise.resolve)}hideIfNotForm(){0==this.modal.find(SELECTORS_FORM).length&&this.hide()}hide(){this.getBackdrop().done((backdrop=>{FocusLock.untrapFocus(),this.countOtherVisibleModals()||(backdrop.hide(),(0,_jquery.default)("body").removeClass("modal-open"));const currentIndex=parseInt(this.root.css("z-index"));this.root.css("z-index",""),backdrop.setZIndex(currentIndex-3),this.accessibilityHide(),this.hasTransitions()?this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",(()=>{this.getRoot().removeClass("show").addClass("hide")})):this.getRoot().removeClass("show").addClass("hide"),(0,_jquery.default)(document.body).find(this.getRoot()).length&&(0,_jquery.default)(document.body).append(this.getRoot()),this.root.trigger(_modal_events.default.hidden,this)}))}destroy(){this.hide(),this.root.remove(),this.root.trigger(_modal_events.default.destroyed,this),this.attachmentPoint.remove()}accessibilityShow(){Aria.unhide(this.root.get()),Aria.hideSiblings(this.root.get()[0])}accessibilityHide(){Aria.unhideSiblings(this.root.get()[0]),Aria.hide(this.root.get())}registerEventListeners(){this.getRoot().on("keydown",(e=>{this.isVisible()&&e.keyCode==KeyCodes.escape&&(this.removeOnClose?this.destroy():this.hide())})),this.getRoot().click((e=>{if(!(0,_jquery.default)(e.target).closest(SELECTORS_MODAL).length&&(0,_jquery.default)(e.target).closest(SELECTORS_CONTAINER).length){const outsideClickEvent=_jquery.default.Event(_modal_events.default.outsideClick);this.getRoot().trigger(outsideClickEvent,this),outsideClickEvent.isDefaultPrevented()||this.hideIfNotForm()}})),CustomEvents.define(this.getModal(),[CustomEvents.events.activate]),this.getModal().on(CustomEvents.events.activate,SELECTORS_HIDE,((e,data)=>{this.removeOnClose?this.destroy():this.hide(),data.originalEvent.preventDefault()})),this.getRoot().on(_modal_events.default.hidden,(()=>{this.focusOnClose&&this.focusOnClose.focus()}))}registerCloseOnCancel(){this.getModal().on(CustomEvents.events.activate,this.getActionSelector("cancel"),((e,data)=>{const cancelEvent=_jquery.default.Event(_modal_events.default.cancel);this.getRoot().trigger(cancelEvent,this),cancelEvent.isDefaultPrevented()||(data.originalEvent.preventDefault(),this.removeOnClose?this.destroy():this.hide())}))}registerCloseOnSave(){this.getModal().on(CustomEvents.events.activate,this.getActionSelector("save"),((e,data)=>{const saveEvent=_jquery.default.Event(_modal_events.default.save);this.getRoot().trigger(saveEvent,this),saveEvent.isDefaultPrevented()||(data.originalEvent.preventDefault(),this.removeOnClose?this.destroy():this.hide())}))}registerCloseOnDelete(){this.getModal().on(CustomEvents.events.activate,this.getActionSelector("delete"),((e,data)=>{const deleteEvent=_jquery.default.Event(_modal_events.default.delete);this.getRoot().trigger(deleteEvent,this),deleteEvent.isDefaultPrevented()||(data.originalEvent.preventDefault(),this.removeOnClose?this.destroy():this.hide())}))}asyncSet(value,setFunction){var p=value;return"object"==typeof value&&value.hasOwnProperty("then")||(p=_jquery.default.Deferred()).resolve(value),p.then((content=>{setFunction(content)})).catch(Notification.exception),p}setButtonText(action,value){const button=this.getFooter().find(this.getActionSelector(action));if(!button)throw new Error("Unable to find the '"+action+"' button");return this.asyncSet(value,button.text.bind(button))}getActionSelector(action){return"[data-action='"+action+"']"}setRemoveOnClose(remove){this.removeOnClose=remove}setReturnElement(element){this.focusOnClose=element}setButtonDisabled(action,disabled){const button=this.getFooter().find(this.getActionSelector(action));if(!button)throw new Error("Unable to find the '"+action+"' button");disabled?button.attr("disabled",""):button.removeAttr("disabled")}}return _exports.default=Modal,_defineProperty(Modal,"modalCounter",0),_exports.default})); //# sourceMappingURL=modal.min.js.map \ No newline at end of file diff --git a/lib/amd/build/modal.min.js.map b/lib/amd/build/modal.min.js.map index 498eecf481d..6e502eca004 100644 --- a/lib/amd/build/modal.min.js.map +++ b/lib/amd/build/modal.min.js.map @@ -1 +1 @@ -{"version":3,"file":"modal.min.js","sources":["../src/modal.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Contain the logic for modals.\n *\n * @module core/modal\n * @class core/modal\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'core/key_codes',\n 'core/custom_interaction_events',\n 'core/modal_backdrop',\n 'core_filters/events',\n 'core/modal_events',\n 'core/local/aria/focuslock',\n 'core/pending',\n 'core/aria',\n 'core/fullscreen'\n], function(\n $,\n Templates,\n Notification,\n KeyCodes,\n CustomEvents,\n ModalBackdrop,\n FilterEvents,\n ModalEvents,\n FocusLock,\n Pending,\n Aria,\n Fullscreen\n) {\n\n var SELECTORS = {\n CONTAINER: '[data-region=\"modal-container\"]',\n MODAL: '[data-region=\"modal\"]',\n HEADER: '[data-region=\"header\"]',\n TITLE: '[data-region=\"title\"]',\n BODY: '[data-region=\"body\"]',\n FOOTER: '[data-region=\"footer\"]',\n HIDE: '[data-action=\"hide\"]',\n DIALOG: '[role=dialog]',\n FORM: 'form',\n MENU_BAR: '[role=menubar]',\n HAS_Z_INDEX: '.moodle-has-zindex',\n CAN_RECEIVE_FOCUS: 'input:not([type=\"hidden\"]), a[href], button, textarea, select, [tabindex]',\n };\n\n var TEMPLATES = {\n LOADING: 'core/loading',\n BACKDROP: 'core/modal_backdrop',\n };\n\n /**\n * Module singleton for the backdrop to be reused by all Modal instances.\n */\n var backdropPromise;\n\n /**\n * A counter that gets incremented for each modal created. This can be\n * used to generate unique values for the modals.\n */\n var modalCounter = 0;\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n var Modal = function(root) {\n this.root = $(root);\n this.modal = this.root.find(SELECTORS.MODAL);\n this.header = this.modal.find(SELECTORS.HEADER);\n this.headerPromise = $.Deferred();\n this.title = this.header.find(SELECTORS.TITLE);\n this.titlePromise = $.Deferred();\n this.body = this.modal.find(SELECTORS.BODY);\n this.bodyPromise = $.Deferred();\n this.footer = this.modal.find(SELECTORS.FOOTER);\n this.footerPromise = $.Deferred();\n this.hiddenSiblings = [];\n this.isAttached = false;\n this.bodyJS = null;\n this.footerJS = null;\n this.modalCount = modalCounter++;\n this.attachmentPoint = document.createElement('div');\n document.body.append(this.attachmentPoint);\n this.focusOnClose = null;\n\n if (!this.root.is(SELECTORS.CONTAINER)) {\n Notification.exception({message: 'Element is not a modal container'});\n }\n\n if (!this.modal.length) {\n Notification.exception({message: 'Container does not contain a modal'});\n }\n\n if (!this.header.length) {\n Notification.exception({message: 'Modal is missing a header region'});\n }\n\n if (!this.title.length) {\n Notification.exception({message: 'Modal header is missing a title region'});\n }\n\n if (!this.body.length) {\n Notification.exception({message: 'Modal is missing a body region'});\n }\n\n if (!this.footer.length) {\n Notification.exception({message: 'Modal is missing a footer region'});\n }\n\n this.registerEventListeners();\n };\n\n /**\n * Attach the modal to the correct part of the page.\n *\n * If it hasn't already been added it runs any\n * javascript that has been cached until now.\n *\n * @method attachToDOM\n */\n Modal.prototype.attachToDOM = function() {\n this.getAttachmentPoint().append(this.root);\n\n if (this.isAttached) {\n return;\n }\n\n FocusLock.trapFocus(this.root[0]);\n\n // If we'd cached any JS then we can run it how that the modal is\n // attached to the DOM.\n if (this.bodyJS) {\n Templates.runTemplateJS(this.bodyJS);\n this.bodyJS = null;\n }\n\n if (this.footerJS) {\n Templates.runTemplateJS(this.footerJS);\n this.footerJS = null;\n }\n\n this.isAttached = true;\n };\n\n /**\n * Count the number of other visible modals (not including this one).\n *\n * @method countOtherVisibleModals\n * @return {int}\n */\n Modal.prototype.countOtherVisibleModals = function() {\n var count = 0;\n $('body').find(SELECTORS.CONTAINER).each(function(index, element) {\n element = $(element);\n\n // If we haven't found ourself and the element is visible.\n if (!this.root.is(element) && element.hasClass('show')) {\n count++;\n }\n }.bind(this));\n\n return count;\n };\n\n /**\n * Get the modal backdrop.\n *\n * @method getBackdrop\n * @return {object} jQuery promise\n */\n Modal.prototype.getBackdrop = function() {\n if (!backdropPromise) {\n backdropPromise = Templates.render(TEMPLATES.BACKDROP, {})\n .then(function(html) {\n var element = $(html);\n\n return new ModalBackdrop(element);\n })\n .fail(Notification.exception);\n }\n\n return backdropPromise;\n };\n\n /**\n * Get the root element of this modal.\n *\n * @method getRoot\n * @return {object} jQuery object\n */\n Modal.prototype.getRoot = function() {\n return this.root;\n };\n\n /**\n * Get the modal element of this modal.\n *\n * @method getModal\n * @return {object} jQuery object\n */\n Modal.prototype.getModal = function() {\n return this.modal;\n };\n\n /**\n * Get the modal title element.\n *\n * @method getTitle\n * @return {object} jQuery object\n */\n Modal.prototype.getTitle = function() {\n return this.title;\n };\n\n /**\n * Get the modal body element.\n *\n * @method getBody\n * @return {object} jQuery object\n */\n Modal.prototype.getBody = function() {\n return this.body;\n };\n\n /**\n * Get the modal footer element.\n *\n * @method getFooter\n * @return {object} jQuery object\n */\n Modal.prototype.getFooter = function() {\n return this.footer;\n };\n\n /**\n * Get a promise resolving to the title region.\n *\n * @method getTitlePromise\n * @return {Promise}\n */\n Modal.prototype.getTitlePromise = function() {\n return this.titlePromise;\n };\n\n /**\n * Get a promise resolving to the body region.\n *\n * @method getBodyPromise\n * @return {object} jQuery object\n */\n Modal.prototype.getBodyPromise = function() {\n return this.bodyPromise;\n };\n\n /**\n * Get a promise resolving to the footer region.\n *\n * @method getFooterPromise\n * @return {object} jQuery object\n */\n Modal.prototype.getFooterPromise = function() {\n return this.footerPromise;\n };\n\n /**\n * Get the unique modal count.\n *\n * @method getModalCount\n * @return {int}\n */\n Modal.prototype.getModalCount = function() {\n return this.modalCount;\n };\n\n /**\n * Set the modal title element.\n *\n * This method is overloaded to take either a string value for the title or a jQuery promise that is resolved with\n * HTML most commonly from a Str.get_string call.\n *\n * @method setTitle\n * @param {(string|object)} value The title string or jQuery promise which resolves to the title.\n */\n Modal.prototype.setTitle = function(value) {\n var title = this.getTitle();\n this.titlePromise = $.Deferred();\n\n this.asyncSet(value, title.html.bind(title))\n .then(function() {\n this.titlePromise.resolve(title);\n }.bind(this))\n .catch(Notification.exception);\n };\n\n /**\n * Set the modal body element.\n *\n * This method is overloaded to take either a string value for the body or a jQuery promise that is resolved with\n * HTML and Javascript most commonly from a Templates.render call.\n *\n * @method setBody\n * @param {(string|object)} value The body string or jQuery promise which resolves to the body.\n * @fires event:filterContentUpdated\n */\n Modal.prototype.setBody = function(value) {\n this.bodyPromise = $.Deferred();\n\n var body = this.getBody();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n body.html(value);\n FilterEvents.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n this.bodyPromise.resolve(body);\n } else {\n var jsPendingId = 'amd-modal-js-pending-id-' + this.getModalCount();\n M.util.js_pending(jsPendingId);\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n var contentPromise = null;\n body.css('overflow', 'hidden');\n\n // Ensure that the `value` is a jQuery Promise.\n value = $.when(value);\n\n if (value.state() == 'pending') {\n // We're still waiting for the body promise to resolve so\n // let's show a loading icon.\n var height = body.innerHeight();\n if (height < 100) {\n height = 100;\n }\n\n body.animate({height: height + 'px'}, 150);\n\n body.html('');\n contentPromise = Templates.render(TEMPLATES.LOADING, {})\n .then(function(html) {\n var loadingIcon = $(html).hide();\n body.html(loadingIcon);\n loadingIcon.fadeIn(150);\n\n // We only want the loading icon to fade out\n // when the content for the body has finished\n // loading.\n return $.when(loadingIcon.promise(), value);\n })\n .then(function(loadingIcon) {\n // Once the content has finished loading and\n // the loading icon has been shown then we can\n // fade the icon away to reveal the content.\n return loadingIcon.fadeOut(100).promise();\n })\n .then(function() {\n return value;\n });\n } else {\n // The content is already loaded so let's just display\n // it to the user. No need for a loading icon.\n contentPromise = value;\n }\n\n // Now we can actually display the content.\n contentPromise.then(function(html, js) {\n var result = null;\n\n if (this.isVisible()) {\n // If the modal is visible then we should display\n // the content gracefully for the user.\n body.css('opacity', 0);\n var currentHeight = body.innerHeight();\n body.html(html);\n // We need to clear any height values we've set here\n // in order to measure the height of the content being\n // added. This then allows us to animate the height\n // transition.\n body.css('height', '');\n var newHeight = body.innerHeight();\n body.css('height', currentHeight + 'px');\n result = body.animate(\n {height: newHeight + 'px', opacity: 1},\n {duration: 150, queue: false}\n ).promise();\n } else {\n // Since the modal isn't visible we can just immediately\n // set the content. No need to animate it.\n body.html(html);\n }\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.bodyJS = js;\n }\n }\n\n return result;\n }.bind(this))\n .then(function(result) {\n FilterEvents.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n return result;\n }.bind(this))\n .then(function() {\n this.bodyPromise.resolve(body);\n return;\n }.bind(this))\n .fail(Notification.exception)\n .always(function() {\n // When we're done displaying all of the content we need\n // to clear the custom values we've set here.\n body.css('height', '');\n body.css('overflow', '');\n body.css('opacity', '');\n M.util.js_complete(jsPendingId);\n\n return;\n })\n .fail(Notification.exception);\n }\n };\n\n /**\n * Alternative to setBody() that can be used from non-Jquery modules\n *\n * @param {Promise} promise promise that returns {html, js} object\n * @return {Promise}\n */\n Modal.prototype.setBodyContent = function(promise) {\n // Call the leegacy API for now and pass it a jQuery Promise.\n // This is a non-spec feature of jQuery and cannot be produced with spec promises.\n // We can encourage people to migrate to this approach, and in future we can swap\n // it so that setBody() calls setBodyPromise().\n return promise.then(({html, js}) => this.setBody($.when(html, js)))\n .catch(exception => {\n this.hide();\n throw exception;\n });\n };\n\n /**\n * Set the modal footer element. The footer element is made visible, if it\n * isn't already.\n *\n * This method is overloaded to take either a string\n * value for the body or a jQuery promise that is resolved with HTML and Javascript\n * most commonly from a Templates.render call.\n *\n * @method setFooter\n * @param {(string|object)} value The footer string or jQuery promise\n */\n Modal.prototype.setFooter = function(value) {\n // Make sure the footer is visible.\n this.showFooter();\n this.footerPromise = $.Deferred();\n\n var footer = this.getFooter();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n footer.html(value);\n this.footerPromise.resolve(footer);\n } else {\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n Templates.render(TEMPLATES.LOADING, {})\n .then(function(html) {\n footer.html(html);\n\n return value;\n })\n .then(function(html, js) {\n footer.html(html);\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.footerJS = js;\n }\n }\n\n return footer;\n }.bind(this))\n .then(function(footer) {\n this.footerPromise.resolve(footer);\n return;\n }.bind(this))\n .catch(Notification.exception);\n }\n };\n\n /**\n * Check if the footer has any content in it.\n *\n * @method hasFooterContent\n * @return {bool}\n */\n Modal.prototype.hasFooterContent = function() {\n return this.getFooter().children().length ? true : false;\n };\n\n /**\n * Hide the footer element.\n *\n * @method hideFooter\n */\n Modal.prototype.hideFooter = function() {\n this.getFooter().addClass('hidden');\n };\n\n /**\n * Show the footer element.\n *\n * @method showFooter\n */\n Modal.prototype.showFooter = function() {\n this.getFooter().removeClass('hidden');\n };\n\n /**\n * Mark the modal as a large modal.\n *\n * @method setLarge\n */\n Modal.prototype.setLarge = function() {\n if (this.isLarge()) {\n return;\n }\n\n this.getModal().addClass('modal-lg');\n };\n\n /**\n * Check if the modal is a large modal.\n *\n * @method isLarge\n * @return {bool}\n */\n Modal.prototype.isLarge = function() {\n return this.getModal().hasClass('modal-lg');\n };\n\n /**\n * Mark the modal as a small modal.\n *\n * @method setSmall\n */\n Modal.prototype.setSmall = function() {\n if (this.isSmall()) {\n return;\n }\n\n this.getModal().removeClass('modal-lg');\n };\n\n /**\n * Check if the modal is a small modal.\n *\n * @method isSmall\n * @return {bool}\n */\n Modal.prototype.isSmall = function() {\n return !this.getModal().hasClass('modal-lg');\n };\n\n /**\n * Set this modal to be scrollable or not.\n *\n * @method setScrollable\n * @param {bool} value Whether the modal is scrollable or not\n */\n Modal.prototype.setScrollable = function(value) {\n if (!value) {\n this.getModal()[0].classList.remove('modal-dialog-scrollable');\n return;\n }\n\n this.getModal()[0].classList.add('modal-dialog-scrollable');\n };\n\n\n /**\n * Determine the highest z-index value currently on the page.\n *\n * @method calculateZIndex\n * @return {int}\n */\n Modal.prototype.calculateZIndex = function() {\n var items = $(SELECTORS.DIALOG + ', ' + SELECTORS.MENU_BAR + ', ' + SELECTORS.HAS_Z_INDEX);\n var zIndex = parseInt(this.root.css('z-index'));\n\n items.each(function(index, item) {\n item = $(item);\n // Note that webkit browsers won't return the z-index value from the CSS stylesheet\n // if the element doesn't have a position specified. Instead it'll return \"auto\".\n var itemZIndex = item.css('z-index') ? parseInt(item.css('z-index')) : 0;\n\n if (itemZIndex > zIndex) {\n zIndex = itemZIndex;\n }\n });\n\n return zIndex;\n };\n\n /**\n * Check if this modal is visible.\n *\n * @method isVisible\n * @return {bool}\n */\n Modal.prototype.isVisible = function() {\n return this.root.hasClass('show');\n };\n\n /**\n * Check if this modal has focus.\n *\n * @method hasFocus\n * @return {bool}\n */\n Modal.prototype.hasFocus = function() {\n var target = $(document.activeElement);\n return this.root.is(target) || this.root.has(target).length;\n };\n\n /**\n * Check if this modal has CSS transitions applied.\n *\n * @method hasTransitions\n * @return {bool}\n */\n Modal.prototype.hasTransitions = function() {\n return this.getRoot().hasClass('fade');\n };\n\n /**\n * Gets the jQuery wrapped node that the Modal should be attached to.\n *\n * @returns {jQuery}\n */\n Modal.prototype.getAttachmentPoint = function() {\n return $(Fullscreen.getElement() || this.attachmentPoint);\n };\n\n /**\n * Display this modal. The modal will be attached to the DOM if it hasn't\n * already been.\n *\n * @method show\n * @returns {Promise}\n */\n Modal.prototype.show = function() {\n if (this.isVisible()) {\n return $.Deferred().resolve();\n }\n\n var pendingPromise = new Pending('core/modal:show');\n\n if (this.hasFooterContent()) {\n this.showFooter();\n } else {\n this.hideFooter();\n }\n\n this.attachToDOM();\n\n // If the focusOnClose was not set. Set the focus back to triggered element.\n if (!this.focusOnClose && document.activeElement) {\n this.focusOnClose = document.activeElement;\n }\n\n return this.getBackdrop()\n .then(function(backdrop) {\n var currentIndex = this.calculateZIndex();\n var newIndex = currentIndex + 2;\n var newBackdropIndex = newIndex - 1;\n this.root.css('z-index', newIndex);\n backdrop.setZIndex(newBackdropIndex);\n backdrop.show();\n\n this.root.removeClass('hide').addClass('show');\n this.accessibilityShow();\n this.getModal().focus();\n $('body').addClass('modal-open');\n this.root.trigger(ModalEvents.shown, this);\n\n return;\n }.bind(this))\n .then(pendingPromise.resolve);\n };\n\n /**\n * Hide this modal if it does not contain a form.\n *\n * @method hideIfNotForm\n */\n Modal.prototype.hideIfNotForm = function() {\n var formElement = this.modal.find(SELECTORS.FORM);\n if (formElement.length == 0) {\n this.hide();\n }\n };\n\n /**\n * Hide this modal.\n *\n * @method hide\n */\n Modal.prototype.hide = function() {\n this.getBackdrop().done(function(backdrop) {\n FocusLock.untrapFocus();\n\n if (!this.countOtherVisibleModals()) {\n // Hide the backdrop if we're the last open modal.\n backdrop.hide();\n $('body').removeClass('modal-open');\n }\n\n var currentIndex = parseInt(this.root.css('z-index'));\n this.root.css('z-index', '');\n backdrop.setZIndex(currentIndex - 3);\n\n this.accessibilityHide();\n\n if (this.hasTransitions()) {\n // Wait for CSS transitions to complete before hiding the element.\n this.getRoot().one('transitionend webkitTransitionEnd oTransitionEnd', function() {\n this.getRoot().removeClass('show').addClass('hide');\n }.bind(this));\n } else {\n this.getRoot().removeClass('show').addClass('hide');\n }\n\n // Ensure the modal is moved onto the body node if it is still attached to the DOM.\n if ($(document.body).find(this.getRoot()).length) {\n $(document.body).append(this.getRoot());\n }\n\n this.root.trigger(ModalEvents.hidden, this);\n }.bind(this));\n };\n\n /**\n * Remove this modal from the DOM.\n *\n * @method destroy\n */\n Modal.prototype.destroy = function() {\n this.hide();\n this.root.remove();\n this.root.trigger(ModalEvents.destroyed, this);\n this.attachmentPoint.remove();\n };\n\n /**\n * Sets the appropriate aria attributes on this dialogue and the other\n * elements in the DOM to ensure that screen readers are able to navigate\n * the dialogue popup correctly.\n *\n * @method accessibilityShow\n */\n Modal.prototype.accessibilityShow = function() {\n // Make us visible to screen readers.\n Aria.unhide(this.root.get());\n\n // Hide siblings.\n Aria.hideSiblings(this.root.get()[0]);\n };\n\n /**\n * Restores the aria visibility on the DOM elements changed when displaying\n * the dialogue popup and makes the dialogue aria hidden to allow screen\n * readers to navigate the main page correctly when the dialogue is closed.\n *\n * @method accessibilityHide\n */\n Modal.prototype.accessibilityHide = function() {\n // Unhide siblings.\n Aria.unhideSiblings(this.root.get()[0]);\n\n // Hide this modal.\n Aria.hide(this.root.get());\n };\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n Modal.prototype.registerEventListeners = function() {\n this.getRoot().on('keydown', function(e) {\n if (!this.isVisible()) {\n return;\n }\n\n if (e.keyCode == KeyCodes.escape) {\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n\n // Listen for clicks on the modal container.\n this.getRoot().click(function(e) {\n // If the click wasn't inside the modal element then we should\n // hide the modal.\n if (!$(e.target).closest(SELECTORS.MODAL).length) {\n // The check above fails to detect the click was inside the modal when the DOM tree is already changed.\n // So, we check if we can still find the container element or not. If not, then the DOM tree is changed.\n // It's best not to hide the modal in that case.\n if ($(e.target).closest(SELECTORS.CONTAINER).length) {\n var outsideClickEvent = $.Event(ModalEvents.outsideClick);\n this.getRoot().trigger(outsideClickEvent, this);\n\n if (!outsideClickEvent.isDefaultPrevented()) {\n this.hideIfNotForm();\n }\n }\n }\n }.bind(this));\n\n CustomEvents.define(this.getModal(), [CustomEvents.events.activate]);\n this.getModal().on(CustomEvents.events.activate, SELECTORS.HIDE, function(e, data) {\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n data.originalEvent.preventDefault();\n }.bind(this));\n\n this.getRoot().on(ModalEvents.hidden, () => {\n if (this.focusOnClose) {\n // Focus on the element that actually triggers the modal.\n this.focusOnClose.focus();\n }\n });\n };\n\n /**\n * Register a listener to close the dialogue when the cancel button is pressed.\n *\n * @method registerCloseOnCancel\n */\n Modal.prototype.registerCloseOnCancel = function() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('cancel'), function(e, data) {\n var cancelEvent = $.Event(ModalEvents.cancel);\n this.getRoot().trigger(cancelEvent, this);\n\n if (!cancelEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n };\n\n /**\n * Register a listener to close the dialogue when the save button is pressed.\n *\n * @method registerCloseOnSave\n */\n Modal.prototype.registerCloseOnSave = function() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('save'), function(e, data) {\n var saveEvent = $.Event(ModalEvents.save);\n this.getRoot().trigger(saveEvent, this);\n\n if (!saveEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n };\n\n\n /**\n * Register a listener to close the dialogue when the delete button is pressed.\n *\n * @method registerCloseOnDelete\n */\n Modal.prototype.registerCloseOnDelete = function() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('delete'), function(e, data) {\n var deleteEvent = $.Event(ModalEvents.delete);\n this.getRoot().trigger(deleteEvent, this);\n\n if (!deleteEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n }.bind(this));\n };\n\n /**\n * Set or resolve and set the value using the function.\n *\n * @method asyncSet\n * @param {(string|object)} value The string or jQuery promise.\n * @param {function} setFunction The setter\n * @return {Promise}\n */\n Modal.prototype.asyncSet = function(value, setFunction) {\n var p = value;\n if (typeof value !== 'object' || !value.hasOwnProperty('then')) {\n p = $.Deferred();\n p.resolve(value);\n }\n\n p.then(function(content) {\n setFunction(content);\n\n return;\n })\n .fail(Notification.exception);\n\n return p;\n };\n\n /**\n * Set the title text of a button.\n *\n * This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with\n * text most commonly from a Str.get_string call.\n *\n * @param {DOMString} action The action of the button\n * @param {(String|object)} value The button text, or a promise which will resolve to it\n * @returns {Promise}\n */\n Modal.prototype.setButtonText = function(action, value) {\n const button = this.getFooter().find(this.getActionSelector(action));\n\n if (!button) {\n throw new Error(\"Unable to find the '\" + action + \"' button\");\n }\n\n return this.asyncSet(value, button.text.bind(button));\n };\n\n /**\n * Get the Selector for an action.\n *\n * @param {String} action\n * @returns {DOMString}\n */\n Modal.prototype.getActionSelector = function(action) {\n return \"[data-action='\" + action + \"']\";\n };\n\n /**\n * Set the flag to remove the modal from the DOM on close.\n *\n * @param {Boolean} remove\n */\n Modal.prototype.setRemoveOnClose = function(remove) {\n this.removeOnClose = remove;\n };\n\n /**\n * Set the return element for the modal.\n *\n * @param {Element|jQuery} element Element to focus when the modal is closed\n */\n Modal.prototype.setReturnElement = function(element) {\n this.focusOnClose = element;\n };\n\n /**\n * Set the a button enabled or disabled.\n *\n * @param {DOMString} action The action of the button\n * @param {Boolean} disabled the new disabled value\n */\n Modal.prototype.setButtonDisabled = function(action, disabled) {\n const button = this.getFooter().find(this.getActionSelector(action));\n\n if (!button) {\n throw new Error(\"Unable to find the '\" + action + \"' button\");\n }\n if (disabled) {\n button.attr('disabled', '');\n } else {\n button.removeAttr('disabled');\n }\n };\n\n return Modal;\n});\n"],"names":["define","$","Templates","Notification","KeyCodes","CustomEvents","ModalBackdrop","FilterEvents","ModalEvents","FocusLock","Pending","Aria","Fullscreen","backdropPromise","SELECTORS","TEMPLATES","modalCounter","Modal","root","modal","this","find","header","headerPromise","Deferred","title","titlePromise","body","bodyPromise","footer","footerPromise","hiddenSiblings","isAttached","bodyJS","footerJS","modalCount","attachmentPoint","document","createElement","append","focusOnClose","is","exception","message","length","registerEventListeners","prototype","attachToDOM","getAttachmentPoint","trapFocus","runTemplateJS","countOtherVisibleModals","count","each","index","element","hasClass","bind","getBackdrop","render","then","html","fail","getRoot","getModal","getTitle","getBody","getFooter","getTitlePromise","getBodyPromise","getFooterPromise","getModalCount","setTitle","value","asyncSet","resolve","catch","setBody","notifyFilterContentUpdated","trigger","bodyRendered","jsPendingId","M","util","js_pending","contentPromise","css","when","state","height","innerHeight","animate","loadingIcon","hide","fadeIn","promise","fadeOut","js","result","isVisible","currentHeight","newHeight","opacity","duration","queue","always","js_complete","setBodyContent","_ref","setFooter","showFooter","hasFooterContent","children","hideFooter","addClass","removeClass","setLarge","isLarge","setSmall","isSmall","setScrollable","classList","add","remove","calculateZIndex","items","zIndex","parseInt","item","itemZIndex","hasFocus","target","activeElement","has","hasTransitions","getElement","show","pendingPromise","backdrop","newIndex","newBackdropIndex","setZIndex","accessibilityShow","focus","shown","hideIfNotForm","done","untrapFocus","currentIndex","accessibilityHide","one","hidden","destroy","destroyed","unhide","get","hideSiblings","unhideSiblings","on","e","keyCode","escape","removeOnClose","click","closest","outsideClickEvent","Event","outsideClick","isDefaultPrevented","events","activate","data","originalEvent","preventDefault","registerCloseOnCancel","getActionSelector","cancelEvent","cancel","registerCloseOnSave","saveEvent","save","registerCloseOnDelete","deleteEvent","delete","setFunction","p","hasOwnProperty","content","setButtonText","action","button","Error","text","setRemoveOnClose","setReturnElement","setButtonDisabled","disabled","attr","removeAttr"],"mappings":";;;;;;;;AAuBAA,oBAAO,CACH,SACA,iBACA,oBACA,iBACA,iCACA,sBACA,sBACA,oBACA,4BACA,eACA,YACA,oBACD,SACCC,EACAC,UACAC,aACAC,SACAC,aACAC,cACAC,aACAC,YACAC,UACAC,QACAC,KACAC,gBA0BIC,gBAvBAC,oBACW,kCADXA,gBAEO,wBAFPA,iBAGQ,yBAHRA,gBAIO,wBAJPA,eAKM,uBALNA,iBAMQ,yBANRA,eAOM,uBAPNA,iBAQQ,gBARRA,eASM,OATNA,mBAUU,iBAVVA,sBAWa,qBAIbC,kBACS,eADTA,mBAEU,sBAYVC,aAAe,EAOfC,MAAQ,SAASC,WACZA,KAAOjB,EAAEiB,WACTC,MAAQC,KAAKF,KAAKG,KAAKP,sBACvBQ,OAASF,KAAKD,MAAME,KAAKP,uBACzBS,cAAgBtB,EAAEuB,gBAClBC,MAAQL,KAAKE,OAAOD,KAAKP,sBACzBY,aAAezB,EAAEuB,gBACjBG,KAAOP,KAAKD,MAAME,KAAKP,qBACvBc,YAAc3B,EAAEuB,gBAChBK,OAAST,KAAKD,MAAME,KAAKP,uBACzBgB,cAAgB7B,EAAEuB,gBAClBO,eAAiB,QACjBC,YAAa,OACbC,OAAS,UACTC,SAAW,UACXC,WAAanB,oBACboB,gBAAkBC,SAASC,cAAc,OAC9CD,SAASV,KAAKY,OAAOnB,KAAKgB,sBACrBI,aAAe,KAEfpB,KAAKF,KAAKuB,GAAG3B,sBACdX,aAAauC,UAAU,CAACC,QAAS,qCAGhCvB,KAAKD,MAAMyB,QACZzC,aAAauC,UAAU,CAACC,QAAS,uCAGhCvB,KAAKE,OAAOsB,QACbzC,aAAauC,UAAU,CAACC,QAAS,qCAGhCvB,KAAKK,MAAMmB,QACZzC,aAAauC,UAAU,CAACC,QAAS,2CAGhCvB,KAAKO,K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qJ,kBAAoB,SAASN,OAAQO,gBAC3CN,OAAS1K,KAAK+C,YAAY9C,KAAKD,KAAK2J,kBAAkBc,aAEvDC,aACK,IAAIC,MAAM,uBAAyBF,OAAS,YAElDO,SACAN,OAAOO,KAAK,WAAY,IAExBP,OAAOQ,WAAW,aAInBrL"} \ No newline at end of file +{"version":3,"file":"modal.min.js","sources":["../src/modal.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Contain the logic for modals.\n *\n * @module core/modal\n * @class core/modal\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport * as Templates from 'core/templates';\nimport * as Notification from 'core/notification';\nimport * as KeyCodes from 'core/key_codes';\nimport ModalBackdrop from 'core/modal_backdrop';\nimport ModalEvents from 'core/modal_events';\nimport Pending from 'core/pending';\nimport * as CustomEvents from 'core/custom_interaction_events';\nimport * as FilterEvents from 'core_filters/events';\nimport * as FocusLock from 'core/local/aria/focuslock';\nimport * as Aria from 'core/aria';\nimport * as Fullscreen from 'core/fullscreen';\n\nconst SELECTORS = {\n CONTAINER: '[data-region=\"modal-container\"]',\n MODAL: '[data-region=\"modal\"]',\n HEADER: '[data-region=\"header\"]',\n TITLE: '[data-region=\"title\"]',\n BODY: '[data-region=\"body\"]',\n FOOTER: '[data-region=\"footer\"]',\n HIDE: '[data-action=\"hide\"]',\n DIALOG: '[role=dialog]',\n FORM: 'form',\n MENU_BAR: '[role=menubar]',\n HAS_Z_INDEX: '.moodle-has-zindex',\n CAN_RECEIVE_FOCUS: 'input:not([type=\"hidden\"]), a[href], button, textarea, select, [tabindex]',\n};\n\nconst TEMPLATES = {\n LOADING: 'core/loading',\n BACKDROP: 'core/modal_backdrop',\n};\n\nexport default class Modal {\n /** @var {Promise} Module singleton for the backdrop to be reused by all Modal instances */\n backdropPromise = null;\n\n /**\n * @var {Number} A counter that gets incremented for each modal created.\n * This can be used to generate unique values for the modals.\n */\n static modalCounter = 0;\n\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n constructor(root) {\n this.root = $(root);\n\n this.modal = this.root.find(SELECTORS.MODAL);\n this.header = this.modal.find(SELECTORS.HEADER);\n this.headerPromise = $.Deferred();\n this.title = this.header.find(SELECTORS.TITLE);\n this.titlePromise = $.Deferred();\n this.body = this.modal.find(SELECTORS.BODY);\n this.bodyPromise = $.Deferred();\n this.footer = this.modal.find(SELECTORS.FOOTER);\n this.footerPromise = $.Deferred();\n this.hiddenSiblings = [];\n this.isAttached = false;\n this.bodyJS = null;\n this.footerJS = null;\n this.modalCount = this.modalCounter++;\n this.attachmentPoint = document.createElement('div');\n document.body.append(this.attachmentPoint);\n this.focusOnClose = null;\n\n if (!this.root.is(SELECTORS.CONTAINER)) {\n Notification.exception({message: 'Element is not a modal container'});\n }\n\n if (!this.modal.length) {\n Notification.exception({message: 'Container does not contain a modal'});\n }\n\n if (!this.header.length) {\n Notification.exception({message: 'Modal is missing a header region'});\n }\n\n if (!this.title.length) {\n Notification.exception({message: 'Modal header is missing a title region'});\n }\n\n if (!this.body.length) {\n Notification.exception({message: 'Modal is missing a body region'});\n }\n\n if (!this.footer.length) {\n Notification.exception({message: 'Modal is missing a footer region'});\n }\n\n this.registerEventListeners();\n }\n\n /**\n * Attach the modal to the correct part of the page.\n *\n * If it hasn't already been added it runs any\n * javascript that has been cached until now.\n *\n * @method attachToDOM\n */\n attachToDOM() {\n this.getAttachmentPoint().append(this.root);\n\n if (this.isAttached) {\n return;\n }\n\n FocusLock.trapFocus(this.root[0]);\n\n // If we'd cached any JS then we can run it how that the modal is\n // attached to the DOM.\n if (this.bodyJS) {\n Templates.runTemplateJS(this.bodyJS);\n this.bodyJS = null;\n }\n\n if (this.footerJS) {\n Templates.runTemplateJS(this.footerJS);\n this.footerJS = null;\n }\n\n this.isAttached = true;\n }\n\n /**\n * Count the number of other visible modals (not including this one).\n *\n * @method countOtherVisibleModals\n * @return {int}\n */\n countOtherVisibleModals() {\n let count = 0;\n $('body').find(SELECTORS.CONTAINER).each((index, element) => {\n element = $(element);\n\n // If we haven't found ourself and the element is visible.\n if (!this.root.is(element) && element.hasClass('show')) {\n count++;\n }\n });\n\n return count;\n }\n\n /**\n * Get the modal backdrop.\n *\n * @method getBackdrop\n * @return {object} jQuery promise\n */\n getBackdrop() {\n if (!Modal.backdropPromise) {\n Modal.backdropPromise = Templates.render(TEMPLATES.BACKDROP, {})\n .then((html) => new ModalBackdrop($(html)))\n .catch(Notification.exception);\n }\n\n return Modal.backdropPromise;\n }\n\n /**\n * Get the root element of this modal.\n *\n * @method getRoot\n * @return {object} jQuery object\n */\n getRoot() {\n return this.root;\n }\n\n /**\n * Get the modal element of this modal.\n *\n * @method getModal\n * @return {object} jQuery object\n */\n getModal() {\n return this.modal;\n }\n\n /**\n * Get the modal title element.\n *\n * @method getTitle\n * @return {object} jQuery object\n */\n getTitle() {\n return this.title;\n }\n\n /**\n * Get the modal body element.\n *\n * @method getBody\n * @return {object} jQuery object\n */\n getBody() {\n return this.body;\n }\n\n /**\n * Get the modal footer element.\n *\n * @method getFooter\n * @return {object} jQuery object\n */\n getFooter() {\n return this.footer;\n }\n\n /**\n * Get a promise resolving to the title region.\n *\n * @method getTitlePromise\n * @return {Promise}\n */\n getTitlePromise() {\n return this.titlePromise;\n }\n\n /**\n * Get a promise resolving to the body region.\n *\n * @method getBodyPromise\n * @return {object} jQuery object\n */\n getBodyPromise() {\n return this.bodyPromise;\n }\n\n /**\n * Get a promise resolving to the footer region.\n *\n * @method getFooterPromise\n * @return {object} jQuery object\n */\n getFooterPromise() {\n return this.footerPromise;\n }\n\n /**\n * Get the unique modal count.\n *\n * @method getModalCount\n * @return {int}\n */\n getModalCount() {\n return this.modalCount;\n }\n\n /**\n * Set the modal title element.\n *\n * This method is overloaded to take either a string value for the title or a jQuery promise that is resolved with\n * HTML most commonly from a Str.get_string call.\n *\n * @method setTitle\n * @param {(string|object)} value The title string or jQuery promise which resolves to the title.\n */\n setTitle(value) {\n const title = this.getTitle();\n this.titlePromise = $.Deferred();\n\n this.asyncSet(value, title.html.bind(title))\n .then(() => {\n this.titlePromise.resolve(title);\n return;\n })\n .catch(Notification.exception);\n }\n\n /**\n * Set the modal body element.\n *\n * This method is overloaded to take either a string value for the body or a jQuery promise that is resolved with\n * HTML and Javascript most commonly from a Templates.render call.\n *\n * @method setBody\n * @param {(string|object)} value The body string or jQuery promise which resolves to the body.\n * @fires event:filterContentUpdated\n */\n setBody(value) {\n this.bodyPromise = $.Deferred();\n\n const body = this.getBody();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n body.html(value);\n FilterEvents.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n this.bodyPromise.resolve(body);\n } else {\n const modalPromise = new Pending(`amd-modal-js-pending-id-${this.getModalCount()}`);\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n let contentPromise = null;\n body.css('overflow', 'hidden');\n\n // Ensure that the `value` is a jQuery Promise.\n value = $.when(value);\n\n if (value.state() == 'pending') {\n // We're still waiting for the body promise to resolve so\n // let's show a loading icon.\n let height = body.innerHeight();\n if (height < 100) {\n height = 100;\n }\n\n body.animate({height: `${height}px`}, 150);\n\n body.html('');\n contentPromise = Templates.render(TEMPLATES.LOADING, {})\n .then((html) => {\n const loadingIcon = $(html).hide();\n body.html(loadingIcon);\n loadingIcon.fadeIn(150);\n\n // We only want the loading icon to fade out\n // when the content for the body has finished\n // loading.\n return $.when(loadingIcon.promise(), value);\n })\n .then((loadingIcon) => {\n // Once the content has finished loading and\n // the loading icon has been shown then we can\n // fade the icon away to reveal the content.\n return loadingIcon.fadeOut(100).promise();\n })\n .then(() => {\n return value;\n });\n } else {\n // The content is already loaded so let's just display\n // it to the user. No need for a loading icon.\n contentPromise = value;\n }\n\n // Now we can actually display the content.\n contentPromise.then((html, js) => {\n let result = null;\n\n if (this.isVisible()) {\n // If the modal is visible then we should display\n // the content gracefully for the user.\n body.css('opacity', 0);\n const currentHeight = body.innerHeight();\n body.html(html);\n // We need to clear any height values we've set here\n // in order to measure the height of the content being\n // added. This then allows us to animate the height\n // transition.\n body.css('height', '');\n const newHeight = body.innerHeight();\n body.css('height', `${currentHeight}px`);\n result = body.animate(\n {height: `${newHeight}px`, opacity: 1},\n {duration: 150, queue: false}\n ).promise();\n } else {\n // Since the modal isn't visible we can just immediately\n // set the content. No need to animate it.\n body.html(html);\n }\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.bodyJS = js;\n }\n }\n\n return result;\n })\n .then((result) => {\n FilterEvents.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n return result;\n })\n .then(() => {\n this.bodyPromise.resolve(body);\n return;\n })\n .catch(Notification.exception)\n .always(() => {\n // When we're done displaying all of the content we need\n // to clear the custom values we've set here.\n body.css('height', '');\n body.css('overflow', '');\n body.css('opacity', '');\n modalPromise.resolve();\n\n return;\n });\n }\n }\n\n /**\n * Alternative to setBody() that can be used from non-Jquery modules\n *\n * @param {Promise} promise promise that returns {html, js} object\n * @return {Promise}\n */\n setBodyContent(promise) {\n // Call the leegacy API for now and pass it a jQuery Promise.\n // This is a non-spec feature of jQuery and cannot be produced with spec promises.\n // We can encourage people to migrate to this approach, and in future we can swap\n // it so that setBody() calls setBodyPromise().\n return promise.then(({html, js}) => this.setBody($.when(html, js)))\n .catch(exception => {\n this.hide();\n throw exception;\n });\n }\n\n /**\n * Set the modal footer element. The footer element is made visible, if it\n * isn't already.\n *\n * This method is overloaded to take either a string\n * value for the body or a jQuery promise that is resolved with HTML and Javascript\n * most commonly from a Templates.render call.\n *\n * @method setFooter\n * @param {(string|object)} value The footer string or jQuery promise\n */\n setFooter(value) {\n // Make sure the footer is visible.\n this.showFooter();\n this.footerPromise = $.Deferred();\n\n const footer = this.getFooter();\n\n if (typeof value === 'string') {\n // Just set the value if it's a string.\n footer.html(value);\n this.footerPromise.resolve(footer);\n } else {\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n Templates.render(TEMPLATES.LOADING, {})\n .then((html) => {\n footer.html(html);\n\n return value;\n })\n .then((html, js) => {\n footer.html(html);\n\n if (js) {\n if (this.isAttached) {\n // If we're in the DOM then run the JS immediately.\n Templates.runTemplateJS(js);\n } else {\n // Otherwise cache it to be run when we're attached.\n this.footerJS = js;\n }\n }\n\n return footer;\n })\n .then((footer) => {\n this.footerPromise.resolve(footer);\n return;\n })\n .catch(Notification.exception);\n }\n }\n\n /**\n * Check if the footer has any content in it.\n *\n * @method hasFooterContent\n * @return {bool}\n */\n hasFooterContent() {\n return this.getFooter().children().length ? true : false;\n }\n\n /**\n * Hide the footer element.\n *\n * @method hideFooter\n */\n hideFooter() {\n this.getFooter().addClass('hidden');\n }\n\n /**\n * Show the footer element.\n *\n * @method showFooter\n */\n showFooter() {\n this.getFooter().removeClass('hidden');\n }\n\n /**\n * Mark the modal as a large modal.\n *\n * @method setLarge\n */\n setLarge() {\n if (this.isLarge()) {\n return;\n }\n\n this.getModal().addClass('modal-lg');\n }\n\n /**\n * Check if the modal is a large modal.\n *\n * @method isLarge\n * @return {bool}\n */\n isLarge() {\n return this.getModal().hasClass('modal-lg');\n }\n\n /**\n * Mark the modal as a small modal.\n *\n * @method setSmall\n */\n setSmall() {\n if (this.isSmall()) {\n return;\n }\n\n this.getModal().removeClass('modal-lg');\n }\n\n /**\n * Check if the modal is a small modal.\n *\n * @method isSmall\n * @return {bool}\n */\n isSmall() {\n return !this.getModal().hasClass('modal-lg');\n }\n\n /**\n * Set this modal to be scrollable or not.\n *\n * @method setScrollable\n * @param {bool} value Whether the modal is scrollable or not\n */\n setScrollable(value) {\n if (!value) {\n this.getModal()[0].classList.remove('modal-dialog-scrollable');\n return;\n }\n\n this.getModal()[0].classList.add('modal-dialog-scrollable');\n }\n\n\n /**\n * Determine the highest z-index value currently on the page.\n *\n * @method calculateZIndex\n * @return {int}\n */\n calculateZIndex() {\n const items = $(`${SELECTORS.DIALOG}, ${SELECTORS.MENU_BAR}, ${SELECTORS.HAS_Z_INDEX}`);\n let zIndex = parseInt(this.root.css('z-index'));\n\n items.each((index, item) => {\n item = $(item);\n // Note that webkit browsers won't return the z-index value from the CSS stylesheet\n // if the element doesn't have a position specified. Instead it'll return \"auto\".\n const itemZIndex = item.css('z-index') ? parseInt(item.css('z-index')) : 0;\n\n if (itemZIndex > zIndex) {\n zIndex = itemZIndex;\n }\n });\n\n return zIndex;\n }\n\n /**\n * Check if this modal is visible.\n *\n * @method isVisible\n * @return {bool}\n */\n isVisible() {\n return this.root.hasClass('show');\n }\n\n /**\n * Check if this modal has focus.\n *\n * @method hasFocus\n * @return {bool}\n */\n hasFocus() {\n const target = $(document.activeElement);\n return this.root.is(target) || this.root.has(target).length;\n }\n\n /**\n * Check if this modal has CSS transitions applied.\n *\n * @method hasTransitions\n * @return {bool}\n */\n hasTransitions() {\n return this.getRoot().hasClass('fade');\n }\n\n /**\n * Gets the jQuery wrapped node that the Modal should be attached to.\n *\n * @returns {jQuery}\n */\n getAttachmentPoint() {\n return $(Fullscreen.getElement() || this.attachmentPoint);\n }\n\n /**\n * Display this modal. The modal will be attached to the DOM if it hasn't\n * already been.\n *\n * @method show\n * @returns {Promise}\n */\n show() {\n if (this.isVisible()) {\n return $.Deferred().resolve();\n }\n\n const pendingPromise = new Pending('core/modal:show');\n\n if (this.hasFooterContent()) {\n this.showFooter();\n } else {\n this.hideFooter();\n }\n\n this.attachToDOM();\n\n // If the focusOnClose was not set. Set the focus back to triggered element.\n if (!this.focusOnClose && document.activeElement) {\n this.focusOnClose = document.activeElement;\n }\n\n return this.getBackdrop()\n .then((backdrop) => {\n const currentIndex = this.calculateZIndex();\n const newIndex = currentIndex + 2;\n const newBackdropIndex = newIndex - 1;\n this.root.css('z-index', newIndex);\n backdrop.setZIndex(newBackdropIndex);\n backdrop.show();\n\n this.root.removeClass('hide').addClass('show');\n this.accessibilityShow();\n this.getModal().focus();\n $('body').addClass('modal-open');\n this.root.trigger(ModalEvents.shown, this);\n\n return;\n })\n .then(pendingPromise.resolve);\n }\n\n /**\n * Hide this modal if it does not contain a form.\n *\n * @method hideIfNotForm\n */\n hideIfNotForm() {\n const formElement = this.modal.find(SELECTORS.FORM);\n if (formElement.length == 0) {\n this.hide();\n }\n }\n\n /**\n * Hide this modal.\n *\n * @method hide\n */\n hide() {\n this.getBackdrop().done((backdrop) => {\n FocusLock.untrapFocus();\n\n if (!this.countOtherVisibleModals()) {\n // Hide the backdrop if we're the last open modal.\n backdrop.hide();\n $('body').removeClass('modal-open');\n }\n\n const currentIndex = parseInt(this.root.css('z-index'));\n this.root.css('z-index', '');\n backdrop.setZIndex(currentIndex - 3);\n\n this.accessibilityHide();\n\n if (this.hasTransitions()) {\n // Wait for CSS transitions to complete before hiding the element.\n this.getRoot().one('transitionend webkitTransitionEnd oTransitionEnd', () => {\n this.getRoot().removeClass('show').addClass('hide');\n });\n } else {\n this.getRoot().removeClass('show').addClass('hide');\n }\n\n // Ensure the modal is moved onto the body node if it is still attached to the DOM.\n if ($(document.body).find(this.getRoot()).length) {\n $(document.body).append(this.getRoot());\n }\n\n this.root.trigger(ModalEvents.hidden, this);\n });\n }\n\n /**\n * Remove this modal from the DOM.\n *\n * @method destroy\n */\n destroy() {\n this.hide();\n this.root.remove();\n this.root.trigger(ModalEvents.destroyed, this);\n this.attachmentPoint.remove();\n }\n\n /**\n * Sets the appropriate aria attributes on this dialogue and the other\n * elements in the DOM to ensure that screen readers are able to navigate\n * the dialogue popup correctly.\n *\n * @method accessibilityShow\n */\n accessibilityShow() {\n // Make us visible to screen readers.\n Aria.unhide(this.root.get());\n\n // Hide siblings.\n Aria.hideSiblings(this.root.get()[0]);\n }\n\n /**\n * Restores the aria visibility on the DOM elements changed when displaying\n * the dialogue popup and makes the dialogue aria hidden to allow screen\n * readers to navigate the main page correctly when the dialogue is closed.\n *\n * @method accessibilityHide\n */\n accessibilityHide() {\n // Unhide siblings.\n Aria.unhideSiblings(this.root.get()[0]);\n\n // Hide this modal.\n Aria.hide(this.root.get());\n }\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n registerEventListeners() {\n this.getRoot().on('keydown', (e) => {\n if (!this.isVisible()) {\n return;\n }\n\n if (e.keyCode == KeyCodes.escape) {\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n });\n\n // Listen for clicks on the modal container.\n this.getRoot().click((e) => {\n // If the click wasn't inside the modal element then we should\n // hide the modal.\n if (!$(e.target).closest(SELECTORS.MODAL).length) {\n // The check above fails to detect the click was inside the modal when the DOM tree is already changed.\n // So, we check if we can still find the container element or not. If not, then the DOM tree is changed.\n // It's best not to hide the modal in that case.\n if ($(e.target).closest(SELECTORS.CONTAINER).length) {\n const outsideClickEvent = $.Event(ModalEvents.outsideClick);\n this.getRoot().trigger(outsideClickEvent, this);\n\n if (!outsideClickEvent.isDefaultPrevented()) {\n this.hideIfNotForm();\n }\n }\n }\n });\n\n CustomEvents.define(this.getModal(), [CustomEvents.events.activate]);\n this.getModal().on(CustomEvents.events.activate, SELECTORS.HIDE, (e, data) => {\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n data.originalEvent.preventDefault();\n });\n\n this.getRoot().on(ModalEvents.hidden, () => {\n if (this.focusOnClose) {\n // Focus on the element that actually triggers the modal.\n this.focusOnClose.focus();\n }\n });\n }\n\n /**\n * Register a listener to close the dialogue when the cancel button is pressed.\n *\n * @method registerCloseOnCancel\n */\n registerCloseOnCancel() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('cancel'), (e, data) => {\n const cancelEvent = $.Event(ModalEvents.cancel);\n this.getRoot().trigger(cancelEvent, this);\n\n if (!cancelEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n });\n }\n\n /**\n * Register a listener to close the dialogue when the save button is pressed.\n *\n * @method registerCloseOnSave\n */\n registerCloseOnSave() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('save'), (e, data) => {\n const saveEvent = $.Event(ModalEvents.save);\n this.getRoot().trigger(saveEvent, this);\n\n if (!saveEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n });\n }\n\n\n /**\n * Register a listener to close the dialogue when the delete button is pressed.\n *\n * @method registerCloseOnDelete\n */\n registerCloseOnDelete() {\n // Handle the clicking of the Cancel button.\n this.getModal().on(CustomEvents.events.activate, this.getActionSelector('delete'), (e, data) => {\n const deleteEvent = $.Event(ModalEvents.delete);\n this.getRoot().trigger(deleteEvent, this);\n\n if (!deleteEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n\n if (this.removeOnClose) {\n this.destroy();\n } else {\n this.hide();\n }\n }\n });\n }\n\n /**\n * Set or resolve and set the value using the function.\n *\n * @method asyncSet\n * @param {(string|object)} value The string or jQuery promise.\n * @param {function} setFunction The setter\n * @return {Promise}\n */\n asyncSet(value, setFunction) {\n var p = value;\n if (typeof value !== 'object' || !value.hasOwnProperty('then')) {\n p = $.Deferred();\n p.resolve(value);\n }\n\n p.then((content) => {\n setFunction(content);\n\n return;\n })\n .catch(Notification.exception);\n\n return p;\n }\n\n /**\n * Set the title text of a button.\n *\n * This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with\n * text most commonly from a Str.get_string call.\n *\n * @param {DOMString} action The action of the button\n * @param {(String|object)} value The button text, or a promise which will resolve to it\n * @returns {Promise}\n */\n setButtonText(action, value) {\n const button = this.getFooter().find(this.getActionSelector(action));\n\n if (!button) {\n throw new Error(\"Unable to find the '\" + action + \"' button\");\n }\n\n return this.asyncSet(value, button.text.bind(button));\n }\n\n /**\n * Get the Selector for an action.\n *\n * @param {String} action\n * @returns {DOMString}\n */\n getActionSelector(action) {\n return \"[data-action='\" + action + \"']\";\n }\n\n /**\n * Set the flag to remove the modal from the DOM on close.\n *\n * @param {Boolean} remove\n */\n setRemoveOnClose(remove) {\n this.removeOnClose = remove;\n }\n\n /**\n * Set the return element for the modal.\n *\n * @param {Element|jQuery} element Element to focus when the modal is closed\n */\n setReturnElement(element) {\n this.focusOnClose = element;\n }\n\n /**\n * Set the a button enabled or disabled.\n *\n * @param {DOMString} action The action of the button\n * @param {Boolean} disabled the new disabled value\n */\n setButtonDisabled(action, disabled) {\n const button = this.getFooter().find(this.getActionSelector(action));\n\n if (!button) {\n throw new Error(\"Unable to find the '\" + action + \"' button\");\n }\n if (disabled) {\n button.attr('disabled', '');\n } else {\n button.removeAttr('disabled');\n }\n }\n}\n"],"names":["SELECTORS","TEMPLATES","Modal","constructor","root","modal","this","find","header","headerPromise","$","Deferred","title","titlePromise","body","bodyPromise","footer","footerPromise","hiddenSiblings","isAttached","bodyJS","footerJS","modalCount","modalCounter","attachmentPoint","document","createElement","append","focusOnClose","is","Notification","exception","message","length","registerEventListeners","attachToDOM","getAttachmentPoint","FocusLock","trapFocus","Templates","runTemplateJS","countOtherVisibleModals","count","each","index","element","hasClass","getBackdrop","backdropPromise","render","then","html","ModalBackdrop","catch","getRoot","getModal","getTitle","getBody","getFooter","getTitlePromise","getBodyPromise","getFooterPromise","getModalCount","setTitle","value","asyncSet","bind","resolve","setBody","FilterEvents","notifyFilterContentUpdated","trigger","ModalEvents","bodyRendered","modalPromise","Pending","contentPromise","css","when","state","height","innerHeight","animate","loadingIcon","hide","fadeIn","promise","fadeOut","js","result","isVisible","currentHeight","newHeight","opacity","duration","queue","always","setBodyContent","_ref","setFooter","showFooter","hasFooterContent","children","hideFooter","addClass","removeClass","setLarge","isLarge","setSmall","isSmall","setScrollable","classList","add","remove","calculateZIndex","items","zIndex","parseInt","item","itemZIndex","hasFocus","target","activeElement","has","hasTransitions","Fullscreen","getElement","show","pendingPromise","backdrop","newIndex","newBackdropIndex","setZIndex","accessibilityShow","focus","shown","hideIfNotForm","done","untrapFocus","currentIndex","accessibilityHide","one","hidden","destroy","destroyed","Aria","unhide","get","hideSiblings","unhideSiblings","on","e","keyCode","KeyCodes","escape","removeOnClose","click","closest","outsideClickEvent","Event","outsideClick","isDefaultPrevented","CustomEvents","define","events","activate","data","originalEvent","preventDefault","registerCloseOnCancel","getActionSelector","cancelEvent","cancel","registerCloseOnSave","saveEvent","save","registerCloseOnDelete","deleteEvent","delete","setFunction","p","hasOwnProperty","content","setButtonText","action","button","Error","text","setRemoveOnClose","setReturnElement","setButtonDisabled","disabled","attr","removeAttr"],"mappings":"itEAqCMA,oBACS,kCADTA,gBAEK,wBAFLA,iBAGM,yBAHNA,gBAIK,wBAJLA,eAKI,uBALJA,iBAMM,yBANNA,eAOI,uBAPJA,iBAQM,gBARNA,eASI,OATJA,mBAUQ,iBAVRA,sBAWW,qBAIXC,kBACO,eADPA,mBAEQ,4BAGOC,MAgBjBC,YAAYC,6CAdM,WAeTA,MAAO,mBAAEA,WAETC,MAAQC,KAAKF,KAAKG,KAAKP,sBACvBQ,OAASF,KAAKD,MAAME,KAAKP,uBACzBS,cAAgBC,gBAAEC,gBAClBC,MAAQN,KAAKE,OAAOD,KAAKP,sBACzBa,aAAeH,gBAAEC,gBACjBG,KAAOR,KAAKD,MAAME,KAAKP,qBACvBe,YAAcL,gBAAEC,gBAChBK,OAASV,KAAKD,MAAME,KAAKP,uBACzBiB,cAAgBP,gBAAEC,gBAClBO,eAAiB,QACjBC,YAAa,OACbC,OAA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AgB1C,OAQzB4E,iBAAiBhJ,cACRjB,aAAeiB,QASxBiJ,kBAAkBN,OAAQO,gBAChBN,OAASnL,KAAKoD,YAAYnD,KAAKD,KAAKoK,kBAAkBc,aAEvDC,aACK,IAAIC,MAAM,uBAAyBF,OAAS,YAElDO,SACAN,OAAOO,KAAK,WAAY,IAExBP,OAAOQ,WAAW,2DA17BT/L,qBAQK"} \ No newline at end of file diff --git a/lib/amd/src/first.js b/lib/amd/src/first.js index 10eb230575f..1b35e752ed1 100644 --- a/lib/amd/src/first.js +++ b/lib/amd/src/first.js @@ -26,10 +26,13 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 2.9 */ -define(['jquery'], function($) { - $(document).bind("ajaxStart", function() { - M.util.js_pending('jq'); - }).bind("ajaxStop", function() { - M.util.js_complete('jq'); - }); + +import $ from 'jquery'; + +$(document) +.bind("ajaxStart", function() { + M.util.js_pending('jq'); +}) +.bind("ajaxStop", function() { + M.util.js_complete('jq'); }); diff --git a/lib/amd/src/modal.js b/lib/amd/src/modal.js index 79f861b3ea2..0ec52e3df1e 100644 --- a/lib/amd/src/modal.js +++ b/lib/amd/src/modal.js @@ -21,72 +21,59 @@ * @copyright 2016 Ryan Wyllie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define([ - 'jquery', - 'core/templates', - 'core/notification', - 'core/key_codes', - 'core/custom_interaction_events', - 'core/modal_backdrop', - 'core_filters/events', - 'core/modal_events', - 'core/local/aria/focuslock', - 'core/pending', - 'core/aria', - 'core/fullscreen' -], function( - $, - Templates, - Notification, - KeyCodes, - CustomEvents, - ModalBackdrop, - FilterEvents, - ModalEvents, - FocusLock, - Pending, - Aria, - Fullscreen -) { - var SELECTORS = { - 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]', - }; +import $ from 'jquery'; +import * as Templates from 'core/templates'; +import * as Notification from 'core/notification'; +import * as KeyCodes from 'core/key_codes'; +import ModalBackdrop from 'core/modal_backdrop'; +import ModalEvents from 'core/modal_events'; +import Pending from 'core/pending'; +import * as CustomEvents from 'core/custom_interaction_events'; +import * as FilterEvents from 'core_filters/events'; +import * as FocusLock from 'core/local/aria/focuslock'; +import * as Aria from 'core/aria'; +import * as Fullscreen from 'core/fullscreen'; - var TEMPLATES = { - LOADING: 'core/loading', - BACKDROP: 'core/modal_backdrop', - }; +const SELECTORS = { + 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]', +}; + +const TEMPLATES = { + LOADING: 'core/loading', + BACKDROP: 'core/modal_backdrop', +}; + +export default class Modal { + /** @var {Promise} Module singleton for the backdrop to be reused by all Modal instances */ + backdropPromise = null; /** - * Module singleton for the backdrop to be reused by all Modal instances. + * @var {Number} A counter that gets incremented for each modal created. + * This can be used to generate unique values for the modals. */ - var backdropPromise; + static modalCounter = 0; - /** - * A counter that gets incremented for each modal created. This can be - * used to generate unique values for the modals. - */ - var modalCounter = 0; /** * Constructor for the Modal. * * @param {object} root The root jQuery element for the modal */ - var Modal = function(root) { + constructor(root) { this.root = $(root); + this.modal = this.root.find(SELECTORS.MODAL); this.header = this.modal.find(SELECTORS.HEADER); this.headerPromise = $.Deferred(); @@ -100,7 +87,7 @@ define([ this.isAttached = false; this.bodyJS = null; this.footerJS = null; - this.modalCount = modalCounter++; + this.modalCount = this.modalCounter++; this.attachmentPoint = document.createElement('div'); document.body.append(this.attachmentPoint); this.focusOnClose = null; @@ -130,7 +117,7 @@ define([ } this.registerEventListeners(); - }; + } /** * Attach the modal to the correct part of the page. @@ -140,7 +127,7 @@ define([ * * @method attachToDOM */ - Modal.prototype.attachToDOM = function() { + attachToDOM() { this.getAttachmentPoint().append(this.root); if (this.isAttached) { @@ -162,7 +149,7 @@ define([ } this.isAttached = true; - }; + } /** * Count the number of other visible modals (not including this one). @@ -170,19 +157,19 @@ define([ * @method countOtherVisibleModals * @return {int} */ - Modal.prototype.countOtherVisibleModals = function() { - var count = 0; - $('body').find(SELECTORS.CONTAINER).each(function(index, element) { + countOtherVisibleModals() { + let count = 0; + $('body').find(SELECTORS.CONTAINER).each((index, element) => { element = $(element); // If we haven't found ourself and the element is visible. if (!this.root.is(element) && element.hasClass('show')) { count++; } - }.bind(this)); + }); return count; - }; + } /** * Get the modal backdrop. @@ -190,19 +177,15 @@ define([ * @method getBackdrop * @return {object} jQuery promise */ - Modal.prototype.getBackdrop = function() { - if (!backdropPromise) { - backdropPromise = Templates.render(TEMPLATES.BACKDROP, {}) - .then(function(html) { - var element = $(html); - - return new ModalBackdrop(element); - }) - .fail(Notification.exception); + getBackdrop() { + if (!Modal.backdropPromise) { + Modal.backdropPromise = Templates.render(TEMPLATES.BACKDROP, {}) + .then((html) => new ModalBackdrop($(html))) + .catch(Notification.exception); } - return backdropPromise; - }; + return Modal.backdropPromise; + } /** * Get the root element of this modal. @@ -210,9 +193,9 @@ define([ * @method getRoot * @return {object} jQuery object */ - Modal.prototype.getRoot = function() { + getRoot() { return this.root; - }; + } /** * Get the modal element of this modal. @@ -220,9 +203,9 @@ define([ * @method getModal * @return {object} jQuery object */ - Modal.prototype.getModal = function() { + getModal() { return this.modal; - }; + } /** * Get the modal title element. @@ -230,9 +213,9 @@ define([ * @method getTitle * @return {object} jQuery object */ - Modal.prototype.getTitle = function() { + getTitle() { return this.title; - }; + } /** * Get the modal body element. @@ -240,9 +223,9 @@ define([ * @method getBody * @return {object} jQuery object */ - Modal.prototype.getBody = function() { + getBody() { return this.body; - }; + } /** * Get the modal footer element. @@ -250,9 +233,9 @@ define([ * @method getFooter * @return {object} jQuery object */ - Modal.prototype.getFooter = function() { + getFooter() { return this.footer; - }; + } /** * Get a promise resolving to the title region. @@ -260,9 +243,9 @@ define([ * @method getTitlePromise * @return {Promise} */ - Modal.prototype.getTitlePromise = function() { + getTitlePromise() { return this.titlePromise; - }; + } /** * Get a promise resolving to the body region. @@ -270,9 +253,9 @@ define([ * @method getBodyPromise * @return {object} jQuery object */ - Modal.prototype.getBodyPromise = function() { + getBodyPromise() { return this.bodyPromise; - }; + } /** * Get a promise resolving to the footer region. @@ -280,9 +263,9 @@ define([ * @method getFooterPromise * @return {object} jQuery object */ - Modal.prototype.getFooterPromise = function() { + getFooterPromise() { return this.footerPromise; - }; + } /** * Get the unique modal count. @@ -290,9 +273,9 @@ define([ * @method getModalCount * @return {int} */ - Modal.prototype.getModalCount = function() { + getModalCount() { return this.modalCount; - }; + } /** * Set the modal title element. @@ -303,16 +286,17 @@ define([ * @method setTitle * @param {(string|object)} value The title string or jQuery promise which resolves to the title. */ - Modal.prototype.setTitle = function(value) { - var title = this.getTitle(); + setTitle(value) { + const title = this.getTitle(); this.titlePromise = $.Deferred(); this.asyncSet(value, title.html.bind(title)) - .then(function() { + .then(() => { this.titlePromise.resolve(title); - }.bind(this)) + return; + }) .catch(Notification.exception); - }; + } /** * Set the modal body element. @@ -324,10 +308,10 @@ define([ * @param {(string|object)} value The body string or jQuery promise which resolves to the body. * @fires event:filterContentUpdated */ - Modal.prototype.setBody = function(value) { + setBody(value) { this.bodyPromise = $.Deferred(); - var body = this.getBody(); + const body = this.getBody(); if (typeof value === 'string') { // Just set the value if it's a string. @@ -336,11 +320,10 @@ define([ this.getRoot().trigger(ModalEvents.bodyRendered, this); this.bodyPromise.resolve(body); } else { - var jsPendingId = 'amd-modal-js-pending-id-' + this.getModalCount(); - M.util.js_pending(jsPendingId); + const modalPromise = new Pending(`amd-modal-js-pending-id-${this.getModalCount()}`); // Otherwise we assume it's a promise to be resolved with // html and javascript. - var contentPromise = null; + let contentPromise = null; body.css('overflow', 'hidden'); // Ensure that the `value` is a jQuery Promise. @@ -349,17 +332,17 @@ define([ if (value.state() == 'pending') { // We're still waiting for the body promise to resolve so // let's show a loading icon. - var height = body.innerHeight(); + let height = body.innerHeight(); if (height < 100) { height = 100; } - body.animate({height: height + 'px'}, 150); + body.animate({height: `${height}px`}, 150); body.html(''); contentPromise = Templates.render(TEMPLATES.LOADING, {}) - .then(function(html) { - var loadingIcon = $(html).hide(); + .then((html) => { + const loadingIcon = $(html).hide(); body.html(loadingIcon); loadingIcon.fadeIn(150); @@ -368,13 +351,13 @@ define([ // loading. return $.when(loadingIcon.promise(), value); }) - .then(function(loadingIcon) { + .then((loadingIcon) => { // Once the content has finished loading and // the loading icon has been shown then we can // fade the icon away to reveal the content. return loadingIcon.fadeOut(100).promise(); }) - .then(function() { + .then(() => { return value; }); } else { @@ -384,24 +367,24 @@ define([ } // Now we can actually display the content. - contentPromise.then(function(html, js) { - var result = null; + contentPromise.then((html, js) => { + let result = null; if (this.isVisible()) { // If the modal is visible then we should display // the content gracefully for the user. body.css('opacity', 0); - var currentHeight = body.innerHeight(); + const currentHeight = body.innerHeight(); body.html(html); // We need to clear any height values we've set here // in order to measure the height of the content being // added. This then allows us to animate the height // transition. body.css('height', ''); - var newHeight = body.innerHeight(); - body.css('height', currentHeight + 'px'); + const newHeight = body.innerHeight(); + body.css('height', `${currentHeight}px`); result = body.animate( - {height: newHeight + 'px', opacity: 1}, + {height: `${newHeight}px`, opacity: 1}, {duration: 150, queue: false} ).promise(); } else { @@ -421,30 +404,29 @@ define([ } return result; - }.bind(this)) - .then(function(result) { + }) + .then((result) => { FilterEvents.notifyFilterContentUpdated(body); this.getRoot().trigger(ModalEvents.bodyRendered, this); return result; - }.bind(this)) - .then(function() { + }) + .then(() => { this.bodyPromise.resolve(body); return; - }.bind(this)) - .fail(Notification.exception) - .always(function() { + }) + .catch(Notification.exception) + .always(() => { // When we're done displaying all of the content we need // to clear the custom values we've set here. body.css('height', ''); body.css('overflow', ''); body.css('opacity', ''); - M.util.js_complete(jsPendingId); + modalPromise.resolve(); return; - }) - .fail(Notification.exception); + }); } - }; + } /** * Alternative to setBody() that can be used from non-Jquery modules @@ -452,7 +434,7 @@ define([ * @param {Promise} promise promise that returns {html, js} object * @return {Promise} */ - Modal.prototype.setBodyContent = function(promise) { + setBodyContent(promise) { // Call the leegacy API for now and pass it a jQuery Promise. // This is a non-spec feature of jQuery and cannot be produced with spec promises. // We can encourage people to migrate to this approach, and in future we can swap @@ -462,7 +444,7 @@ define([ this.hide(); throw exception; }); - }; + } /** * Set the modal footer element. The footer element is made visible, if it @@ -475,12 +457,12 @@ define([ * @method setFooter * @param {(string|object)} value The footer string or jQuery promise */ - Modal.prototype.setFooter = function(value) { + setFooter(value) { // Make sure the footer is visible. this.showFooter(); this.footerPromise = $.Deferred(); - var footer = this.getFooter(); + const footer = this.getFooter(); if (typeof value === 'string') { // Just set the value if it's a string. @@ -490,12 +472,12 @@ define([ // Otherwise we assume it's a promise to be resolved with // html and javascript. Templates.render(TEMPLATES.LOADING, {}) - .then(function(html) { + .then((html) => { footer.html(html); return value; }) - .then(function(html, js) { + .then((html, js) => { footer.html(html); if (js) { @@ -509,14 +491,14 @@ define([ } return footer; - }.bind(this)) - .then(function(footer) { + }) + .then((footer) => { this.footerPromise.resolve(footer); return; - }.bind(this)) + }) .catch(Notification.exception); } - }; + } /** * Check if the footer has any content in it. @@ -524,40 +506,40 @@ define([ * @method hasFooterContent * @return {bool} */ - Modal.prototype.hasFooterContent = function() { + hasFooterContent() { return this.getFooter().children().length ? true : false; - }; + } /** * Hide the footer element. * * @method hideFooter */ - Modal.prototype.hideFooter = function() { + hideFooter() { this.getFooter().addClass('hidden'); - }; + } /** * Show the footer element. * * @method showFooter */ - Modal.prototype.showFooter = function() { + showFooter() { this.getFooter().removeClass('hidden'); - }; + } /** * Mark the modal as a large modal. * * @method setLarge */ - Modal.prototype.setLarge = function() { + setLarge() { if (this.isLarge()) { return; } this.getModal().addClass('modal-lg'); - }; + } /** * Check if the modal is a large modal. @@ -565,22 +547,22 @@ define([ * @method isLarge * @return {bool} */ - Modal.prototype.isLarge = function() { + isLarge() { return this.getModal().hasClass('modal-lg'); - }; + } /** * Mark the modal as a small modal. * * @method setSmall */ - Modal.prototype.setSmall = function() { + setSmall() { if (this.isSmall()) { return; } this.getModal().removeClass('modal-lg'); - }; + } /** * Check if the modal is a small modal. @@ -588,9 +570,9 @@ define([ * @method isSmall * @return {bool} */ - Modal.prototype.isSmall = function() { + isSmall() { return !this.getModal().hasClass('modal-lg'); - }; + } /** * Set this modal to be scrollable or not. @@ -598,14 +580,14 @@ define([ * @method setScrollable * @param {bool} value Whether the modal is scrollable or not */ - Modal.prototype.setScrollable = function(value) { + setScrollable(value) { if (!value) { this.getModal()[0].classList.remove('modal-dialog-scrollable'); return; } this.getModal()[0].classList.add('modal-dialog-scrollable'); - }; + } /** @@ -614,15 +596,15 @@ define([ * @method calculateZIndex * @return {int} */ - Modal.prototype.calculateZIndex = function() { - var items = $(SELECTORS.DIALOG + ', ' + SELECTORS.MENU_BAR + ', ' + SELECTORS.HAS_Z_INDEX); - var zIndex = parseInt(this.root.css('z-index')); + calculateZIndex() { + const items = $(`${SELECTORS.DIALOG}, ${SELECTORS.MENU_BAR}, ${SELECTORS.HAS_Z_INDEX}`); + let zIndex = parseInt(this.root.css('z-index')); - items.each(function(index, item) { + items.each((index, item) => { item = $(item); // Note that webkit browsers won't return the z-index value from the CSS stylesheet // if the element doesn't have a position specified. Instead it'll return "auto". - var itemZIndex = item.css('z-index') ? parseInt(item.css('z-index')) : 0; + const itemZIndex = item.css('z-index') ? parseInt(item.css('z-index')) : 0; if (itemZIndex > zIndex) { zIndex = itemZIndex; @@ -630,7 +612,7 @@ define([ }); return zIndex; - }; + } /** * Check if this modal is visible. @@ -638,9 +620,9 @@ define([ * @method isVisible * @return {bool} */ - Modal.prototype.isVisible = function() { + isVisible() { return this.root.hasClass('show'); - }; + } /** * Check if this modal has focus. @@ -648,10 +630,10 @@ define([ * @method hasFocus * @return {bool} */ - Modal.prototype.hasFocus = function() { - var target = $(document.activeElement); + hasFocus() { + const target = $(document.activeElement); return this.root.is(target) || this.root.has(target).length; - }; + } /** * Check if this modal has CSS transitions applied. @@ -659,18 +641,18 @@ define([ * @method hasTransitions * @return {bool} */ - Modal.prototype.hasTransitions = function() { + hasTransitions() { return this.getRoot().hasClass('fade'); - }; + } /** * Gets the jQuery wrapped node that the Modal should be attached to. * * @returns {jQuery} */ - Modal.prototype.getAttachmentPoint = function() { + getAttachmentPoint() { return $(Fullscreen.getElement() || this.attachmentPoint); - }; + } /** * Display this modal. The modal will be attached to the DOM if it hasn't @@ -679,12 +661,12 @@ define([ * @method show * @returns {Promise} */ - Modal.prototype.show = function() { + show() { if (this.isVisible()) { return $.Deferred().resolve(); } - var pendingPromise = new Pending('core/modal:show'); + const pendingPromise = new Pending('core/modal:show'); if (this.hasFooterContent()) { this.showFooter(); @@ -700,10 +682,10 @@ define([ } return this.getBackdrop() - .then(function(backdrop) { - var currentIndex = this.calculateZIndex(); - var newIndex = currentIndex + 2; - var newBackdropIndex = newIndex - 1; + .then((backdrop) => { + const currentIndex = this.calculateZIndex(); + const newIndex = currentIndex + 2; + const newBackdropIndex = newIndex - 1; this.root.css('z-index', newIndex); backdrop.setZIndex(newBackdropIndex); backdrop.show(); @@ -715,29 +697,29 @@ define([ this.root.trigger(ModalEvents.shown, this); return; - }.bind(this)) + }) .then(pendingPromise.resolve); - }; + } /** * Hide this modal if it does not contain a form. * * @method hideIfNotForm */ - Modal.prototype.hideIfNotForm = function() { - var formElement = this.modal.find(SELECTORS.FORM); + hideIfNotForm() { + const formElement = this.modal.find(SELECTORS.FORM); if (formElement.length == 0) { this.hide(); } - }; + } /** * Hide this modal. * * @method hide */ - Modal.prototype.hide = function() { - this.getBackdrop().done(function(backdrop) { + hide() { + this.getBackdrop().done((backdrop) => { FocusLock.untrapFocus(); if (!this.countOtherVisibleModals()) { @@ -746,7 +728,7 @@ define([ $('body').removeClass('modal-open'); } - var currentIndex = parseInt(this.root.css('z-index')); + const currentIndex = parseInt(this.root.css('z-index')); this.root.css('z-index', ''); backdrop.setZIndex(currentIndex - 3); @@ -754,9 +736,9 @@ define([ if (this.hasTransitions()) { // Wait for CSS transitions to complete before hiding the element. - this.getRoot().one('transitionend webkitTransitionEnd oTransitionEnd', function() { + this.getRoot().one('transitionend webkitTransitionEnd oTransitionEnd', () => { this.getRoot().removeClass('show').addClass('hide'); - }.bind(this)); + }); } else { this.getRoot().removeClass('show').addClass('hide'); } @@ -767,20 +749,20 @@ define([ } this.root.trigger(ModalEvents.hidden, this); - }.bind(this)); - }; + }); + } /** * Remove this modal from the DOM. * * @method destroy */ - Modal.prototype.destroy = function() { + destroy() { this.hide(); this.root.remove(); this.root.trigger(ModalEvents.destroyed, this); this.attachmentPoint.remove(); - }; + } /** * Sets the appropriate aria attributes on this dialogue and the other @@ -789,13 +771,13 @@ define([ * * @method accessibilityShow */ - Modal.prototype.accessibilityShow = function() { + accessibilityShow() { // Make us visible to screen readers. Aria.unhide(this.root.get()); // Hide siblings. Aria.hideSiblings(this.root.get()[0]); - }; + } /** * Restores the aria visibility on the DOM elements changed when displaying @@ -804,21 +786,21 @@ define([ * * @method accessibilityHide */ - Modal.prototype.accessibilityHide = function() { + accessibilityHide() { // Unhide siblings. Aria.unhideSiblings(this.root.get()[0]); // Hide this modal. Aria.hide(this.root.get()); - }; + } /** * Set up all of the event handling for the modal. * * @method registerEventListeners */ - Modal.prototype.registerEventListeners = function() { - this.getRoot().on('keydown', function(e) { + registerEventListeners() { + this.getRoot().on('keydown', (e) => { if (!this.isVisible()) { return; } @@ -830,10 +812,10 @@ define([ this.hide(); } } - }.bind(this)); + }); // Listen for clicks on the modal container. - this.getRoot().click(function(e) { + this.getRoot().click((e) => { // If the click wasn't inside the modal element then we should // hide the modal. if (!$(e.target).closest(SELECTORS.MODAL).length) { @@ -841,7 +823,7 @@ define([ // So, we check if we can still find the container element or not. If not, then the DOM tree is changed. // It's best not to hide the modal in that case. if ($(e.target).closest(SELECTORS.CONTAINER).length) { - var outsideClickEvent = $.Event(ModalEvents.outsideClick); + const outsideClickEvent = $.Event(ModalEvents.outsideClick); this.getRoot().trigger(outsideClickEvent, this); if (!outsideClickEvent.isDefaultPrevented()) { @@ -849,17 +831,17 @@ define([ } } } - }.bind(this)); + }); CustomEvents.define(this.getModal(), [CustomEvents.events.activate]); - this.getModal().on(CustomEvents.events.activate, SELECTORS.HIDE, function(e, data) { + this.getModal().on(CustomEvents.events.activate, SELECTORS.HIDE, (e, data) => { if (this.removeOnClose) { this.destroy(); } else { this.hide(); } data.originalEvent.preventDefault(); - }.bind(this)); + }); this.getRoot().on(ModalEvents.hidden, () => { if (this.focusOnClose) { @@ -867,17 +849,17 @@ define([ this.focusOnClose.focus(); } }); - }; + } /** * Register a listener to close the dialogue when the cancel button is pressed. * * @method registerCloseOnCancel */ - Modal.prototype.registerCloseOnCancel = function() { + registerCloseOnCancel() { // Handle the clicking of the Cancel button. - this.getModal().on(CustomEvents.events.activate, this.getActionSelector('cancel'), function(e, data) { - var cancelEvent = $.Event(ModalEvents.cancel); + this.getModal().on(CustomEvents.events.activate, this.getActionSelector('cancel'), (e, data) => { + const cancelEvent = $.Event(ModalEvents.cancel); this.getRoot().trigger(cancelEvent, this); if (!cancelEvent.isDefaultPrevented()) { @@ -889,18 +871,18 @@ define([ this.hide(); } } - }.bind(this)); - }; + }); + } /** * Register a listener to close the dialogue when the save button is pressed. * * @method registerCloseOnSave */ - Modal.prototype.registerCloseOnSave = function() { + registerCloseOnSave() { // Handle the clicking of the Cancel button. - this.getModal().on(CustomEvents.events.activate, this.getActionSelector('save'), function(e, data) { - var saveEvent = $.Event(ModalEvents.save); + this.getModal().on(CustomEvents.events.activate, this.getActionSelector('save'), (e, data) => { + const saveEvent = $.Event(ModalEvents.save); this.getRoot().trigger(saveEvent, this); if (!saveEvent.isDefaultPrevented()) { @@ -912,8 +894,8 @@ define([ this.hide(); } } - }.bind(this)); - }; + }); + } /** @@ -921,10 +903,10 @@ define([ * * @method registerCloseOnDelete */ - Modal.prototype.registerCloseOnDelete = function() { + registerCloseOnDelete() { // Handle the clicking of the Cancel button. - this.getModal().on(CustomEvents.events.activate, this.getActionSelector('delete'), function(e, data) { - var deleteEvent = $.Event(ModalEvents.delete); + this.getModal().on(CustomEvents.events.activate, this.getActionSelector('delete'), (e, data) => { + const deleteEvent = $.Event(ModalEvents.delete); this.getRoot().trigger(deleteEvent, this); if (!deleteEvent.isDefaultPrevented()) { @@ -936,8 +918,8 @@ define([ this.hide(); } } - }.bind(this)); - }; + }); + } /** * Set or resolve and set the value using the function. @@ -947,22 +929,22 @@ define([ * @param {function} setFunction The setter * @return {Promise} */ - Modal.prototype.asyncSet = function(value, setFunction) { + asyncSet(value, setFunction) { var p = value; if (typeof value !== 'object' || !value.hasOwnProperty('then')) { p = $.Deferred(); p.resolve(value); } - p.then(function(content) { + p.then((content) => { setFunction(content); return; }) - .fail(Notification.exception); + .catch(Notification.exception); return p; - }; + } /** * Set the title text of a button. @@ -974,7 +956,7 @@ define([ * @param {(String|object)} value The button text, or a promise which will resolve to it * @returns {Promise} */ - Modal.prototype.setButtonText = function(action, value) { + setButtonText(action, value) { const button = this.getFooter().find(this.getActionSelector(action)); if (!button) { @@ -982,7 +964,7 @@ define([ } return this.asyncSet(value, button.text.bind(button)); - }; + } /** * Get the Selector for an action. @@ -990,27 +972,27 @@ define([ * @param {String} action * @returns {DOMString} */ - Modal.prototype.getActionSelector = function(action) { + getActionSelector(action) { return "[data-action='" + action + "']"; - }; + } /** * Set the flag to remove the modal from the DOM on close. * * @param {Boolean} remove */ - Modal.prototype.setRemoveOnClose = function(remove) { + setRemoveOnClose(remove) { this.removeOnClose = remove; - }; + } /** * Set the return element for the modal. * * @param {Element|jQuery} element Element to focus when the modal is closed */ - Modal.prototype.setReturnElement = function(element) { + setReturnElement(element) { this.focusOnClose = element; - }; + } /** * Set the a button enabled or disabled. @@ -1018,7 +1000,7 @@ define([ * @param {DOMString} action The action of the button * @param {Boolean} disabled the new disabled value */ - Modal.prototype.setButtonDisabled = function(action, disabled) { + setButtonDisabled(action, disabled) { const button = this.getFooter().find(this.getActionSelector(action)); if (!button) { @@ -1029,7 +1011,5 @@ define([ } else { button.removeAttr('disabled'); } - }; - - return Modal; -}); + } +}