MDL-69301 course: Remove custom keyboard navigation code
[moodle.git] / course / amd / build / local / activitychooser / dialogue.min.js
1 function _typeof(a){"@babel/helpers - typeof";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_course/local/activitychooser/dialogue",["exports","jquery","core/modal_events","core_course/local/activitychooser/selectors","core/templates","core/key_codes","core/loadingicon","core_course/local/activitychooser/repository","core/notification","core/utils"],function(a,b,c,d,e,f,g,h,i,j){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.displayChooser=void 0;b=m(b);c=l(c);d=m(d);e=l(e);h=l(h);i=m(i);var v="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function k(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;k=function(){return a};return a}function l(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=k();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function m(a){return a&&a.__esModule?a:{default: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)})}}function p(a,b){return u(a)||t(a,b)||r(a,b)||q()}function q(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function r(a,b){if(!a)return;if("string"==typeof a)return s(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return s(a,b)}function s(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}function t(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;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 u(a){if(Array.isArray(a))return a}var w=function(a){return"function"==typeof v.define&&v.define.amd?new Promise(function(b,c){v.require([a],b,c)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&v.require&&"component"===v.require.loader?Promise.resolve(require((a))):Promise.resolve(v[a])},x=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(null!==c&&!0===b.showFooter){c.setFooter(e.render("core_course/local/activitychooser/footer_partial",b))}var f=a.find(d.default.regions.help)[0];f.innerHTML="";f.classList.add("m-auto");var h=(0,g.addIconToContainer)(f),j=null,k=new Promise(function(a){j=a}),l=e.renderForPromise("core_course/local/activitychooser/help",b);Promise.all([l,h,k]).then(function(a){var b=p(a,1),c=b[0],d=c.html,g=c.js;return e.replaceNodeContents(f,d,g)}).then(function(){f.querySelector(d.default.regions.chooserSummary.header).focus();return f}).catch(i.default.exception);a.one("slid.bs.carousel",function(){j()});a.carousel("next")},y=function(){var a=o(regeneratorRuntime.mark(function a(b,c,d){var e,f,g,i;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:e=c.dataset.favourited;f=c.dataset.id;g=c.dataset.name;i=c.dataset.internal;if(!("true"===e)){a.next=10;break}a.next=7;return h.unfavouriteModule(g,f);case 7:d(i,!1,b);a.next=13;break;case 10:a.next=12;return h.favouriteModule(g,f);case 12:d(i,!0,b);case 13:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),z=function(a,c,f,g){var h=function(){var e=o(regeneratorRuntime.mark(function g(h){var e,i,j,k,l,m,n,o,p,q;return regeneratorRuntime.wrap(function(g){while(1){switch(g.prev=g.next){case 0:if(h.target.closest(d.default.actions.optionActions.showSummary)){e=(0,b.default)(a.getBody()[0].querySelector(d.default.regions.carousel));i=h.target.closest(d.default.regions.chooserOption.container);j=i.dataset.modname;k=c.get(j);k.showFooter=a.hasFooterContent();x(e,k,a)}if(!h.target.closest(d.default.actions.optionActions.manageFavourite)){g.next=10;break}l=h.target.closest(d.default.actions.optionActions.manageFavourite);g.next=5;return y(a.getBody()[0],l,f);case 5:m=a.getBody()[0].querySelector(d.default.elements.activetab).getAttribute("href");n=a.getBody()[0].querySelector(d.default.regions.getSectionChooserOptions(m));o=n.querySelector(d.default.regions.chooserOption.container);C(o,!0);A(a.getBody()[0],c,n,a);case 10:if(h.target.matches(d.default.actions.closeOption)){p=(0,b.default)(a.getBody()[0].querySelector(d.default.regions.carousel));p.carousel("prev");p.on("slid.bs.carousel",function(){var b=a.getBody()[0].querySelector(d.default.regions.modules),c=b.querySelector(d.default.regions.getModuleSelector(h.target.dataset.modname));c.focus()})}if(h.target.closest(d.default.actions.clearSearch)){q=a.getBody()[0].querySelector(d.default.actions.search);q.value="";q.focus();F(a,c,q.value)}case 12:case"end":return g.stop();}}},g)}));return function(){return e.apply(this,arguments)}}(),i=function(){var b=o(regeneratorRuntime.mark(function b(c){var d;return regeneratorRuntime.wrap(function(b){while(1){switch(b.prev=b.next){case 0:if(!(!0===g.footer)){b.next=6;break}b.next=3;return w(g.customfooterjs);case 3:d=b.sent;b.next=6;return d.footerClickListener(c,g,a);case 6:case"end":return b.stop();}}},b)}));return function(){return b.apply(this,arguments)}}();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",h);return a}).then(function(b){var e=b.querySelector(d.default.actions.search);e.addEventListener("input",(0,j.debounce)(function(){F(a,c,e.value)},300));return b}).then(function(b){var e=b.querySelector(d.default.elements.activetab).getAttribute("href"),f=b.querySelector(d.default.regions.getSectionChooserOptions(e)),g=f.querySelector(d.default.regions.chooserOption.container);C(g,!0);A(b,c,f,a);return b}).catch();a.getFooterPromise().then(function(a){return a[0]}).then(function(a){a.addEventListener("click",i);return a}).catch()},A=function(a,c,g){var h=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null,i=g.querySelectorAll(d.default.regions.chooserOption.container);Array.from(i).forEach(function(e){return e.addEventListener("keydown",function(i){if(i.keyCode===f.enter||i.keyCode===f.space){if(i.target.matches(d.default.actions.optionActions.showSummary)){i.preventDefault();var e=i.target.closest(d.default.regions.chooserOption.container),j=e.dataset.modname,k=c.get(j),l=(0,b.default)(a.querySelector(d.default.regions.carousel));l.carousel({interval:!1,pause:!0,keyboard:!1});k.showFooter=h.hasFooterContent();x(l,k,h)}}if(i.keyCode===f.arrowRight){i.preventDefault();var m=i.target.closest(d.default.regions.chooserOption.container),n=m.nextElementSibling,o=g.firstElementChild,p=D(n,o);B(p,m)}if(i.keyCode===f.arrowLeft){i.preventDefault();var q=i.target.closest(d.default.regions.chooserOption.container),r=q.previousElementSibling,s=g.lastElementChild,t=D(r,s);B(t,q)}if(i.keyCode===f.home){i.preventDefault();var u=i.target.closest(d.default.regions.chooserOption.container),v=g.firstElementChild;B(v,u)}if(i.keyCode===f.end){i.preventDefault();var w=i.target.closest(d.default.regions.chooserOption.container),y=g.lastElementChild;B(y,w)}})})},B=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:null;if(null!==b){C(b,!1)}C(a,!0);a.focus()},C=function(a,b){var c=a.querySelector(d.default.actions.addChooser),e=a.querySelector(d.default.actions.optionActions.showSummary),f=a.querySelector(d.default.actions.optionActions.manageFavourite);if(b){a.tabIndex=0;c.tabIndex=0;e.tabIndex=0;f.tabIndex=0}else{a.tabIndex=-1;c.tabIndex=-1;e.tabIndex=-1;f.tabIndex=-1}},D=function(a,b){if(null!==a){return a}else{return b}},E=function(){var a=o(regeneratorRuntime.mark(function a(b,c){var d,f,g,h;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d={searchresultsnumber:c.length,searchresults:c};a.next=3;return e.renderForPromise("core_course/local/activitychooser/search_results",d);case 3:f=a.sent;g=f.html;h=f.js;a.next=8;return e.replaceNodeContents(b,g,h);case 8:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),F=function(){var a=o(regeneratorRuntime.mark(function a(b,c,e){var f,g,h,i,j,k,l;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:f=b.getBody()[0];g=f.querySelector(d.default.regions.searchResults);h=f.querySelector(d.default.regions.chooser);i=f.querySelector(d.default.actions.clearSearch);if(!(0<e.length)){a.next=16;break}j=G(c,e);a.next=8;return E(g,j);case 8:k=g.querySelector(d.default.regions.searchResultItems);l=k.querySelector(d.default.regions.chooserOption.container);if(l){C(l,!0);A(f,c,k,b)}i.classList.remove("d-none");h.setAttribute("hidden","hidden");g.removeAttribute("hidden");a.next=19;break;case 16:i.classList.add("d-none");g.setAttribute("hidden","hidden");h.removeAttribute("hidden");case 19:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),G=function(a,b){if(""===b){return a}b=b.toLowerCase();var c=[];a.forEach(function(a){var d=a.title.toLowerCase(),e=a.help.toLowerCase();if(d.includes(b)||e.includes(b)){c.push(a)}});return c},H=function(a,c){a.getModal()[0].tabIndex=-1;a.getBodyPromise().then(function(f){(0,b.default)(d.default.elements.tab).on("shown.bs.tab",function(b){var e=b.target.getAttribute("href"),g=f[0].querySelector(d.default.regions.getSectionChooserOptions(e)),h=g.querySelector(d.default.regions.chooserOption.container),i=b.relatedTarget.getAttribute("href"),j=f[0].querySelector(d.default.regions.getSectionChooserOptions(i));I(j);C(h,!0);A(f[0],c,g,a)})}).catch(i.default.exception)},I=function(a){var b=a.querySelectorAll(d.default.regions.chooserOption.container);b.forEach(function(a){C(a,!1)})};a.displayChooser=function displayChooser(a,b,d,e){var f=new Map;b.forEach(function(a){f.set(a.componentname+"_"+a.link,a)});a.then(function(a){z(a,f,d,e);H(a,f);a.getRoot().on(c.hidden,function(){a.destroy()});return a}).catch()}});
2 //# sourceMappingURL=dialogue.min.js.map