MDL-67264 core_course: Activity chooser new feature
[moodle.git] / course / amd / build / local / activitychooser / dialogue.min.js
1 define ("core_course/local/activitychooser/dialogue",["exports","jquery","core/modal_events","core_course/local/activitychooser/selectors","core/templates","core/key_codes","core/loadingicon"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.displayChooser=void 0;b=i(b);c=h(c);d=i(d);e=h(e);function h(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 i(a){return a&&a.__esModule?a:{default:a}}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}var n=function(a,b){var c=a.find(d.default.regions.help)[0];c.innerHTML="";var f=(0,g.addIconToContainer)(c),h=null,i=new Promise(function(a){h=a}),k=e.renderForPromise("core_course/chooser_help",b);Promise.all([k,f,i]).then(function(a){var b=j(a,1),d=b[0],f=d.html,g=d.js;return e.replaceNodeContents(c,f,g)}).then(function(){c.querySelector(d.default.regions.chooserSummary.description).focus();return c}).catch(Notification.exception);a.one("slid.bs.carousel",function(){h()});a.carousel("next")},o=function(a,c){var e=function(f){if(f.target.closest(d.default.actions.optionActions.showSummary)){var e=(0,b.default)(a.getBody()[0].querySelector(d.default.regions.carousel)),g=f.target.closest(d.default.regions.chooserOption.container),h=g.dataset.modname,i=c.get(h);n(e,i)}if(f.target.matches(d.default.actions.closeOption)){var j=(0,b.default)(a.getBody()[0].querySelector(d.default.regions.carousel));j.carousel("prev");j.on("slid.bs.carousel",function(){var b=a.getBody()[0].querySelector(d.default.regions.modules),c=b.querySelector(d.default.regions.getModuleSelector(f.target.dataset.modname));c.focus()})}};a.getBodyPromise().then(function(a){return a[0]}).then(function(a){(0,b.default)(a.querySelector(d.default.regions.carousel)).carousel({interval:!1,pause:!0,keyboard:!1});return a}).then(function(a){a.addEventListener("click",e);return a}).then(function(a){p(a,c);return a}).catch()},p=function(a,c){var e=a.querySelectorAll(d.default.regions.chooserOption.container);Array.from(e).forEach(function(e){return e.addEventListener("keyup",function(g){var e=document.querySelector(d.default.regions.chooserOptions);if(g.keyCode===f.enter||g.keyCode===f.space){if(g.target.matches(d.default.actions.optionActions.showSummary)){g.preventDefault();var h=g.target.closest(d.default.regions.chooserOption.container),i=h.dataset.modname,j=c.get(i),k=(0,b.default)(a.querySelector(d.default.regions.carousel));k.carousel({interval:!1,pause:!0,keyboard:!1});n(k,j)}}if(g.keyCode===f.arrowRight){g.preventDefault();var l=g.target.closest(d.default.regions.chooserOption.container),m=l.nextElementSibling,o=e.firstElementChild,p=r(m,o);q(p,l)}if(g.keyCode===f.arrowLeft){g.preventDefault();var s=g.target.closest(d.default.regions.chooserOption.container),t=s.previousElementSibling,u=e.lastElementChild,v=r(t,u);q(v,s)}if(g.keyCode===f.home){g.preventDefault();var w=g.target.closest(d.default.regions.chooserOption.container),x=e.firstElementChild;q(x,w)}if(g.keyCode===f.end){g.preventDefault();var y=g.target.closest(d.default.regions.chooserOption.container),z=e.lastElementChild;q(z,y)}})})},q=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:!1;if(!1!==b){var c=b.querySelector(d.default.actions.addChooser),e=b.querySelector(d.default.actions.optionActions.showSummary);b.tabIndex=-1;c.tabIndex=-1;e.tabIndex=-1}var f=a.querySelector(d.default.actions.addChooser),g=a.querySelector(d.default.actions.optionActions.showSummary);a.tabIndex=0;f.tabIndex=0;g.tabIndex=0;a.focus()},r=function(a,b){if(null!==a){return a}else{return b}},s=function(a,b,e){var f=new Map;e.forEach(function(a){f.set(a.modulename,a)});o(b,f);b.getRoot().on(c.hidden,function(){b.destroy()});b.getRoot().on(c.shown,function(){b.getModal()[0].tabIndex=-1;b.getBodyPromise().then(function(a){var b=a[0].querySelector(d.default.regions.chooserOption.container);q(b)}).catch(Notification.exception)});b.show()};a.displayChooser=s});
2 //# sourceMappingURL=dialogue.min.js.map