moodle/course/format/amd/build/local/content.min.js

2 lines
9.7 KiB
JavaScript

define ("core_courseformat/local/content",["exports","core/reactive","core_courseformat/courseeditor","core/inplace_editable","core_courseformat/local/content/section","core_courseformat/local/content/section/cmitem","core_course/actions","core_courseformat/local/content/actions"],function(a,b,c,d,e,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;d=i(d);e=i(e);f=i(f);g=i(g);h=i(h);function i(a){return a&&a.__esModule?a:{default:a}}function j(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){j=function(a){return typeof a}}else{j=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return j(a)}function k(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 l(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){k(h,d,e,f,g,"next",a)}function g(a){k(h,d,e,f,g,"throw",a)}f(void 0)})}}function m(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);if(b)d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable});c.push.apply(c,d)}return c}function n(a){for(var b=1,c;b<arguments.length;b++){c=null!=arguments[b]?arguments[b]:{};if(b%2){m(Object(c),!0).forEach(function(b){o(a,b,c[b])})}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(a,Object.getOwnPropertyDescriptors(c))}else{m(Object(c)).forEach(function(b){Object.defineProperty(a,b,Object.getOwnPropertyDescriptor(c,b))})}}return a}function o(a,b,c){if(b in a){Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0})}else{a[b]=c}return a}function p(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}function q(a,b){for(var c=0,d;c<b.length;c++){d=b[c];d.enumerable=d.enumerable||!1;d.configurable=!0;if("value"in d)d.writable=!0;Object.defineProperty(a,d.key,d)}}function r(a,b,c){if(b)q(a.prototype,b);if(c)q(a,c);return a}function s(a,b){if("function"!=typeof b&&null!==b){throw new TypeError("Super expression must either be null or a function")}a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}});if(b)t(a,b)}function t(a,b){t=Object.setPrototypeOf||function(a,b){a.__proto__=b;return a};return t(a,b)}function u(a){return function(){var b=y(a),c;if(x()){var d=y(this).constructor;c=Reflect.construct(b,arguments,d)}else{c=b.apply(this,arguments)}return v(this,c)}}function v(a,b){if(b&&("object"===j(b)||"function"==typeof b)){return b}return w(a)}function w(a){if(void 0===a){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return a}function x(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{Date.prototype.toString.call(Reflect.construct(Date,[],function(){}));return!0}catch(a){return!1}}function y(a){y=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)};return y(a)}var z=function(a){s(b,a);var i=u(b);function b(){p(this,b);return i.apply(this,arguments)}r(b,[{key:"create",value:function create(a){var b;this.name="course_format";this.selectors={SECTION:"[data-for='section']",SECTION_ITEM:"[data-for='section_title']",SECTION_CMLIST:"[data-for='cmlist']",COURSE_SECTIONLIST:"[data-for='course_sectionlist']",CM:"[data-for='cmitem']",TOGGLER:"[data-action=\"togglecoursecontentsection\"]",COLLAPSE:"[data-toggle=\"collapse\"]",ACTIVITYTAG:"li",SECTIONTAG:"li"};this.classes={COLLAPSED:"collapsed",ACTIVITY:"activity",STATEDREADY:"stateready",SECTION:"section"};this.dettachedCms={};this.dettachedSections={};this.sections={};this.cms={};this.sectionReturn=null!==(b=a.sectionReturn)&&void 0!==b?b:0}},{key:"stateReady",value:function stateReady(){this._indexContents();this.addEventListener(this.element,"click",this._sectionTogglers);if(this.reactive.supportComponents){if(this.reactive.isEditing){new h.default(this)}this.element.classList.add(this.classes.STATEDREADY)}}},{key:"_sectionTogglers",value:function _sectionTogglers(a){var b=a.target.closest(this.selectors.TOGGLER),c=a.target.closest(this.selectors.COLLAPSE);if(b||c){var d,e=a.target.closest(this.selectors.SECTION),f=e.querySelector(this.selectors.COLLAPSE),g=null!==(d=null===f||void 0===f?void 0:f.classList.contains(this.classes.COLLAPSED))&&void 0!==d?d:!1;if(c||g){var h=e.getAttribute("data-id");this.reactive.dispatch("sectionPreferences",[h],{contentexpanded:g})}}}},{key:"getWatchers",value:function getWatchers(){this.reactive.sectionReturn=this.sectionReturn;if(!this.reactive.supportComponents){return[]}return[{watch:"cm.visible:updated",handler:this._reloadCm},{watch:"section.number:updated",handler:this._refreshSectionNumber},{watch:"section.contentexpanded:updated",handler:this._refreshSectionCollapsed},{watch:"transaction:start",handler:this._startProcessing},{watch:"course.sectionlist:updated",handler:this._refreshCourseSectionlist},{watch:"section.cmlist:updated",handler:this._refreshSectionCmlist},{watch:"state:updated",handler:this._indexContents},{watch:"cm.visible:updated",handler:this._reloadCm},{watch:"cm.sectionid:updated",handler:this._reloadCm}]}},{key:"_refreshSectionCollapsed",value:function _refreshSectionCollapsed(a){var b,c=a.element,d=this.getElement(this.selectors.SECTION,c.id);if(!d){throw new Error("Unknown section with ID ".concat(c.id))}var e=d.querySelector(this.selectors.COLLAPSE),f=null!==(b=null===e||void 0===e?void 0:e.classList.contains(this.classes.COLLAPSED))&&void 0!==b?b:!1;if(c.contentexpanded===f){e.click()}}},{key:"_startProcessing",value:function _startProcessing(){this.dettachedCms={};this.dettachedSections={}}},{key:"_refreshSectionNumber",value:function _refreshSectionNumber(a){var b=a.element,c=this.getElement(this.selectors.SECTION,b.id);if(!c){return}c.id="section-".concat(b.number);c.dataset.sectionid=b.number;c.dataset.number=b.number;var e=d.default.getInplaceEditable(c.querySelector(this.selectors.SECTION_ITEM));if(e){var f=e.getValue(),g=e.getItemId();if(""===e.getValue()){if(g==b.id&&(f!=b.rawtitle||""==b.rawtitle)){e.setValue(b.rawtitle)}}}}},{key:"_refreshSectionCmlist",value:function _refreshSectionCmlist(a){var b,c=a.element,d=null!==(b=c.cmlist)&&void 0!==b?b:[],e=this.getElement(this.selectors.SECTION,c.id),f=null===e||void 0===e?void 0:e.querySelector(this.selectors.SECTION_CMLIST),g=this._createCmItem.bind(this);if(f){this._fixOrder(f,d,this.selectors.CM,this.dettachedCms,g)}}},{key:"_refreshCourseSectionlist",value:function _refreshCourseSectionlist(a){var b,c=a.element;if(0!=this.reactive.sectionReturn){return}var d=null!==(b=c.sectionlist)&&void 0!==b?b:[],e=this.getElement(this.selectors.COURSE_SECTIONLIST),f=this._createSectionItem.bind(this);if(e){this._fixOrder(e,d,this.selectors.SECTION,this.dettachedSections,f)}}},{key:"_indexContents",value:function _indexContents(){this._scanIndex(this.selectors.SECTION,this.sections,function(a){return new e.default(a)});this._scanIndex(this.selectors.CM,this.cms,function(a){return new f.default(a)})}},{key:"_scanIndex",value:function _scanIndex(a,b,c){var d=this,e=this.getElements("".concat(a,":not([data-indexed])"));e.forEach(function(a){var e;if(!(null===a||void 0===a?void 0:null===(e=a.dataset)||void 0===e?void 0:e.id)){return}if(b[a.dataset.id]!==void 0){b[a.dataset.id].unregister()}b[a.dataset.id]=c(n({},d,{element:a}));a.dataset.indexed=!0})}},{key:"_reloadCm",value:function _reloadCm(a){var b=this,c=a.element,d=this.getElement(this.selectors.CM,c.id);if(d){var e=g.default.refreshModule(d,c.id);e.then(function(){b._indexContents()}).catch()}}},{key:"_reloadSection",value:function _reloadSection(a){var b=this,c=a.element,d=this.getElement(this.selectors.SECTION,c.id);if(d){var e=g.default.refreshSection(d,c.id);e.then(function(){b._indexContents()}).catch()}}},{key:"_createCmItem",value:function _createCmItem(a,b){var c=document.createElement(this.selectors.ACTIVITYTAG);c.dataset.for="cmitem";c.dataset.id=b;c.id="module-".concat(b);c.classList.add(this.classes.ACTIVITY);a.append(c);this._reloadCm({element:this.reactive.get("cm",b)});return c}},{key:"_createSectionItem",value:function _createSectionItem(a,b){var c=this.reactive.get("section",b),d=document.createElement(this.selectors.SECTIONTAG);d.dataset.for="section";d.dataset.id=b;d.dataset.number=c.number;d.id="section-".concat(b);d.classList.add(this.classes.SECTION);a.append(d);this._reloadSection({element:c});return d}},{key:"_fixOrder",value:function(){var a=l(regeneratorRuntime.mark(function a(b,c,d,e,f){var g=this,h,i,j,k,l;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:if(!(b===void 0)){a.next=2;break}return a.abrupt("return");case 2:if(c.length){a.next=6;break}b.classList.add("hidden");b.innerHTML="";return a.abrupt("return");case 6:b.classList.remove("hidden");c.forEach(function(a,c){var h,i,j=null!==(h=null!==(i=g.getElement(d,a))&&void 0!==i?i:e[a])&&void 0!==h?h:f(b,a);if(j===void 0){return}var k=b.children[c];if(k===void 0){b.append(j);return}if(k!==j){b.insertBefore(j,k)}});while(b.children.length>c.length){j=b.lastChild;if(null===j||void 0===j?void 0:null===(i=j.classList)||void 0===i?void 0:i.contains("dndupload-preview")){h=j}else{e[null!==(k=null===j||void 0===j?void 0:null===(l=j.dataset)||void 0===l?void 0:l.id)&&void 0!==k?k:0]=j}b.removeChild(j)}if(h){b.append(h)}case 10:case"end":return a.stop();}}},a)}));return function _fixOrder(){return a.apply(this,arguments)}}()}],[{key:"init",value:function init(a,d,e){return new b({element:document.getElementById(a),reactive:(0,c.getCurrentCourseEditor)(),selectors:d,sectionReturn:e})}}]);return b}(b.BaseComponent);a.default=z;return a.default});
//# sourceMappingURL=content.min.js.map