diff --git a/lib/amd/build/modal.min.js b/lib/amd/build/modal.min.js index f8be0bcf20e..833b5c9f7fb 100644 --- a/lib/amd/build/modal.min.js +++ b/lib/amd/build/modal.min.js @@ -1,2 +1,2 @@ -function _typeof(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core/modal",["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core/event","core/modal_events"],function(a,b,c,d,e,f,g,h){var i={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]"},j={LOADING:"core/loading",BACKDROP:"core/modal_backdrop"},k,l=0,m=function(b){this.root=a(b);this.modal=this.root.find(i.MODAL);this.header=this.modal.find(i.HEADER);this.title=this.header.find(i.TITLE);this.body=this.modal.find(i.BODY);this.footer=this.modal.find(i.FOOTER);this.hiddenSiblings=[];this.isAttached=!1;this.bodyJS=null;this.footerJS=null;this.modalCount=l++;if(!this.root.is(i.CONTAINER)){c.exception({message:"Element is not a modal container"})}if(!this.modal.length){c.exception({message:"Container does not contain a modal"})}if(!this.header.length){c.exception({message:"Modal is missing a header region"})}if(!this.title.length){c.exception({message:"Modal header is missing a title region"})}if(!this.body.length){c.exception({message:"Modal is missing a body region"})}if(!this.footer.length){c.exception({message:"Modal is missing a footer region"})}this.registerEventListeners()};m.prototype.attachToDOM=function(){if(this.isAttached){return}a("body").append(this.root);if(this.bodyJS){b.runTemplateJS(this.bodyJS);this.bodyJS=null}if(this.footerJS){b.runTemplateJS(this.footerJS);this.footerJS=null}this.isAttached=!0};m.prototype.countOtherVisibleModals=function(){var b=0;a("body").find(i.CONTAINER).each(function(c,d){d=a(d);if(!this.root.is(d)&&d.hasClass("show")){b++}}.bind(this));return b};m.prototype.getBackdrop=function(){if(!k){k=b.render(j.BACKDROP,{}).then(function(b){var c=a(b);return new f(c)}).fail(c.exception)}return k};m.prototype.getRoot=function(){return this.root};m.prototype.getModal=function(){return this.modal};m.prototype.getTitle=function(){return this.title};m.prototype.getBody=function(){return this.body};m.prototype.getFooter=function(){return this.footer};m.prototype.getModalCount=function(){return this.modalCount};m.prototype.setTitle=function(a){var b=this.getTitle();this.asyncSet(a,b.html.bind(b))};m.prototype.setBody=function(d){var e=this.getBody();if("string"==typeof d){e.html(d);g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this)}else{var f="amd-modal-js-pending-id-"+this.getModalCount();M.util.js_pending(f);var i=null;e.css("overflow","hidden");if("pending"==d.state()){var k=e.innerHeight();if(100>k){k=100}e.animate({height:k+"px"},150);e.html("");i=b.render(j.LOADING,{}).then(function(b){var c=a(b).hide();e.html(c);c.fadeIn(150);return a.when(c.promise(),d)}).then(function(a){return a.fadeOut(100).promise()}).then(function(){return d})}else{i=d}i.then(function(a,c){var d=null;if(this.isVisible()){e.css("opacity",0);var f=e.innerHeight();e.html(a);e.css("height","");var i=e.innerHeight();e.css("height",f+"px");d=e.animate({height:i+"px",opacity:1},{duration:150,queue:!1}).promise()}else{e.html(a)}if(c){if(this.isAttached){b.runTemplateJS(c)}else{this.bodyJS=c}}g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this);return d}.bind(this)).fail(c.exception).always(function(){e.css("height","");e.css("overflow","");e.css("opacity","");M.util.js_complete(f)}).fail(c.exception)}};m.prototype.setFooter=function(a){this.showFooter();var c=this.getFooter();if("string"==typeof a){c.html(a)}else{b.render(j.LOADING,{}).done(function(d){c.html(d);a.done(function(a,d){c.html(a);if(d){if(this.isAttached){b.runTemplateJS(d)}else{this.footerJS=d}}}.bind(this))}.bind(this))}};m.prototype.hasFooterContent=function(){return this.getFooter().children().length?!0:!1};m.prototype.hideFooter=function(){this.getFooter().addClass("hidden")};m.prototype.showFooter=function(){this.getFooter().removeClass("hidden")};m.prototype.setLarge=function(){if(this.isLarge()){return}this.getModal().addClass("modal-lg")};m.prototype.isLarge=function(){return this.getModal().hasClass("modal-lg")};m.prototype.setSmall=function(){if(this.isSmall()){return}this.getModal().removeClass("modal-lg")};m.prototype.isSmall=function(){return!this.getModal().hasClass("modal-lg")};m.prototype.calculateZIndex=function(){var b=a(i.DIALOG+", "+i.MENU_BAR+", "+i.HAS_Z_INDEX),c=parseInt(this.root.css("z-index"));b.each(function(b,d){d=a(d);var e=d.css("z-index")?parseInt(d.css("z-index")):0;if(e>c){c=e}});return c};m.prototype.isVisible=function(){return this.root.hasClass("show")};m.prototype.hasFocus=function(){var b=a(document.activeElement);return this.root.is(b)||this.root.has(b).length};m.prototype.hasTransitions=function(){return this.getRoot().hasClass("fade")};m.prototype.show=function(){if(this.isVisible()){return}if(this.hasFooterContent()){this.showFooter()}else{this.hideFooter()}if(!this.isAttached){this.attachToDOM()}this.getBackdrop().done(function(b){var c=this.calculateZIndex(),d=c+2;this.root.css("z-index",d);b.setZIndex(d-1);b.show();this.root.removeClass("hide").addClass("show");this.accessibilityShow();this.getModal().focus();a("body").addClass("modal-open");this.root.trigger(h.shown,this)}.bind(this))};m.prototype.hideIfNotForm=function(){var a=this.modal.find(i.FORM);if(0==a.length){this.hide()}};m.prototype.hide=function(){this.getBackdrop().done(function(b){if(!this.countOtherVisibleModals()){b.hide();a("body").removeClass("modal-open")}var c=parseInt(this.root.css("z-index"));this.root.css("z-index","");b.setZIndex(c-3);this.accessibilityHide();if(this.hasTransitions()){this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",function(){this.getRoot().removeClass("show").addClass("hide")}.bind(this))}else{this.getRoot().removeClass("show").addClass("hide")}this.root.trigger(h.hidden,this)}.bind(this))};m.prototype.destroy=function(){this.root.remove();this.root.trigger(h.destroyed,this)};m.prototype.accessibilityShow=function(){a("body").children().each(function(b,c){if(!this.root.is(c)){c=a(c);var d=c.attr("aria-hidden");if("true"!==d){c.data("previous-aria-hidden",d);this.hiddenSiblings.push(c);c.attr("aria-hidden","true")}}}.bind(this));this.root.attr("aria-hidden","false")};m.prototype.accessibilityHide=function(){this.root.attr("aria-hidden","true");a.each(this.hiddenSiblings,function(b,c){c=a(c);var d=c.data("previous-aria-hidden");if("undefined"==typeof d){c.removeAttr("aria-hidden")}else{c.attr("aria-hidden",d)}});this.hiddenSiblings=[]};m.prototype.handleTabLock=function(b){if(!this.hasFocus()){return}var c=a(document.activeElement),d=this.modal.find(i.CAN_RECEIVE_FOCUS),e=d.first(),f=d.last();if(c.is(e)&&b.shiftKey){f.focus();b.preventDefault()}else if(c.is(f)&&!b.shiftKey){e.focus();b.preventDefault()}};m.prototype.registerEventListeners=function(){this.getRoot().on("keydown",function(a){if(!this.isVisible()){return}if(a.keyCode==d.tab){this.handleTabLock(a)}else if(a.keyCode==d.escape){this.hide()}}.bind(this));this.getRoot().click(function(b){if(!a(b.target).closest(i.MODAL).length){if(a(b.target).closest(i.CONTAINER).length){this.hideIfNotForm()}}}.bind(this));e.define(this.getModal(),[e.events.activate]);this.getModal().on(e.events.activate,i.HIDE,function(a,b){this.hide();b.originalEvent.preventDefault()}.bind(this))};m.prototype.asyncSet=function(b,d){var e=b;if("object"!==_typeof(b)||!b.hasOwnProperty("then")){e=a.Deferred();e.resolve(b)}e.then(function(a){d(a)}).fail(c.exception);return e};return m}); +function _typeof(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core/modal",["jquery","core/templates","core/notification","core/key_codes","core/custom_interaction_events","core/modal_backdrop","core/event","core/modal_events"],function(a,b,c,d,e,f,g,h){var i={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]"},j={LOADING:"core/loading",BACKDROP:"core/modal_backdrop"},k,l=0,m=function(b){this.root=a(b);this.modal=this.root.find(i.MODAL);this.header=this.modal.find(i.HEADER);this.title=this.header.find(i.TITLE);this.body=this.modal.find(i.BODY);this.footer=this.modal.find(i.FOOTER);this.hiddenSiblings=[];this.isAttached=!1;this.bodyJS=null;this.footerJS=null;this.modalCount=l++;if(!this.root.is(i.CONTAINER)){c.exception({message:"Element is not a modal container"})}if(!this.modal.length){c.exception({message:"Container does not contain a modal"})}if(!this.header.length){c.exception({message:"Modal is missing a header region"})}if(!this.title.length){c.exception({message:"Modal header is missing a title region"})}if(!this.body.length){c.exception({message:"Modal is missing a body region"})}if(!this.footer.length){c.exception({message:"Modal is missing a footer region"})}this.registerEventListeners()};m.prototype.attachToDOM=function(){if(this.isAttached){return}a("body").append(this.root);if(this.bodyJS){b.runTemplateJS(this.bodyJS);this.bodyJS=null}if(this.footerJS){b.runTemplateJS(this.footerJS);this.footerJS=null}this.isAttached=!0};m.prototype.countOtherVisibleModals=function(){var b=0;a("body").find(i.CONTAINER).each(function(c,d){d=a(d);if(!this.root.is(d)&&d.hasClass("show")){b++}}.bind(this));return b};m.prototype.getBackdrop=function(){if(!k){k=b.render(j.BACKDROP,{}).then(function(b){var c=a(b);return new f(c)}).fail(c.exception)}return k};m.prototype.getRoot=function(){return this.root};m.prototype.getModal=function(){return this.modal};m.prototype.getTitle=function(){return this.title};m.prototype.getBody=function(){return this.body};m.prototype.getFooter=function(){return this.footer};m.prototype.getModalCount=function(){return this.modalCount};m.prototype.setTitle=function(a){var b=this.getTitle();this.asyncSet(a,b.html.bind(b))};m.prototype.setBody=function(d){var e=this.getBody();if("string"==typeof d){e.html(d);g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this)}else{var f="amd-modal-js-pending-id-"+this.getModalCount();M.util.js_pending(f);var i=null;e.css("overflow","hidden");if("pending"==d.state()){var k=e.innerHeight();if(100>k){k=100}e.animate({height:k+"px"},150);e.html("");i=b.render(j.LOADING,{}).then(function(b){var c=a(b).hide();e.html(c);c.fadeIn(150);return a.when(c.promise(),d)}).then(function(a){return a.fadeOut(100).promise()}).then(function(){return d})}else{i=d}i.then(function(a,c){var d=null;if(this.isVisible()){e.css("opacity",0);var f=e.innerHeight();e.html(a);e.css("height","");var g=e.innerHeight();e.css("height",f+"px");d=e.animate({height:g+"px",opacity:1},{duration:150,queue:!1}).promise()}else{e.html(a)}if(c){if(this.isAttached){b.runTemplateJS(c)}else{this.bodyJS=c}}return d}.bind(this)).then(function(a){g.notifyFilterContentUpdated(e);this.getRoot().trigger(h.bodyRendered,this);return a}.bind(this)).fail(c.exception).always(function(){e.css("height","");e.css("overflow","");e.css("opacity","");M.util.js_complete(f)}).fail(c.exception)}};m.prototype.setFooter=function(a){this.showFooter();var c=this.getFooter();if("string"==typeof a){c.html(a)}else{b.render(j.LOADING,{}).done(function(d){c.html(d);a.done(function(a,d){c.html(a);if(d){if(this.isAttached){b.runTemplateJS(d)}else{this.footerJS=d}}}.bind(this))}.bind(this))}};m.prototype.hasFooterContent=function(){return this.getFooter().children().length?!0:!1};m.prototype.hideFooter=function(){this.getFooter().addClass("hidden")};m.prototype.showFooter=function(){this.getFooter().removeClass("hidden")};m.prototype.setLarge=function(){if(this.isLarge()){return}this.getModal().addClass("modal-lg")};m.prototype.isLarge=function(){return this.getModal().hasClass("modal-lg")};m.prototype.setSmall=function(){if(this.isSmall()){return}this.getModal().removeClass("modal-lg")};m.prototype.isSmall=function(){return!this.getModal().hasClass("modal-lg")};m.prototype.calculateZIndex=function(){var b=a(i.DIALOG+", "+i.MENU_BAR+", "+i.HAS_Z_INDEX),c=parseInt(this.root.css("z-index"));b.each(function(b,d){d=a(d);var e=d.css("z-index")?parseInt(d.css("z-index")):0;if(e>c){c=e}});return c};m.prototype.isVisible=function(){return this.root.hasClass("show")};m.prototype.hasFocus=function(){var b=a(document.activeElement);return this.root.is(b)||this.root.has(b).length};m.prototype.hasTransitions=function(){return this.getRoot().hasClass("fade")};m.prototype.show=function(){if(this.isVisible()){return}if(this.hasFooterContent()){this.showFooter()}else{this.hideFooter()}if(!this.isAttached){this.attachToDOM()}this.getBackdrop().done(function(b){var c=this.calculateZIndex(),d=c+2;this.root.css("z-index",d);b.setZIndex(d-1);b.show();this.root.removeClass("hide").addClass("show");this.accessibilityShow();this.getModal().focus();a("body").addClass("modal-open");this.root.trigger(h.shown,this)}.bind(this))};m.prototype.hideIfNotForm=function(){var a=this.modal.find(i.FORM);if(0==a.length){this.hide()}};m.prototype.hide=function(){this.getBackdrop().done(function(b){if(!this.countOtherVisibleModals()){b.hide();a("body").removeClass("modal-open")}var c=parseInt(this.root.css("z-index"));this.root.css("z-index","");b.setZIndex(c-3);this.accessibilityHide();if(this.hasTransitions()){this.getRoot().one("transitionend webkitTransitionEnd oTransitionEnd",function(){this.getRoot().removeClass("show").addClass("hide")}.bind(this))}else{this.getRoot().removeClass("show").addClass("hide")}this.root.trigger(h.hidden,this)}.bind(this))};m.prototype.destroy=function(){this.root.remove();this.root.trigger(h.destroyed,this)};m.prototype.accessibilityShow=function(){a("body").children().each(function(b,c){if(!this.root.is(c)){c=a(c);var d=c.attr("aria-hidden");if("true"!==d){c.data("previous-aria-hidden",d);this.hiddenSiblings.push(c);c.attr("aria-hidden","true")}}}.bind(this));this.root.attr("aria-hidden","false")};m.prototype.accessibilityHide=function(){this.root.attr("aria-hidden","true");a.each(this.hiddenSiblings,function(b,c){c=a(c);var d=c.data("previous-aria-hidden");if("undefined"==typeof d){c.removeAttr("aria-hidden")}else{c.attr("aria-hidden",d)}});this.hiddenSiblings=[]};m.prototype.handleTabLock=function(b){if(!this.hasFocus()){return}var c=a(document.activeElement),d=this.modal.find(i.CAN_RECEIVE_FOCUS),e=d.first(),f=d.last();if(c.is(e)&&b.shiftKey){f.focus();b.preventDefault()}else if(c.is(f)&&!b.shiftKey){e.focus();b.preventDefault()}};m.prototype.registerEventListeners=function(){this.getRoot().on("keydown",function(a){if(!this.isVisible()){return}if(a.keyCode==d.tab){this.handleTabLock(a)}else if(a.keyCode==d.escape){this.hide()}}.bind(this));this.getRoot().click(function(b){if(!a(b.target).closest(i.MODAL).length){if(a(b.target).closest(i.CONTAINER).length){this.hideIfNotForm()}}}.bind(this));e.define(this.getModal(),[e.events.activate]);this.getModal().on(e.events.activate,i.HIDE,function(a,b){this.hide();b.originalEvent.preventDefault()}.bind(this))};m.prototype.asyncSet=function(b,d){var e=b;if("object"!==_typeof(b)||!b.hasOwnProperty("then")){e=a.Deferred();e.resolve(b)}e.then(function(a){d(a)}).fail(c.exception);return e};return m}); //# sourceMappingURL=modal.min.js.map diff --git a/lib/amd/build/modal.min.js.map b/lib/amd/build/modal.min.js.map index 8f8bf40acea..33a5e2c31ca 100644 --- a/lib/amd/build/modal.min.js.map +++ b/lib/amd/build/modal.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/modal.js"],"names":["define","$","Templates","Notification","KeyCodes","CustomEvents","ModalBackdrop","Event","ModalEvents","SELECTORS","CONTAINER","MODAL","HEADER","TITLE","BODY","FOOTER","HIDE","DIALOG","FORM","MENU_BAR","HAS_Z_INDEX","CAN_RECEIVE_FOCUS","TEMPLATES","LOADING","BACKDROP","backdropPromise","modalCounter","Modal","root","modal","find","header","title","body","footer","hiddenSiblings","isAttached","bodyJS","footerJS","modalCount","is","exception","message","length","registerEventListeners","prototype","attachToDOM","append","runTemplateJS","countOtherVisibleModals","count","each","index","element","hasClass","bind","getBackdrop","render","then","html","fail","getRoot","getModal","getTitle","getBody","getFooter","getModalCount","setTitle","value","asyncSet","setBody","notifyFilterContentUpdated","trigger","bodyRendered","jsPendingId","M","util","js_pending","contentPromise","css","state","height","innerHeight","animate","loadingIcon","hide","fadeIn","when","promise","fadeOut","js","result","isVisible","currentHeight","newHeight","opacity","duration","queue","always","js_complete","setFooter","showFooter","done","hasFooterContent","children","hideFooter","addClass","removeClass","setLarge","isLarge","setSmall","isSmall","calculateZIndex","items","zIndex","parseInt","item","itemZIndex","hasFocus","target","document","activeElement","has","hasTransitions","show","backdrop","currentIndex","newIndex","setZIndex","accessibilityShow","focus","shown","hideIfNotForm","formElement","accessibilityHide","one","hidden","destroy","remove","destroyed","child","attr","data","push","sibling","previousValue","removeAttr","handleTabLock","e","focusableElements","firstFocusable","first","lastFocusable","last","shiftKey","preventDefault","on","keyCode","tab","escape","click","closest","events","activate","originalEvent","setFunction","p","hasOwnProperty","Deferred","resolve","content"],"mappings":"yQAwBAA,OAAM,cAAC,CAAC,QAAD,CAAW,gBAAX,CAA6B,mBAA7B,CAAkD,gBAAlD,CACC,gCADD,CACmC,qBADnC,CAC0D,YAD1D,CACwE,mBADxE,CAAD,CAED,SAASC,CAAT,CAAYC,CAAZ,CAAuBC,CAAvB,CAAqCC,CAArC,CAA+CC,CAA/C,CAA6DC,CAA7D,CAA4EC,CAA5E,CAAmFC,CAAnF,CAAgG,IAE7FC,CAAAA,CAAS,CAAG,CACZC,SAAS,CAAE,mCADC,CAEZC,KAAK,CAAE,yBAFK,CAGZC,MAAM,CAAE,0BAHI,CAIZC,KAAK,CAAE,yBAJK,CAKZC,IAAI,CAAE,wBALM,CAMZC,MAAM,CAAE,0BANI,CAOZC,IAAI,CAAE,wBAPM,CAQZC,MAAM,CAAE,eARI,CASZC,IAAI,CAAE,MATM,CAUZC,QAAQ,CAAE,gBAVE,CAWZC,WAAW,CAAE,oBAXD,CAYZC,iBAAi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B,KAAK8D,QAAL,EAApB,CAAqC,CAACzD,CAAY,CAAC6J,MAAb,CAAoBC,QAArB,CAArC,EACA,KAAKrG,QAAL,GAAgB8F,EAAhB,CAAmBvJ,CAAY,CAAC6J,MAAb,CAAoBC,QAAvC,CAAiD1J,CAAS,CAACO,IAA3D,CAAiE,SAASoI,CAAT,CAAYN,CAAZ,CAAkB,CAC/E,KAAKzD,IAAL,GACAyD,CAAI,CAACsB,aAAL,CAAmBT,cAAnB,EACH,CAHgE,CAG/DpG,IAH+D,CAG1D,IAH0D,CAAjE,CAIH,CAhCD,CA0CA5B,CAAK,CAACkB,SAAN,CAAgBwB,QAAhB,CAA2B,SAASD,CAAT,CAAgBiG,CAAhB,CAA6B,CACpD,GAAIC,CAAAA,CAAC,CAAGlG,CAAR,CACA,GAAqB,QAAjB,WAAOA,CAAP,GAA6B,CAACA,CAAK,CAACmG,cAAN,CAAqB,MAArB,CAAlC,CAAgE,CAC5DD,CAAC,CAAGrK,CAAC,CAACuK,QAAF,EAAJ,CACAF,CAAC,CAACG,OAAF,CAAUrG,CAAV,CACH,CAEDkG,CAAC,CAAC5G,IAAF,CAAO,SAASgH,CAAT,CAAkB,CACrBL,CAAW,CAACK,CAAD,CAGd,CAJD,EAKC9G,IALD,CAKMzD,CAAY,CAACsC,SALnB,EAOA,MAAO6H,CAAAA,CACV,CAfD,CAiBA,MAAO3I,CAAAA,CACV,CApvBK,CAAN","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 modal\n * @package core\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/templates', 'core/notification', 'core/key_codes',\n 'core/custom_interaction_events', 'core/modal_backdrop', 'core/event', 'core/modal_events'],\n function($, Templates, Notification, KeyCodes, CustomEvents, ModalBackdrop, Event, ModalEvents) {\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.title = this.header.find(SELECTORS.TITLE);\n this.body = this.modal.find(SELECTORS.BODY);\n this.footer = this.modal.find(SELECTORS.FOOTER);\n this.hiddenSiblings = [];\n this.isAttached = false;\n this.bodyJS = null;\n this.footerJS = null;\n this.modalCount = modalCounter++;\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 * Add the modal to the page, if it hasn't already been added. This includes running any\n * javascript that has been cached until now.\n *\n * @method attachToDOM\n */\n Modal.prototype.attachToDOM = function() {\n if (this.isAttached) {\n return;\n }\n\n $('body').append(this.root);\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 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\n this.asyncSet(value, title.html.bind(title));\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 */\n Modal.prototype.setBody = function(value) {\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 Event.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\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 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 Event.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n\n return result;\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 * 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\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 } else {\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n Templates.render(TEMPLATES.LOADING, {}).done(function(html) {\n footer.html(html);\n\n value.done(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 }.bind(this));\n }.bind(this));\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 * 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 * Display this modal. The modal will be attached to the DOM if it hasn't\n * already been.\n *\n * @method show\n */\n Modal.prototype.show = function() {\n if (this.isVisible()) {\n return;\n }\n\n if (this.hasFooterContent()) {\n this.showFooter();\n } else {\n this.hideFooter();\n }\n\n if (!this.isAttached) {\n this.attachToDOM();\n }\n\n this.getBackdrop().done(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 }.bind(this));\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 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 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.root.remove();\n this.root.trigger(ModalEvents.destroyed, this);\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 // We need to get a list containing each sibling element and the shallowest\n // non-ancestral nodes in the DOM. We can shortcut this a little by leveraging\n // the fact that this dialogue is always appended to the document body therefore\n // it's siblings are the shallowest non-ancestral nodes. If that changes then\n // this code should also be updated.\n $('body').children().each(function(index, child) {\n // Skip the current modal.\n if (!this.root.is(child)) {\n child = $(child);\n var hidden = child.attr('aria-hidden');\n // If they are already hidden we can ignore them.\n if (hidden !== 'true') {\n // Save their current state.\n child.data('previous-aria-hidden', hidden);\n this.hiddenSiblings.push(child);\n\n // Hide this node from screen readers.\n child.attr('aria-hidden', 'true');\n }\n }\n }.bind(this));\n\n // Make us visible to screen readers.\n this.root.attr('aria-hidden', 'false');\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 this.root.attr('aria-hidden', 'true');\n\n // Restore the sibling nodes back to their original values.\n $.each(this.hiddenSiblings, function(index, sibling) {\n sibling = $(sibling);\n var previousValue = sibling.data('previous-aria-hidden');\n // If the element didn't previously have an aria-hidden attribute\n // then we can just remove the one we set.\n if (typeof previousValue == 'undefined') {\n sibling.removeAttr('aria-hidden');\n } else {\n // Otherwise set it back to the old value (which will be false).\n sibling.attr('aria-hidden', previousValue);\n }\n });\n\n // Clear the cache. No longer need to store these.\n this.hiddenSiblings = [];\n };\n\n /**\n * Handle the tab event to lock focus within this modal.\n *\n * @method handleTabLock\n * @param {event} e The tab key jQuery event\n */\n Modal.prototype.handleTabLock = function(e) {\n if (!this.hasFocus()) {\n return;\n }\n\n var target = $(document.activeElement);\n var focusableElements = this.modal.find(SELECTORS.CAN_RECEIVE_FOCUS);\n var firstFocusable = focusableElements.first();\n var lastFocusable = focusableElements.last();\n\n if (target.is(firstFocusable) && e.shiftKey) {\n lastFocusable.focus();\n e.preventDefault();\n } else if (target.is(lastFocusable) && !e.shiftKey) {\n firstFocusable.focus();\n e.preventDefault();\n }\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.tab) {\n this.handleTabLock(e);\n } else if (e.keyCode == KeyCodes.escape) {\n this.hide();\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 this.hideIfNotForm();\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 this.hide();\n data.originalEvent.preventDefault();\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 return Modal;\n});\n"],"file":"modal.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/modal.js"],"names":["define","$","Templates","Notification","KeyCodes","CustomEvents","ModalBackdrop","Event","ModalEvents","SELECTORS","CONTAINER","MODAL","HEADER","TITLE","BODY","FOOTER","HIDE","DIALOG","FORM","MENU_BAR","HAS_Z_INDEX","CAN_RECEIVE_FOCUS","TEMPLATES","LOADING","BACKDROP","backdropPromise","modalCounter","Modal","root","modal","find","header","title","body","footer","hiddenSiblings","isAttached","bodyJS","footerJS","modalCount","is","exception","message","length","registerEventListeners","prototype","attachToDOM","append","runTemplateJS","countOtherVisibleModals","count","each","index","element","hasClass","bind","getBackdrop","render","then","html","fail","getRoot","getModal","getTitle","getBody","getFooter","getModalCount","setTitle","value","asyncSet","setBody","notifyFilterContentUpdated","trigger","bodyRendered","jsPendingId","M","util","js_pending","contentPromise","css","state","height","innerHeight","animate","loadingIcon","hide","fadeIn","when","promise","fadeOut","js","result","isVisible","currentHeight","newHeight","opacity","duration","queue","always","js_complete","setFooter","showFooter","done","hasFooterContent","children","hideFooter","addClass","removeClass","setLarge","isLarge","setSmall","isSmall","calculateZIndex","items","zIndex","parseInt","item","itemZIndex","hasFocus","target","document","activeElement","has","hasTransitions","show","backdrop","currentIndex","newIndex","setZIndex","accessibilityShow","focus","shown","hideIfNotForm","formElement","accessibilityHide","one","hidden","destroy","remove","destroyed","child","attr","data","push","sibling","previousValue","removeAttr","handleTabLock","e","focusableElements","firstFocusable","first","lastFocusable","last","shiftKey","preventDefault","on","keyCode","tab","escape","click","closest","events","activate","originalEvent","setFunction","p","hasOwnProperty","Deferred","resolve","content"],"mappings":"yQAwBAA,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AAN,CAAqB,MAArB,CAAlC,CAAgE,CAC5DD,CAAC,CAAGrK,CAAC,CAACuK,QAAF,EAAJ,CACAF,CAAC,CAACG,OAAF,CAAUrG,CAAV,CACH,CAEDkG,CAAC,CAAC5G,IAAF,CAAO,SAASgH,CAAT,CAAkB,CACrBL,CAAW,CAACK,CAAD,CAGd,CAJD,EAKC9G,IALD,CAKMzD,CAAY,CAACsC,SALnB,EAOA,MAAO6H,CAAAA,CACV,CAfD,CAiBA,MAAO3I,CAAAA,CACV,CAvvBK,CAAN","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 modal\n * @package core\n * @copyright 2016 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/templates', 'core/notification', 'core/key_codes',\n 'core/custom_interaction_events', 'core/modal_backdrop', 'core/event', 'core/modal_events'],\n function($, Templates, Notification, KeyCodes, CustomEvents, ModalBackdrop, Event, ModalEvents) {\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.title = this.header.find(SELECTORS.TITLE);\n this.body = this.modal.find(SELECTORS.BODY);\n this.footer = this.modal.find(SELECTORS.FOOTER);\n this.hiddenSiblings = [];\n this.isAttached = false;\n this.bodyJS = null;\n this.footerJS = null;\n this.modalCount = modalCounter++;\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 * Add the modal to the page, if it hasn't already been added. This includes running any\n * javascript that has been cached until now.\n *\n * @method attachToDOM\n */\n Modal.prototype.attachToDOM = function() {\n if (this.isAttached) {\n return;\n }\n\n $('body').append(this.root);\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 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\n this.asyncSet(value, title.html.bind(title));\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 */\n Modal.prototype.setBody = function(value) {\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 Event.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\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 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 Event.notifyFilterContentUpdated(body);\n this.getRoot().trigger(ModalEvents.bodyRendered, this);\n return result;\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 * 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\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 } else {\n // Otherwise we assume it's a promise to be resolved with\n // html and javascript.\n Templates.render(TEMPLATES.LOADING, {}).done(function(html) {\n footer.html(html);\n\n value.done(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 }.bind(this));\n }.bind(this));\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 * 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 * Display this modal. The modal will be attached to the DOM if it hasn't\n * already been.\n *\n * @method show\n */\n Modal.prototype.show = function() {\n if (this.isVisible()) {\n return;\n }\n\n if (this.hasFooterContent()) {\n this.showFooter();\n } else {\n this.hideFooter();\n }\n\n if (!this.isAttached) {\n this.attachToDOM();\n }\n\n this.getBackdrop().done(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 }.bind(this));\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 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 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.root.remove();\n this.root.trigger(ModalEvents.destroyed, this);\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 // We need to get a list containing each sibling element and the shallowest\n // non-ancestral nodes in the DOM. We can shortcut this a little by leveraging\n // the fact that this dialogue is always appended to the document body therefore\n // it's siblings are the shallowest non-ancestral nodes. If that changes then\n // this code should also be updated.\n $('body').children().each(function(index, child) {\n // Skip the current modal.\n if (!this.root.is(child)) {\n child = $(child);\n var hidden = child.attr('aria-hidden');\n // If they are already hidden we can ignore them.\n if (hidden !== 'true') {\n // Save their current state.\n child.data('previous-aria-hidden', hidden);\n this.hiddenSiblings.push(child);\n\n // Hide this node from screen readers.\n child.attr('aria-hidden', 'true');\n }\n }\n }.bind(this));\n\n // Make us visible to screen readers.\n this.root.attr('aria-hidden', 'false');\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 this.root.attr('aria-hidden', 'true');\n\n // Restore the sibling nodes back to their original values.\n $.each(this.hiddenSiblings, function(index, sibling) {\n sibling = $(sibling);\n var previousValue = sibling.data('previous-aria-hidden');\n // If the element didn't previously have an aria-hidden attribute\n // then we can just remove the one we set.\n if (typeof previousValue == 'undefined') {\n sibling.removeAttr('aria-hidden');\n } else {\n // Otherwise set it back to the old value (which will be false).\n sibling.attr('aria-hidden', previousValue);\n }\n });\n\n // Clear the cache. No longer need to store these.\n this.hiddenSiblings = [];\n };\n\n /**\n * Handle the tab event to lock focus within this modal.\n *\n * @method handleTabLock\n * @param {event} e The tab key jQuery event\n */\n Modal.prototype.handleTabLock = function(e) {\n if (!this.hasFocus()) {\n return;\n }\n\n var target = $(document.activeElement);\n var focusableElements = this.modal.find(SELECTORS.CAN_RECEIVE_FOCUS);\n var firstFocusable = focusableElements.first();\n var lastFocusable = focusableElements.last();\n\n if (target.is(firstFocusable) && e.shiftKey) {\n lastFocusable.focus();\n e.preventDefault();\n } else if (target.is(lastFocusable) && !e.shiftKey) {\n firstFocusable.focus();\n e.preventDefault();\n }\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.tab) {\n this.handleTabLock(e);\n } else if (e.keyCode == KeyCodes.escape) {\n this.hide();\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 this.hideIfNotForm();\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 this.hide();\n data.originalEvent.preventDefault();\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 return Modal;\n});\n"],"file":"modal.min.js"} \ No newline at end of file diff --git a/lib/amd/src/modal.js b/lib/amd/src/modal.js index 4e61d10ac26..a44a43ad9a0 100644 --- a/lib/amd/src/modal.js +++ b/lib/amd/src/modal.js @@ -343,9 +343,12 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes', this.bodyJS = js; } } + + return result; + }.bind(this)) + .then(function(result) { Event.notifyFilterContentUpdated(body); this.getRoot().trigger(ModalEvents.bodyRendered, this); - return result; }.bind(this)) .fail(Notification.exception) diff --git a/mod/forum/amd/build/grades/expandconversation.min.js b/mod/forum/amd/build/grades/expandconversation.min.js index 4e07f093d2d..f295fd35f72 100644 --- a/mod/forum/amd/build/grades/expandconversation.min.js +++ b/mod/forum/amd/build/grades/expandconversation.min.js @@ -1,2 +1,2 @@ -define ("mod_forum/grades/expandconversation",["exports","./grader/selectors","mod_forum/repository","core/notification","core/templates","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=i(b);c=h(c);e=h(e);f=i(f);g=i(g);function h(a){return a&&a.__esModule?a:{default:a}}function i(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}function j(a,b){return m(a)||l(a,b)||k()}function k(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function l(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function m(a){if(Array.isArray(a))return a}function n(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function o(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){n(h,d,e,f,g,"next",a)}function g(a){n(h,d,e,f,g,"throw",a)}f(void 0)})}}var p=function(a){return a.closest(b.expandConversation)},q=function(){var a=o(regeneratorRuntime.mark(function a(b){var d,h,i,k,l,m,n,o,p;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d=b.dataset.postid;h=b.dataset.discussionid;i=b.dataset.name;a.next=5;return Promise.all([c.default.getDiscussionPosts(parseInt(h)),f.create({title:i,large:!0,type:f.types.CANCEL})]);case 5:k=a.sent;l=j(k,2);m=l[0];n=l[1];o=m.posts.map(function(a){a.subject=null;a.readonly=!0;a.html.rating=null;return a});n.getRoot().on(g.hidden,function(){n.destroy()});n.show();p=e.default.render("mod_forum/grades/grader/discussion/post_modal",o);n.setBody(p);p.then(function(){var a=n.getRoot()[0].querySelector("#p".concat(d));if(a){a.scrollIntoView({behavior:"smooth"})}return});case 15:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.registerEventListeners=function registerEventListeners(a){a.addEventListener("click",function(a){var b=p(a.target);if(b){a.preventDefault();try{q(b)}catch(a){(0,d.exception)(a)}}})}}); +define ("mod_forum/grades/expandconversation",["exports","./grader/selectors","mod_forum/repository","core/notification","core/templates","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=i(b);c=h(c);e=h(e);f=i(f);g=i(g);function h(a){return a&&a.__esModule?a:{default:a}}function i(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}function j(a,b){return m(a)||l(a,b)||k()}function k(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function l(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function m(a){if(Array.isArray(a))return a}function n(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function o(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){n(h,d,e,f,g,"next",a)}function g(a){n(h,d,e,f,g,"throw",a)}f(void 0)})}}var p=function(a){return a.closest(b.expandConversation)},q=function(){var a=o(regeneratorRuntime.mark(function a(b){var d,h,i,k,l,m,n,o,p,q;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d=b.dataset.postid;h=b.dataset.discussionid;i=b.dataset.name;a.next=5;return Promise.all([c.default.getDiscussionPosts(parseInt(h)),f.create({title:i,large:!0,type:f.types.CANCEL})]);case 5:k=a.sent;l=j(k,2);m=l[0];n=l[1];o=new Map(m.posts.map(function(a){a.readonly=!0;a.hasreplies=!1;a.replies=[];return[a.id,a]}));p=[];m.posts.forEach(function(a){if(a.parentid){var b=o.get(a.parentid);if(b){b.hasreplies=!0;b.replies.push(a)}else{p.push(a)}}else{p.push(a)}});n.getRoot().on(g.hidden,function(){n.destroy()});n.getRoot().on(g.bodyRendered,function(){var a=n.getRoot()[0].querySelector("#p".concat(d));if(a){a.scrollIntoView({behavior:"smooth"})}});n.show();q=e.default.render("mod_forum/grades/grader/discussion/post_modal",{posts:p});n.setBody(q);case 17:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.registerEventListeners=function registerEventListeners(a){a.addEventListener("click",function(a){var b=p(a.target);if(b){a.preventDefault();try{q(b)}catch(a){(0,d.exception)(a)}}})}}); //# sourceMappingURL=expandconversation.min.js.map diff --git a/mod/forum/amd/build/grades/expandconversation.min.js.map b/mod/forum/amd/build/grades/expandconversation.min.js.map index 1f1bf289264..e6b0b93da3e 100644 --- a/mod/forum/amd/build/grades/expandconversation.min.js.map +++ b/mod/forum/amd/build/grades/expandconversation.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/grades/expandconversation.js"],"names":["findGradableNode","node","closest","ForumSelectors","expandConversation","showPostInContext","rootNode","postId","dataset","postid","discussionId","discussionid","discussionName","name","Promise","all","Repository","getDiscussionPosts","parseInt","Modal","create","title","large","type","types","CANCEL","allPosts","modal","userPosts","posts","map","post","subject","readonly","html","rating","getRoot","on","ModalEvents","hidden","destroy","show","templatePromise","Templates","render","setBody","then","relevantPost","querySelector","scrollIntoView","behavior","registerEventListeners","addEventListener","e","target","preventDefault","err"],"mappings":"0SAuBA,OACA,OAEA,OACA,OACA,O,4lCAQMA,CAAAA,CAAgB,CAAG,SAAAC,CAAI,QAAIA,CAAAA,CAAI,CAACC,OAAL,CAAaC,CAAc,CAACC,kBAA5B,CAAJ,C,CAOvBC,CAAiB,4CAAG,WAAMC,CAAN,yGAChBC,CADgB,CACPD,CAAQ,CAACE,OAAT,CAAiBC,MADV,CAEhBC,CAFgB,CAEDJ,CAAQ,CAACE,OAAT,CAAiBG,YAFhB,CAGhBC,CAHgB,CAGCN,CAAQ,CAACE,OAAT,CAAiBK,IAHlB,gBAQZC,CAAAA,OAAO,CAACC,GAAR,CAAY,CAClBC,UAAWC,kBAAX,CAA8BC,QAAQ,CAACR,CAAD,CAAtC,CADkB,CAElBS,CAAK,CAACC,MAAN,CAAa,CACTC,KAAK,CAAET,CADE,CAETU,KAAK,GAFI,CAGTC,IAAI,CAAEJ,CAAK,CAACK,KAAN,CAAYC,MAHT,CAAb,CAFkB,CAAZ,CARY,0BAMlBC,CANkB,MAOlBC,CAPkB,MAiBhBC,CAjBgB,CAiBJF,CAAQ,CAACG,KAAT,CAAeC,GAAf,CAAmB,SAACC,CAAD,CAAU,CAC3CA,CAAI,CAACC,OAAL,CAAe,IAAf,CACAD,CAAI,CAACE,QAAL,IACAF,CAAI,CAACG,IAAL,CAAUC,MAAV,CAAmB,IAAnB,CAEA,MAAOJ,CAAAA,CACV,CANiB,CAjBI,CA0BtBJ,CAAK,CAACS,OAAN,GAAgBC,EAAhB,CAAmBC,CAAW,CAACC,MAA/B,CAAuC,UAAW,CAE9CZ,CAAK,CAACa,OAAN,EACH,CAHD,EAKAb,CAAK,CAACc,IAAN,GAGMC,CAlCgB,CAkCEC,UAAUC,MAAV,CAAiB,+CAAjB,CAAkEhB,CAAlE,CAlCF,CAmCtBD,CAAK,CAACkB,OAAN,CAAcH,CAAd,EAEAA,CAAe,CAACI,IAAhB,CAAqB,UAAM,CACvB,GAAMC,CAAAA,CAAY,CAAGpB,CAAK,CAACS,OAAN,GAAgB,CAAhB,EAAmBY,aAAnB,aAAsCzC,CAAtC,EAArB,CACA,GAAIwC,CAAJ,CAAkB,CACdA,CAAY,CAACE,cAAb,CAA4B,CAACC,QAAQ,CAAE,QAAX,CAA5B,CACH,CAED,MACH,CAPD,EArCsB,yCAAH,uD,0BAoDe,QAAzBC,CAAAA,sBAAyB,CAAC7C,CAAD,CAAc,CAChDA,CAAQ,CAAC8C,gBAAT,CAA0B,OAA1B,CAAmC,SAACC,CAAD,CAAO,CACtC,GAAM/C,CAAAA,CAAQ,CAAGN,CAAgB,CAACqD,CAAC,CAACC,MAAH,CAAjC,CAEA,GAAIhD,CAAJ,CAAc,CACV+C,CAAC,CAACE,cAAF,GAEA,GAAI,CACAlD,CAAiB,CAACC,CAAD,CACpB,CAAC,MAAOkD,CAAP,CAAY,CACV,gBAAcA,CAAd,CACH,CACJ,CACJ,CAZD,CAaH,C","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 module handles the creation of a Modal that shows the user's post in context of the entire discussion.\n *\n * @module mod_forum/grades/expandconversation\n * @package mod_forum\n * @copyright 2019 Mathew May \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as ForumSelectors from './grader/selectors';\nimport Repository from 'mod_forum/repository';\nimport {exception as showException} from \"core/notification\";\nimport Templates from 'core/templates';\nimport * as Modal from 'core/modal_factory';\nimport * as ModalEvents from 'core/modal_events';\n\n/**\n * Find the Node containing the gradable details from the provided node by searching up the tree.\n *\n * @param {HTMLElement} node\n * @returns {HTMLElement}\n */\nconst findGradableNode = node => node.closest(ForumSelectors.expandConversation);\n\n/**\n * Show the post in context in a modal.\n *\n * @param {HTMLElement} rootNode The button that has been clicked\n */\nconst showPostInContext = async(rootNode) => {\n const postId = rootNode.dataset.postid;\n const discussionId = rootNode.dataset.discussionid;\n const discussionName = rootNode.dataset.name;\n\n const [\n allPosts,\n modal,\n ] = await Promise.all([\n Repository.getDiscussionPosts(parseInt(discussionId)),\n Modal.create({\n title: discussionName,\n large: true,\n type: Modal.types.CANCEL\n }),\n ]);\n\n const userPosts = allPosts.posts.map((post) => {\n post.subject = null;\n post.readonly = true;\n post.html.rating = null;\n\n return post;\n });\n\n // Handle hidden event.\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Destroy when hidden.\n modal.destroy();\n });\n\n modal.show();\n\n // Note: We do not use await here because it messes with the Modal transitions.\n const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', userPosts);\n modal.setBody(templatePromise);\n // eslint-disable-next-line promise/catch-or-return\n templatePromise.then(() => {\n const relevantPost = modal.getRoot()[0].querySelector(`#p${postId}`);\n if (relevantPost) {\n relevantPost.scrollIntoView({behavior: \"smooth\"});\n }\n\n return;\n });\n};\n\n/**\n * Register event listeners for the expand conversations button.\n *\n * @param {HTMLElement} rootNode The root to listen to.\n */\nexport const registerEventListeners = (rootNode) => {\n rootNode.addEventListener('click', (e) => {\n const rootNode = findGradableNode(e.target);\n\n if (rootNode) {\n e.preventDefault();\n\n try {\n showPostInContext(rootNode);\n } catch (err) {\n showException(err);\n }\n }\n });\n};\n"],"file":"expandconversation.min.js"} \ No newline at end of file +{"version":3,"sources":["../../src/grades/expandconversation.js"],"names":["findGradableNode","node","closest","ForumSelectors","expandConversation","showPostInContext","rootNode","postId","dataset","postid","discussionId","discussionid","discussionName","name","Promise","all","Repository","getDiscussionPosts","parseInt","Modal","create","title","large","type","types","CANCEL","allPosts","modal","postsById","Map","posts","map","post","readonly","hasreplies","replies","id","forEach","parentid","parent","get","push","getRoot","on","ModalEvents","hidden","destroy","bodyRendered","relevantPost","querySelector","scrollIntoView","behavior","show","templatePromise","Templates","render","setBody","registerEventListeners","addEventListener","e","target","preventDefault","err"],"mappings":"0SAuBA,OACA,OAEA,OACA,OACA,O,4lCAQMA,CAAAA,CAAgB,CAAG,SAAAC,CAAI,QAAIA,CAAAA,CAAI,CAACC,OAAL,CAAaC,CAAc,CAACC,kBAA5B,CAAJ,C,CAOvBC,CAAiB,4CAAG,WAAMC,CAAN,2GAChBC,CADgB,CACPD,CAAQ,CAACE,OAAT,CAAiBC,MADV,CAEhBC,CAFgB,CAEDJ,CAAQ,CAACE,OAAT,CAAiBG,YAFhB,CAGhBC,CAHgB,CAGCN,CAAQ,CAACE,OAAT,CAAiBK,IAHlB,gBAQZC,CAAAA,OAAO,CAACC,GAAR,CAAY,CAClBC,UAAWC,kBAAX,CAA8BC,QAAQ,CAACR,CAAD,CAAtC,CADkB,CAElBS,CAAK,CAACC,MAAN,CAAa,CACTC,KAAK,CAAET,CADE,CAETU,KAAK,GAFI,CAGTC,IAAI,CAAEJ,CAAK,CAACK,KAAN,CAAYC,MAHT,CAAb,CAFkB,CAAZ,CARY,0BAMlBC,CANkB,MAOlBC,CAPkB,MAiBhBC,CAjBgB,CAiBJ,GAAIC,CAAAA,GAAJ,CAAQH,CAAQ,CAACI,KAAT,CAAeC,GAAf,CAAmB,SAAAC,CAAI,CAAI,CACjDA,CAAI,CAACC,QAAL,IACAD,CAAI,CAACE,UAAL,IACAF,CAAI,CAACG,OAAL,CAAe,EAAf,CACA,MAAO,CAACH,CAAI,CAACI,EAAN,CAAUJ,CAAV,CACV,CALyB,C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N,CAAgB,CAAC2D,CAAC,CAACC,MAAH,CAAjC,CAEA,GAAItD,CAAJ,CAAc,CACVqD,CAAC,CAACE,cAAF,GAEA,GAAI,CACAxD,CAAiB,CAACC,CAAD,CACpB,CAAC,MAAOwD,CAAP,CAAY,CACV,gBAAcA,CAAd,CACH,CACJ,CACJ,CAZD,CAaH,C","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 module handles the creation of a Modal that shows the user's post in context of the entire discussion.\n *\n * @module mod_forum/grades/expandconversation\n * @package mod_forum\n * @copyright 2019 Mathew May \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as ForumSelectors from './grader/selectors';\nimport Repository from 'mod_forum/repository';\nimport {exception as showException} from \"core/notification\";\nimport Templates from 'core/templates';\nimport * as Modal from 'core/modal_factory';\nimport * as ModalEvents from 'core/modal_events';\n\n/**\n * Find the Node containing the gradable details from the provided node by searching up the tree.\n *\n * @param {HTMLElement} node\n * @returns {HTMLElement}\n */\nconst findGradableNode = node => node.closest(ForumSelectors.expandConversation);\n\n/**\n * Show the post in context in a modal.\n *\n * @param {HTMLElement} rootNode The button that has been clicked\n */\nconst showPostInContext = async(rootNode) => {\n const postId = rootNode.dataset.postid;\n const discussionId = rootNode.dataset.discussionid;\n const discussionName = rootNode.dataset.name;\n\n const [\n allPosts,\n modal,\n ] = await Promise.all([\n Repository.getDiscussionPosts(parseInt(discussionId)),\n Modal.create({\n title: discussionName,\n large: true,\n type: Modal.types.CANCEL\n }),\n ]);\n\n const postsById = new Map(allPosts.posts.map(post => {\n post.readonly = true;\n post.hasreplies = false;\n post.replies = [];\n return [post.id, post];\n }));\n\n let posts = [];\n allPosts.posts.forEach(post => {\n if (post.parentid) {\n const parent = postsById.get(post.parentid);\n if (parent) {\n parent.hasreplies = true;\n parent.replies.push(post);\n } else {\n posts.push(post);\n }\n } else {\n posts.push(post);\n }\n });\n\n // Handle hidden event.\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Destroy when hidden.\n modal.destroy();\n });\n\n modal.getRoot().on(ModalEvents.bodyRendered, () => {\n const relevantPost = modal.getRoot()[0].querySelector(`#p${postId}`);\n if (relevantPost) {\n relevantPost.scrollIntoView({behavior: \"smooth\"});\n }\n });\n\n modal.show();\n\n // Note: We do not use await here because it messes with the Modal transitions.\n const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', {posts});\n modal.setBody(templatePromise);\n};\n\n/**\n * Register event listeners for the expand conversations button.\n *\n * @param {HTMLElement} rootNode The root to listen to.\n */\nexport const registerEventListeners = (rootNode) => {\n rootNode.addEventListener('click', (e) => {\n const rootNode = findGradableNode(e.target);\n\n if (rootNode) {\n e.preventDefault();\n\n try {\n showPostInContext(rootNode);\n } catch (err) {\n showException(err);\n }\n }\n });\n};\n"],"file":"expandconversation.min.js"} \ No newline at end of file diff --git a/mod/forum/amd/src/grades/expandconversation.js b/mod/forum/amd/src/grades/expandconversation.js index face93f78b3..591cbe6d36b 100644 --- a/mod/forum/amd/src/grades/expandconversation.js +++ b/mod/forum/amd/src/grades/expandconversation.js @@ -58,12 +58,26 @@ const showPostInContext = async(rootNode) => { }), ]); - const userPosts = allPosts.posts.map((post) => { - post.subject = null; + const postsById = new Map(allPosts.posts.map(post => { post.readonly = true; - post.html.rating = null; + post.hasreplies = false; + post.replies = []; + return [post.id, post]; + })); - return post; + let posts = []; + allPosts.posts.forEach(post => { + if (post.parentid) { + const parent = postsById.get(post.parentid); + if (parent) { + parent.hasreplies = true; + parent.replies.push(post); + } else { + posts.push(post); + } + } else { + posts.push(post); + } }); // Handle hidden event. @@ -72,20 +86,18 @@ const showPostInContext = async(rootNode) => { modal.destroy(); }); - modal.show(); - - // Note: We do not use await here because it messes with the Modal transitions. - const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', userPosts); - modal.setBody(templatePromise); - // eslint-disable-next-line promise/catch-or-return - templatePromise.then(() => { + modal.getRoot().on(ModalEvents.bodyRendered, () => { const relevantPost = modal.getRoot()[0].querySelector(`#p${postId}`); if (relevantPost) { relevantPost.scrollIntoView({behavior: "smooth"}); } - - return; }); + + modal.show(); + + // Note: We do not use await here because it messes with the Modal transitions. + const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', {posts}); + modal.setBody(templatePromise); }; /** diff --git a/mod/forum/templates/grades/grader/discussion/post_modal.mustache b/mod/forum/templates/grades/grader/discussion/post_modal.mustache index f402197c970..e03c700caeb 100644 --- a/mod/forum/templates/grades/grader/discussion/post_modal.mustache +++ b/mod/forum/templates/grades/grader/discussion/post_modal.mustache @@ -30,7 +30,7 @@ } }}
- {{#.}} - {{> mod_forum/forum_discussion_nested_v2_post_reply }} - {{/.}} + {{#posts}} + {{> mod_forum/forum_discussion_nested_post }} + {{/posts}}