From 82bdf4f5de183c237095b366ca975fa284aee740 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:44:44 +0100 Subject: [PATCH] Work in progress #191. --- amd/build/local/content.min.js | 7 ++++--- amd/build/local/content.min.js.map | 2 +- amd/build/popup.min.js | 2 +- amd/build/popup.min.js.map | 2 +- amd/src/popup.js | 23 +++++++++++++++++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/amd/build/local/content.min.js b/amd/build/local/content.min.js index 05295f31..f8d25260 100644 --- a/amd/build/local/content.min.js +++ b/amd/build/local/content.min.js @@ -1,9 +1,10 @@ define("format_grid/local/content",["exports","core_courseformat/local/content","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","core_course/events"],(function(_exports,_content,_courseeditor,_inplace_editable,_section,_cmitem,_actions,_actions2,CourseEvents){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} /** - * Course index main component. + * Grid format Course index main component. * - * @module core_courseformat/local/content - * @class core_courseformat/local/content + * @module format_grid/local/content + * @class format_grid/local/content + * @copyright 2023 G J Barnard based upon work done by: * @copyright 2020 Ferran Recio * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_content=_interopRequireDefault(_content),_inplace_editable=_interopRequireDefault(_inplace_editable),_section=_interopRequireDefault(_section),_cmitem=_interopRequireDefault(_cmitem),_actions=_interopRequireDefault(_actions),_actions2=_interopRequireDefault(_actions2),CourseEvents=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(CourseEvents);class Component extends _content.default{create(descriptor){var _descriptor$sectionRe;this.name="grid_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']",PAGE:"#page",ACTIVITYTAG:"li",SECTIONTAG:"li"},this.classes={ACTIVITY:"activity",STATEDREADY:"stateready",SECTION:"section"},this.dettachedCms={},this.dettachedSections={},this.sections={},this.cms={},this.sectionReturn=null!==(_descriptor$sectionRe=descriptor.sectionReturn)&&void 0!==_descriptor$sectionRe?_descriptor$sectionRe:0}static init(target,selectors,sectionReturn){return new Component({element:document.getElementById(target),reactive:(0,_courseeditor.getCurrentCourseEditor)(),selectors:selectors,sectionReturn:sectionReturn})}stateReady(){this._indexContents(),this.reactive.supportComponents&&(this.reactive.isEditing&&new _actions2.default(this),this.element.classList.add(this.classes.STATEDREADY)),this.addEventListener(this.element,CourseEvents.manualCompletionToggled,this._completionHandler),this.addEventListener(document.querySelector(this.selectors.PAGE),"scroll",this._scrollHandler)}getWatchers(){return this.reactive.sectionReturn=this.sectionReturn,this.reactive.supportComponents?[{watch:"cm.visible:updated",handler:this._reloadCm},{watch:"cm.stealth:updated",handler:this._reloadCm},{watch:"section.number:updated",handler:this._refreshSectionNumber},{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}]:[]}_startProcessing(){this.dettachedCms={},this.dettachedSections={}}_completionHandler(_ref){let{detail:detail}=_ref;void 0!==detail&&this.reactive.dispatch("cmCompletion",[detail.cmid],detail.completed)}_scrollHandler(){const pageOffset=document.querySelector(this.selectors.PAGE).scrollTop,items=this.reactive.getExporter().allItemsArray(this.reactive.state);let pageItem=null;items.every((item=>{const index="section"===item.type?this.sections:this.cms;if(void 0===index[item.id])return!0;const element=index[item.id].element;return"cm"!==item.type||item.url||this.reactive.isEditing?(pageItem=item,pageOffset>=element.offsetTop):pageOffset>=element.offsetTop})),pageItem&&this.reactive.dispatch("setPageItem",pageItem.type,pageItem.id)}_refreshSectionNumber(_ref2){let{element:element}=_ref2;const target=this.getElement(this.selectors.SECTION,element.id);if(!target)return;target.id="section-".concat(element.number),target.dataset.sectionid=element.number,target.dataset.number=element.number;const inplace=_inplace_editable.default.getInplaceEditable(target.querySelector(this.selectors.SECTION_ITEM));if(inplace){const currentvalue=inplace.getValue(),currentitemid=inplace.getItemId();""===inplace.getValue()&&(currentitemid!=element.id||currentvalue==element.rawtitle&&""!=element.rawtitle||inplace.setValue(element.rawtitle))}}_refreshSectionCmlist(_ref3){var _element$cmlist;let{element:element}=_ref3;const cmlist=null!==(_element$cmlist=element.cmlist)&&void 0!==_element$cmlist?_element$cmlist:[],section=this.getElement(this.selectors.SECTION,element.id),listparent=null==section?void 0:section.querySelector(this.selectors.SECTION_CMLIST),createCm=this._createCmItem.bind(this);listparent&&this._fixOrder(listparent,cmlist,this.selectors.CM,this.dettachedCms,createCm)}_refreshCourseSectionlist(_ref4){var _element$sectionlist;let{element:element}=_ref4;if(0!=this.reactive.sectionReturn)return;const sectionlist=null!==(_element$sectionlist=element.sectionlist)&&void 0!==_element$sectionlist?_element$sectionlist:[],listparent=this.getElement(this.selectors.COURSE_SECTIONLIST),createSection=this._createSectionItem.bind(this);listparent&&this._fixOrder(listparent,sectionlist,this.selectors.SECTION,this.dettachedSections,createSection)}_indexContents(){this._scanIndex(this.selectors.SECTION,this.sections,(item=>new _section.default(item))),this._scanIndex(this.selectors.CM,this.cms,(item=>new _cmitem.default(item)))}_scanIndex(selector,index,creationhandler){this.getElements("".concat(selector,":not([data-indexed])")).forEach((item=>{var _item$dataset;null!=item&&null!==(_item$dataset=item.dataset)&&void 0!==_item$dataset&&_item$dataset.id&&(void 0!==index[item.dataset.id]&&index[item.dataset.id].unregister(),index[item.dataset.id]=creationhandler({...this,element:item}),item.dataset.indexed=!0)}))}_reloadCm(_ref5){let{element:element}=_ref5;const cmitem=this.getElement(this.selectors.CM,element.id);if(cmitem){_actions.default.refreshModule(cmitem,element.id).then((()=>{this._indexContents()})).catch()}}_reloadSection(_ref6){let{element:element}=_ref6;const sectionitem=this.getElement(this.selectors.SECTION,element.id);if(sectionitem){_actions.default.refreshSection(sectionitem,element.id).then((()=>{this._indexContents()})).catch()}}_createCmItem(container,cmid){const newItem=document.createElement(this.selectors.ACTIVITYTAG);return newItem.dataset.for="cmitem",newItem.dataset.id=cmid,newItem.id="module-".concat(cmid),newItem.classList.add(this.classes.ACTIVITY),container.append(newItem),this._reloadCm({element:this.reactive.get("cm",cmid)}),newItem}_createSectionItem(container,sectionid){const section=this.reactive.get("section",sectionid),newItem=document.createElement(this.selectors.SECTIONTAG);return newItem.dataset.for="section",newItem.dataset.id=sectionid,newItem.dataset.number=section.number,newItem.id="section-".concat(sectionid),newItem.classList.add(this.classes.SECTION),container.append(newItem),this._reloadSection({element:section}),newItem}async _fixOrder(container,neworder,selector,dettachedelements,createMethod){if(void 0===container)return;if(!neworder.length)return container.classList.add("hidden"),void(container.innerHTML="");let dndFakeActivity;for(container.classList.remove("hidden"),neworder.forEach(((itemid,index)=>{var _ref7,_this$getElement;let item=null!==(_ref7=null!==(_this$getElement=this.getElement(selector,itemid))&&void 0!==_this$getElement?_this$getElement:dettachedelements[itemid])&&void 0!==_ref7?_ref7:createMethod(container,itemid);if(void 0===item)return;const currentitem=container.children[index];void 0!==currentitem?currentitem!==item&&container.insertBefore(item,currentitem):container.append(item)}));container.children.length>neworder.length;){var _lastchild$classList;const lastchild=container.lastChild;var _lastchild$dataset$id,_lastchild$dataset;if(null!=lastchild&&null!==(_lastchild$classList=lastchild.classList)&&void 0!==_lastchild$classList&&_lastchild$classList.contains("dndupload-preview"))dndFakeActivity=lastchild;else dettachedelements[null!==(_lastchild$dataset$id=null==lastchild||null===(_lastchild$dataset=lastchild.dataset)||void 0===_lastchild$dataset?void 0:_lastchild$dataset.id)&&void 0!==_lastchild$dataset$id?_lastchild$dataset$id:0]=lastchild;container.removeChild(lastchild)}dndFakeActivity&&container.append(dndFakeActivity)}}return _exports.default=Component,_exports.default})); diff --git a/amd/build/local/content.min.js.map b/amd/build/local/content.min.js.map index 3a2916e7..58662ab1 100644 --- a/amd/build/local/content.min.js.map +++ b/amd/build/local/content.min.js.map @@ -1 +1 @@ -{"version":3,"file":"content.min.js","sources":["../../src/local/content.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Course index main component.\n *\n * @module core_courseformat/local/content\n * @class core_courseformat/local/content\n * @copyright 2020 Ferran Recio \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport BaseComponent from 'core_courseformat/local/content';\nimport {getCurrentCourseEditor} from 'core_courseformat/courseeditor';\nimport inplaceeditable from 'core/inplace_editable';\nimport Section from 'core_courseformat/local/content/section';\nimport CmItem from 'core_courseformat/local/content/section/cmitem';\n// Course actions is needed for actions that are not migrated to components.\nimport courseActions from 'core_course/actions';\nimport DispatchActions from 'core_courseformat/local/content/actions';\nimport * as CourseEvents from 'core_course/events';\n\nexport default class Component extends BaseComponent {\n\n /**\n * Constructor hook.\n *\n * @param {Object} descriptor the component descriptor\n */\n create(descriptor) {\n // Optional component name for debugging.\n this.name = 'grid_course_format';\n // Default query selectors.\n this.selectors = {\n SECTION: `[data-for='section']`,\n SECTION_ITEM: `[data-for='section_title']`,\n SECTION_CMLIST: `[data-for='cmlist']`,\n COURSE_SECTIONLIST: `[data-for='course_sectionlist']`,\n CM: `[data-for='cmitem']`,\n PAGE: `#page`,\n // Formats can override the activity tag but a default one is needed to create new elements.\n ACTIVITYTAG: 'li',\n SECTIONTAG: 'li',\n };\n // Default classes to toggle on refresh.\n this.classes = {\n //COLLAPSED: `collapsed`,\n // Course content classes.\n ACTIVITY: `activity`,\n STATEDREADY: `stateready`,\n SECTION: `section`,\n };\n // Array to save dettached elements during element resorting.\n this.dettachedCms = {};\n this.dettachedSections = {};\n // Index of sections and cms components.\n this.sections = {};\n this.cms = {};\n // The page section return.\n this.sectionReturn = descriptor.sectionReturn ?? 0;\n }\n\n /**\n * Static method to create a component instance form the mustahce template.\n *\n * @param {string} target the DOM main element or its ID\n * @param {object} selectors optional css selector overrides\n * @param {number} sectionReturn the content section return\n * @return {Component}\n */\n static init(target, selectors, sectionReturn) {\n return new Component({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n selectors,\n sectionReturn,\n });\n }\n\n /**\n * Initial state ready method.\n */\n stateReady(/*state*/) {\n this._indexContents();\n\n if (this.reactive.supportComponents) {\n // Actions are only available in edit mode.\n if (this.reactive.isEditing) {\n new DispatchActions(this);\n }\n\n // Mark content as state ready.\n this.element.classList.add(this.classes.STATEDREADY);\n }\n\n // Capture completion events.\n this.addEventListener(\n this.element,\n CourseEvents.manualCompletionToggled,\n this._completionHandler\n );\n\n // Capture page scroll to update page item.\n this.addEventListener(\n document.querySelector(this.selectors.PAGE),\n \"scroll\",\n this._scrollHandler\n );\n }\n\n /**\n * Return the component watchers.\n *\n * @returns {Array} of watchers\n */\n getWatchers() {\n // Section return is a global page variable but most formats define it just before start printing\n // the course content. This is the reason why we define this page setting here.\n this.reactive.sectionReturn = this.sectionReturn;\n\n // Check if the course format is compatible with reactive components.\n if (!this.reactive.supportComponents) {\n return [];\n }\n return [\n // State changes that require to reload some course modules.\n {watch: `cm.visible:updated`, handler: this._reloadCm},\n {watch: `cm.stealth:updated`, handler: this._reloadCm},\n // Update section number and title.\n {watch: `section.number:updated`, handler: this._refreshSectionNumber},\n // Sections and cm sorting.\n {watch: `transaction:start`, handler: this._startProcessing},\n {watch: `course.sectionlist:updated`, handler: this._refreshCourseSectionlist},\n {watch: `section.cmlist:updated`, handler: this._refreshSectionCmlist},\n // Reindex sections and cms.\n {watch: `state:updated`, handler: this._indexContents},\n // State changes thaty require to reload course modules.\n {watch: `cm.visible:updated`, handler: this._reloadCm},\n {watch: `cm.sectionid:updated`, handler: this._reloadCm},\n ];\n }\n\n /**\n * Setup the component to start a transaction.\n *\n * Some of the course actions replaces the current DOM element with a new one before updating the\n * course state. This means the component cannot preload any index properly until the transaction starts.\n *\n */\n _startProcessing() {\n // During a section or cm sorting, some elements could be dettached from the DOM and we\n // need to store somewhare in case they are needed later.\n this.dettachedCms = {};\n this.dettachedSections = {};\n }\n\n /**\n * Activity manual completion listener.\n *\n * @param {Event} event the custom ecent\n */\n _completionHandler({detail}) {\n if (detail === undefined) {\n return;\n }\n this.reactive.dispatch('cmCompletion', [detail.cmid], detail.completed);\n }\n\n /**\n * Check the current page scroll and update the active element if necessary.\n */\n _scrollHandler() {\n const pageOffset = document.querySelector(this.selectors.PAGE).scrollTop;\n const items = this.reactive.getExporter().allItemsArray(this.reactive.state);\n // Check what is the active element now.\n let pageItem = null;\n items.every(item => {\n const index = (item.type === 'section') ? this.sections : this.cms;\n if (index[item.id] === undefined) {\n return true;\n }\n\n const element = index[item.id].element;\n // Activities without url can only be page items in edit mode.\n if (item.type === 'cm' && !item.url && !this.reactive.isEditing) {\n return pageOffset >= element.offsetTop;\n }\n pageItem = item;\n return pageOffset >= element.offsetTop;\n });\n if (pageItem) {\n this.reactive.dispatch('setPageItem', pageItem.type, pageItem.id);\n }\n }\n\n /**\n * Update a course section when the section number changes.\n *\n * The courseActions module used for most course section tools still depends on css classes and\n * section numbers (not id). To prevent inconsistencies when a section is moved, we need to refresh\n * the\n *\n * Course formats can override the section title rendering so the frontend depends heavily on backend\n * rendering. Luckily in edit mode we can trigger a title update using the inplace_editable module.\n *\n * @param {Object} param\n * @param {Object} param.element details the update details.\n */\n _refreshSectionNumber({element}) {\n // Find the element.\n const target = this.getElement(this.selectors.SECTION, element.id);\n if (!target) {\n // Job done. Nothing to refresh.\n return;\n }\n // Update section numbers in all data, css and YUI attributes.\n target.id = `section-${element.number}`;\n // YUI uses section number as section id in data-sectionid, in principle if a format use components\n // don't need this sectionid attribute anymore, but we keep the compatibility in case some plugin\n // use it for legacy purposes.\n target.dataset.sectionid = element.number;\n // The data-number is the attribute used by components to store the section number.\n target.dataset.number = element.number;\n\n // Update title and title inplace editable, if any.\n const inplace = inplaceeditable.getInplaceEditable(target.querySelector(this.selectors.SECTION_ITEM));\n if (inplace) {\n // The course content HTML can be modified at any moment, so the function need to do some checkings\n // to make sure the inplace editable still represents the same itemid.\n const currentvalue = inplace.getValue();\n const currentitemid = inplace.getItemId();\n // Unnamed sections must be recalculated.\n if (inplace.getValue() === '') {\n // The value to send can be an empty value if it is a default name.\n if (currentitemid == element.id && (currentvalue != element.rawtitle || element.rawtitle == '')) {\n inplace.setValue(element.rawtitle);\n }\n }\n }\n }\n\n /**\n * Refresh a section cm list.\n *\n * @param {Object} param\n * @param {Object} param.element details the update details.\n */\n _refreshSectionCmlist({element}) {\n const cmlist = element.cmlist ?? [];\n const section = this.getElement(this.selectors.SECTION, element.id);\n const listparent = section?.querySelector(this.selectors.SECTION_CMLIST);\n // A method to create a fake element to be replaced when the item is ready.\n const createCm = this._createCmItem.bind(this);\n if (listparent) {\n this._fixOrder(listparent, cmlist, this.selectors.CM, this.dettachedCms, createCm);\n }\n }\n\n /**\n * Refresh the section list.\n *\n * @param {Object} param\n * @param {Object} param.element details the update details.\n */\n _refreshCourseSectionlist({element}) {\n // If we have a section return means we only show a single section so no need to fix order.\n if (this.reactive.sectionReturn != 0) {\n return;\n }\n const sectionlist = element.sectionlist ?? [];\n const listparent = this.getElement(this.selectors.COURSE_SECTIONLIST);\n // For now section cannot be created at a frontend level.\n const createSection = this._createSectionItem.bind(this);\n if (listparent) {\n this._fixOrder(listparent, sectionlist, this.selectors.SECTION, this.dettachedSections, createSection);\n }\n }\n\n /**\n * Regenerate content indexes.\n *\n * This method is used when a legacy action refresh some content element.\n */\n _indexContents() {\n // Find unindexed sections.\n this._scanIndex(\n this.selectors.SECTION,\n this.sections,\n (item) => {\n return new Section(item);\n }\n );\n\n // Find unindexed cms.\n this._scanIndex(\n this.selectors.CM,\n this.cms,\n (item) => {\n return new CmItem(item);\n }\n );\n }\n\n /**\n * Reindex a content (section or cm) of the course content.\n *\n * This method is used internally by _indexContents.\n *\n * @param {string} selector the DOM selector to scan\n * @param {*} index the index attribute to update\n * @param {*} creationhandler method to create a new indexed element\n */\n _scanIndex(selector, index, creationhandler) {\n const items = this.getElements(`${selector}:not([data-indexed])`);\n items.forEach((item) => {\n if (!item?.dataset?.id) {\n return;\n }\n // Delete previous item component.\n if (index[item.dataset.id] !== undefined) {\n index[item.dataset.id].unregister();\n }\n // Create the new component.\n index[item.dataset.id] = creationhandler({\n ...this,\n element: item,\n });\n // Mark as indexed.\n item.dataset.indexed = true;\n });\n }\n\n /**\n * Reload a course module contents.\n *\n * Most course module HTML is still strongly backend dependant.\n * Some changes require to get a new version of the module.\n *\n * @param {object} param0 the watcher details\n * @param {object} param0.element the state object\n */\n _reloadCm({element}) {\n const cmitem = this.getElement(this.selectors.CM, element.id);\n if (cmitem) {\n const promise = courseActions.refreshModule(cmitem, element.id);\n promise.then(() => {\n this._indexContents();\n return;\n }).catch();\n }\n }\n\n /**\n * Reload a course section contents.\n *\n * Section HTML is still strongly backend dependant.\n * Some changes require to get a new version of the section.\n *\n * @param {details} param0 the watcher details\n * @param {object} param0.element the state object\n */\n _reloadSection({element}) {\n const sectionitem = this.getElement(this.selectors.SECTION, element.id);\n if (sectionitem) {\n const promise = courseActions.refreshSection(sectionitem, element.id);\n promise.then(() => {\n this._indexContents();\n return;\n }).catch();\n }\n }\n\n /**\n * Create a new course module item in a section.\n *\n * Thos method will append a fake item in the container and trigger an ajax request to\n * replace the fake element by the real content.\n *\n * @param {Element} container the container element (section)\n * @param {Number} cmid the course-module ID\n * @returns {Element} the created element\n */\n _createCmItem(container, cmid) {\n const newItem = document.createElement(this.selectors.ACTIVITYTAG);\n newItem.dataset.for = 'cmitem';\n newItem.dataset.id = cmid;\n // The legacy actions.js requires a specific ID and class to refresh the CM.\n newItem.id = `module-${cmid}`;\n newItem.classList.add(this.classes.ACTIVITY);\n container.append(newItem);\n this._reloadCm({\n element: this.reactive.get('cm', cmid),\n });\n return newItem;\n }\n\n /**\n * Create a new section item.\n *\n * This method will append a fake item in the container and trigger an ajax request to\n * replace the fake element by the real content.\n *\n * @param {Element} container the container element (section)\n * @param {Number} sectionid the course-module ID\n * @returns {Element} the created element\n */\n _createSectionItem(container, sectionid) {\n const section = this.reactive.get('section', sectionid);\n const newItem = document.createElement(this.selectors.SECTIONTAG);\n newItem.dataset.for = 'section';\n newItem.dataset.id = sectionid;\n newItem.dataset.number = section.number;\n // The legacy actions.js requires a specific ID and class to refresh the section.\n newItem.id = `section-${sectionid}`;\n newItem.classList.add(this.classes.SECTION);\n container.append(newItem);\n this._reloadSection({\n element: section,\n });\n return newItem;\n }\n\n /**\n * Fix/reorder the section or cms order.\n *\n * @param {Element} container the HTML element to reorder.\n * @param {Array} neworder an array with the ids order\n * @param {string} selector the element selector\n * @param {Object} dettachedelements a list of dettached elements\n * @param {function} createMethod method to create missing elements\n */\n async _fixOrder(container, neworder, selector, dettachedelements, createMethod) {\n if (container === undefined) {\n return;\n }\n\n // Empty lists should not be visible.\n if (!neworder.length) {\n container.classList.add('hidden');\n container.innerHTML = '';\n return;\n }\n\n // Grant the list is visible (in case it was empty).\n container.classList.remove('hidden');\n\n // Move the elements in order at the beginning of the list.\n neworder.forEach((itemid, index) => {\n let item = this.getElement(selector, itemid) ?? dettachedelements[itemid] ?? createMethod(container, itemid);\n if (item === undefined) {\n // Missing elements cannot be sorted.\n return;\n }\n // Get the current elemnt at that position.\n const currentitem = container.children[index];\n if (currentitem === undefined) {\n container.append(item);\n return;\n }\n if (currentitem !== item) {\n container.insertBefore(item, currentitem);\n }\n });\n\n // Dndupload add a fake element we need to keep.\n let dndFakeActivity;\n\n // Remove the remaining elements.\n while (container.children.length > neworder.length) {\n const lastchild = container.lastChild;\n if (lastchild?.classList?.contains('dndupload-preview')) {\n dndFakeActivity = lastchild;\n } else {\n dettachedelements[lastchild?.dataset?.id ?? 0] = lastchild;\n }\n container.removeChild(lastchild);\n }\n // Restore dndupload fake element.\n if (dndFakeActivity) {\n container.append(dndFakeActivity);\n }\n }\n}\n"],"names":["Component","BaseComponent","create","descriptor","name","selectors","SECTION","SECTION_ITEM","SECTION_CMLIST","COURSE_SECTIONLIST","CM","PAGE","ACTIVITYTAG","SECTIONTAG","classes","ACTIVITY","STATEDREADY","dettachedCms","dettachedSections","sections","cms","sectionReturn","target","element","document","getElementById","reactive","stateReady","_indexContents","this","supportComponents","isEditing","DispatchActions","classList","add","addEventListener","CourseEvents","manualCompletionToggled","_completionHandler","querySelector","_scrollHandler","getWatchers","watch","handler","_reloadCm","_refreshSectionNumber","_startProcessing","_refreshCourseSectionlist","_refreshSectionCmlist","detail","undefined","dispatch","cmid","completed","pageOffset","scrollTop","items","getExporter","allItemsArray","state","pageItem","every","item","index","type","id","url","offsetTop","getElement","number","dataset","sectionid","inplace","inplaceeditable","getInplaceEditable","currentvalue","getValue","currentitemid","getItemId","rawtitle","setValue","cmlist","section","listparent","createCm","_createCmItem","bind","_fixOrder","sectionlist","createSection","_createSectionItem","_scanIndex","Section","CmItem","selector","creationhandler","getElements","forEach","_item$dataset","unregister","indexed","cmitem","courseActions","refreshModule","then","catch","_reloadSection","sectionitem","refreshSection","container","newItem","createElement","for","append","get","neworder","dettachedelements","createMethod","length","innerHTML","dndFakeActivity","remove","itemid","currentitem","children","insertBefore","lastchild","lastChild","_lastchild$classList","contains","_lastchild$dataset","removeChild"],"mappings":";;;;;;;;ihCAkCqBA,kBAAkBC,iBAOnCC,OAAOC,2CAEEC,KAAO,0BAEPC,UAAY,CACbC,+BACAC,0CACAC,qCACAC,qDACAC,yBACAC,aAEAC,YAAa,KACbC,WAAY,WAGXC,QAAU,CAGXC,oBACAC,yBACAV,wBAGCW,aAAe,QACfC,kBAAoB,QAEpBC,SAAW,QACXC,IAAM,QAENC,4CAAgBlB,WAAWkB,qEAAiB,cAWzCC,OAAQjB,UAAWgB,sBACpB,IAAIrB,UAAU,CACjBuB,QAASC,SAASC,eAAeH,QACjCI,UAAU,0CACVrB,oBACAgB,8BAORM,kBACSC,iBAEDC,KAAKH,SAASI,oBAEVD,KAAKH,SAASK,eACVC,kBAAgBH,WAInBN,QAAQU,UAAUC,IAAIL,KAAKf,QAAQE,mBAIvCmB,iBACDN,KAAKN,QACLa,aAAaC,wBACbR,KAAKS,yBAIJH,iBACDX,SAASe,cAAcV,KAAKxB,UAAUM,MACtC,SACAkB,KAAKW,gBASbC,0BAGSf,SAASL,cAAgBQ,KAAKR,cAG9BQ,KAAKH,SAASI,kBAGZ,CAEH,CAACY,2BAA6BC,QAASd,KAAKe,WAC5C,CAACF,2BAA6BC,QAASd,KAAKe,WAE5C,CAACF,+BAAiCC,QAASd,KAAKgB,uBAEhD,CAACH,0BAA4BC,QAASd,KAAKiB,kBAC3C,CAACJ,mCAAqCC,QAASd,KAA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B,aAAa/D,KAAM6D,aAJ7Bd,UAAUI,OAAOnD,SAYlB+C,UAAUe,SAASN,OAASH,SAASG,QAAQ,gCAC1CQ,UAAYjB,UAAUkB,0DACxBD,8CAAAA,UAAW7F,2CAAX+F,qBAAsBC,SAAS,qBAC/BT,gBAAkBM,eAElBV,gDAAkBU,4CAAAA,UAAWxD,6CAAX4D,mBAAoBjE,0DAAM,GAAK6D,UAErDjB,UAAUsB,YAAYL,WAGtBN,iBACAX,UAAUI,OAAOO"} \ No newline at end of file +{"version":3,"file":"content.min.js","sources":["../../src/local/content.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Grid format Course index main component.\n *\n * @module format_grid/local/content\n * @class format_grid/local/content\n * @copyright 2023 G J Barnard based upon work done by:\n * @copyright 2020 Ferran Recio \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport BaseComponent from 'core_courseformat/local/content';\nimport {getCurrentCourseEditor} from 'core_courseformat/courseeditor';\nimport inplaceeditable from 'core/inplace_editable';\nimport Section from 'core_courseformat/local/content/section';\nimport CmItem from 'core_courseformat/local/content/section/cmitem';\n// Course actions is needed for actions that are not migrated to components.\nimport courseActions from 'core_course/actions';\nimport DispatchActions from 'core_courseformat/local/content/actions';\nimport * as CourseEvents from 'core_course/events';\n\nexport default class Component extends BaseComponent {\n\n /**\n * Constructor hook.\n *\n * @param {Object} descriptor the component descriptor\n */\n create(descriptor) {\n // Optional component name for debugging.\n this.name = 'grid_course_format';\n // Default query selectors.\n this.selectors = {\n SECTION: `[data-for='section']`,\n SECTION_ITEM: `[data-for='section_title']`,\n SECTION_CMLIST: `[data-for='cmlist']`,\n COURSE_SECTIONLIST: `[data-for='course_sectionlist']`,\n CM: `[data-for='cmitem']`,\n PAGE: `#page`,\n // Formats can override the activity tag but a default one is needed to create new elements.\n ACTIVITYTAG: 'li',\n SECTIONTAG: 'li',\n };\n // Default classes to toggle on refresh.\n this.classes = {\n //COLLAPSED: `collapsed`,\n // Course content classes.\n ACTIVITY: `activity`,\n STATEDREADY: `stateready`,\n SECTION: `section`,\n };\n // Array to save dettached elements during element resorting.\n this.dettachedCms = {};\n this.dettachedSections = {};\n // Index of sections and cms components.\n this.sections = {};\n this.cms = {};\n // The page section return.\n this.sectionReturn = descriptor.sectionReturn ?? 0;\n }\n\n /**\n * Static method to create a component instance form the mustahce template.\n *\n * @param {string} target the DOM main element or its ID\n * @param {object} selectors optional css selector overrides\n * @param {number} sectionReturn the content section return\n * @return {Component}\n */\n static init(target, selectors, sectionReturn) {\n return new Component({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n selectors,\n sectionReturn,\n });\n }\n\n /**\n * Initial state ready method.\n */\n stateReady(/*state*/) {\n this._indexContents();\n\n if (this.reactive.supportComponents) {\n // Actions are only available in edit mode.\n if (this.reactive.isEditing) {\n new DispatchActions(this);\n }\n\n // Mark content as state ready.\n this.element.classList.add(this.classes.STATEDREADY);\n }\n\n // Capture completion events.\n this.addEventListener(\n this.element,\n CourseEvents.manualCompletionToggled,\n this._completionHandler\n );\n\n // Capture page scroll to update page item.\n this.addEventListener(\n document.querySelector(this.selectors.PAGE),\n \"scroll\",\n this._scrollHandler\n );\n }\n\n /**\n * Return the component watchers.\n *\n * @returns {Array} of watchers\n */\n getWatchers() {\n // Section return is a global page variable but most formats define it just before start printing\n // the course content. This is the reason why we define this page setting here.\n this.reactive.sectionReturn = this.sectionReturn;\n\n // Check if the course format is compatible with reactive components.\n if (!this.reactive.supportComponents) {\n return [];\n }\n return [\n // State changes that require to reload some course modules.\n {watch: `cm.visible:updated`, handler: this._reloadCm},\n {watch: `cm.stealth:updated`, handler: this._reloadCm},\n // Update section number and title.\n {watch: `section.number:updated`, handler: this._refreshSectionNumber},\n // Sections and cm sorting.\n {watch: `transaction:start`, handler: this._startProcessing},\n {watch: `course.sectionlist:updated`, handler: this._refreshCourseSectionlist},\n {watch: `section.cmlist:updated`, handler: this._refreshSectionCmlist},\n // Reindex sections and cms.\n {watch: `state:updated`, handler: this._indexContents},\n // State changes thaty require to reload course modules.\n {watch: `cm.visible:updated`, handler: this._reloadCm},\n {watch: `cm.sectionid:updated`, handler: this._reloadCm},\n ];\n }\n\n /**\n * Setup the component to start a transaction.\n *\n * Some of the course actions replaces the current DOM element with a new one before updating the\n * course state. This means the component cannot preload any index properly until the transaction starts.\n *\n */\n _startProcessing() {\n // During a section or cm sorting, some elements could be dettached from the DOM and we\n // need to store somewhare in case they are needed later.\n this.dettachedCms = {};\n this.dettachedSections = {};\n }\n\n /**\n * Activity manual completion listener.\n *\n * @param {Event} event the custom ecent\n */\n _completionHandler({detail}) {\n if (detail === undefined) {\n return;\n }\n this.reactive.dispatch('cmCompletion', [detail.cmid], detail.completed);\n }\n\n /**\n * Check the current page scroll and update the active element if necessary.\n */\n _scrollHandler() {\n const pageOffset = document.querySelector(this.selectors.PAGE).scrollTop;\n const items = this.reactive.getExporter().allItemsArray(this.reactive.state);\n // Check what is the active element now.\n let pageItem = null;\n items.every(item => {\n const index = (item.type === 'section') ? this.sections : this.cms;\n if (index[item.id] === undefined) {\n return true;\n }\n\n const element = index[item.id].element;\n // Activities without url can only be page items in edit mode.\n if (item.type === 'cm' && !item.url && !this.reactive.isEditing) {\n return pageOffset >= element.offsetTop;\n }\n pageItem = item;\n return pageOffset >= element.offsetTop;\n });\n if (pageItem) {\n this.reactive.dispatch('setPageItem', pageItem.type, pageItem.id);\n }\n }\n\n /**\n * Update a course section when the section number changes.\n *\n * The courseActions module used for most course section tools still depends on css classes and\n * section numbers (not id). To prevent inconsistencies when a section is moved, we need to refresh\n * the\n *\n * Course formats can override the section title rendering so the frontend depends heavily on backend\n * rendering. Luckily in edit mode we can trigger a title update using the inplace_editable module.\n *\n * @param {Object} param\n * @param {Object} param.element details the update details.\n */\n _refreshSectionNumber({element}) {\n // Find the element.\n const target = this.getElement(this.selectors.SECTION, element.id);\n if (!target) {\n // Job done. Nothing to refresh.\n return;\n }\n // Update section numbers in all data, css and YUI attributes.\n target.id = `section-${element.number}`;\n // YUI uses section number as section id in data-sectionid, in principle if a format use components\n // don't need this sectionid attribute anymore, but we keep the compatibility in case some plugin\n // use it for legacy purposes.\n target.dataset.sectionid = element.number;\n // The data-number is the attribute used by components to store the section number.\n target.dataset.number = element.number;\n\n // Update title and title inplace editable, if any.\n const inplace = inplaceeditable.getInplaceEditable(target.querySelector(this.selectors.SECTION_ITEM));\n if (inplace) {\n // The course content HTML can be modified at any moment, so the function need to do some checkings\n // to make sure the inplace editable still represents the same itemid.\n const currentvalue = inplace.getValue();\n const currentitemid = inplace.getItemId();\n // Unnamed sections must be recalculated.\n if (inplace.getValue() === '') {\n // The value to send can be an empty value if it is a default name.\n if (currentitemid == element.id && (currentvalue != element.rawtitle || element.rawtitle == '')) {\n inplace.setValue(element.rawtitle);\n }\n }\n }\n }\n\n /**\n * Refresh a section cm list.\n *\n * @param {Object} param\n * @param {Object} param.element details the update details.\n */\n _refreshSectionCmlist({element}) {\n const cmlist = element.cmlist ?? [];\n const section = this.getElement(this.selectors.SECTION, element.id);\n const listparent = section?.querySelector(this.selectors.SECTION_CMLIST);\n // A method to create a fake element to be replaced when the item is ready.\n const createCm = this._createCmItem.bind(this);\n if (listparent) {\n this._fixOrder(listparent, cmlist, this.selectors.CM, this.dettachedCms, createCm);\n }\n }\n\n /**\n * Refresh the section list.\n *\n * @param {Object} param\n * @param {Object} param.element details the update details.\n */\n _refreshCourseSectionlist({element}) {\n // If we have a section return means we only show a single section so no need to fix order.\n if (this.reactive.sectionReturn != 0) {\n return;\n }\n const sectionlist = element.sectionlist ?? [];\n const listparent = this.getElement(this.selectors.COURSE_SECTIONLIST);\n // For now section cannot be created at a frontend level.\n const createSection = this._createSectionItem.bind(this);\n if (listparent) {\n this._fixOrder(listparent, sectionlist, this.selectors.SECTION, this.dettachedSections, createSection);\n }\n }\n\n /**\n * Regenerate content indexes.\n *\n * This method is used when a legacy action refresh some content element.\n */\n _indexContents() {\n // Find unindexed sections.\n this._scanIndex(\n this.selectors.SECTION,\n this.sections,\n (item) => {\n return new Section(item);\n }\n );\n\n // Find unindexed cms.\n this._scanIndex(\n this.selectors.CM,\n this.cms,\n (item) => {\n return new CmItem(item);\n }\n );\n }\n\n /**\n * Reindex a content (section or cm) of the course content.\n *\n * This method is used internally by _indexContents.\n *\n * @param {string} selector the DOM selector to scan\n * @param {*} index the index attribute to update\n * @param {*} creationhandler method to create a new indexed element\n */\n _scanIndex(selector, index, creationhandler) {\n const items = this.getElements(`${selector}:not([data-indexed])`);\n items.forEach((item) => {\n if (!item?.dataset?.id) {\n return;\n }\n // Delete previous item component.\n if (index[item.dataset.id] !== undefined) {\n index[item.dataset.id].unregister();\n }\n // Create the new component.\n index[item.dataset.id] = creationhandler({\n ...this,\n element: item,\n });\n // Mark as indexed.\n item.dataset.indexed = true;\n });\n }\n\n /**\n * Reload a course module contents.\n *\n * Most course module HTML is still strongly backend dependant.\n * Some changes require to get a new version of the module.\n *\n * @param {object} param0 the watcher details\n * @param {object} param0.element the state object\n */\n _reloadCm({element}) {\n const cmitem = this.getElement(this.selectors.CM, element.id);\n if (cmitem) {\n const promise = courseActions.refreshModule(cmitem, element.id);\n promise.then(() => {\n this._indexContents();\n return;\n }).catch();\n }\n }\n\n /**\n * Reload a course section contents.\n *\n * Section HTML is still strongly backend dependant.\n * Some changes require to get a new version of the section.\n *\n * @param {details} param0 the watcher details\n * @param {object} param0.element the state object\n */\n _reloadSection({element}) {\n const sectionitem = this.getElement(this.selectors.SECTION, element.id);\n if (sectionitem) {\n const promise = courseActions.refreshSection(sectionitem, element.id);\n promise.then(() => {\n this._indexContents();\n return;\n }).catch();\n }\n }\n\n /**\n * Create a new course module item in a section.\n *\n * Thos method will append a fake item in the container and trigger an ajax request to\n * replace the fake element by the real content.\n *\n * @param {Element} container the container element (section)\n * @param {Number} cmid the course-module ID\n * @returns {Element} the created element\n */\n _createCmItem(container, cmid) {\n const newItem = document.createElement(this.selectors.ACTIVITYTAG);\n newItem.dataset.for = 'cmitem';\n newItem.dataset.id = cmid;\n // The legacy actions.js requires a specific ID and class to refresh the CM.\n newItem.id = `module-${cmid}`;\n newItem.classList.add(this.classes.ACTIVITY);\n container.append(newItem);\n this._reloadCm({\n element: this.reactive.get('cm', cmid),\n });\n return newItem;\n }\n\n /**\n * Create a new section item.\n *\n * This method will append a fake item in the container and trigger an ajax request to\n * replace the fake element by the real content.\n *\n * @param {Element} container the container element (section)\n * @param {Number} sectionid the course-module ID\n * @returns {Element} the created element\n */\n _createSectionItem(container, sectionid) {\n const section = this.reactive.get('section', sectionid);\n const newItem = document.createElement(this.selectors.SECTIONTAG);\n newItem.dataset.for = 'section';\n newItem.dataset.id = sectionid;\n newItem.dataset.number = section.number;\n // The legacy actions.js requires a specific ID and class to refresh the section.\n newItem.id = `section-${sectionid}`;\n newItem.classList.add(this.classes.SECTION);\n container.append(newItem);\n this._reloadSection({\n element: section,\n });\n return newItem;\n }\n\n /**\n * Fix/reorder the section or cms order.\n *\n * @param {Element} container the HTML element to reorder.\n * @param {Array} neworder an array with the ids order\n * @param {string} selector the element selector\n * @param {Object} dettachedelements a list of dettached elements\n * @param {function} createMethod method to create missing elements\n */\n async _fixOrder(container, neworder, selector, dettachedelements, createMethod) {\n if (container === undefined) {\n return;\n }\n\n // Empty lists should not be visible.\n if (!neworder.length) {\n container.classList.add('hidden');\n container.innerHTML = '';\n return;\n }\n\n // Grant the list is visible (in case it was empty).\n container.classList.remove('hidden');\n\n // Move the elements in order at the beginning of the list.\n neworder.forEach((itemid, index) => {\n let item = this.getElement(selector, itemid) ?? dettachedelements[itemid] ?? createMethod(container, itemid);\n if (item === undefined) {\n // Missing elements cannot be sorted.\n return;\n }\n // Get the current elemnt at that position.\n const currentitem = container.children[index];\n if (currentitem === undefined) {\n container.append(item);\n return;\n }\n if (currentitem !== item) {\n container.insertBefore(item, currentitem);\n }\n });\n\n // Dndupload add a fake element we need to keep.\n let dndFakeActivity;\n\n // Remove the remaining elements.\n while (container.children.length > neworder.length) {\n const lastchild = container.lastChild;\n if (lastchild?.classList?.contains('dndupload-preview')) {\n dndFakeActivity = lastchild;\n } else {\n dettachedelements[lastchild?.dataset?.id ?? 0] = lastchild;\n }\n container.removeChild(lastchild);\n }\n // Restore dndupload fake element.\n if (dndFakeActivity) {\n container.append(dndFakeActivity);\n }\n }\n}\n"],"names":["Component","BaseComponent","create","descriptor","name","selectors","SECTION","SECTION_ITEM","SECTION_CMLIST","COURSE_SECTIONLIST","CM","PAGE","ACTIVITYTAG","SECTIONTAG","classes","ACTIVITY","STATEDREADY","dettachedCms","dettachedSections","sections","cms","sectionReturn","target","element","document","getElementById","reactive","stateReady","_indexContents","this","supportComponents","isEditing","DispatchActions","classList","add","addEventListener","CourseEvents","manualCompletionToggled","_completionHandler","querySelector","_scrollHandler","getWatchers","watch","handler","_reloadCm","_refreshSectionNumber","_startProcessing","_refreshCourseSectionlist","_refreshSectionCmlist","detail","undefined","dispatch","cmid","completed","pageOffset","scrollTop","items","getExporter","allItemsArray","state","pageItem","every","item","index","type","id","url","offsetTop","getElement","number","dataset","sectionid","inplace","inplaceeditable","getInplaceEditable","currentvalue","getValue","currentitemid","getItemId","rawtitle","setValue","cmlist","section","listparent","createCm","_createCmItem","bind","_fixOrder","sectionlist","createSection","_createSectionItem","_scanIndex","Section","CmItem","selector","creationhandler","getElements","forEach","_item$dataset","unregister","indexed","cmitem","courseActions","refreshModule","then","catch","_reloadSection","sectionitem","refreshSection","container","newItem","createElement","for","append","get","neworder","dettachedelements","createMethod","length","innerHTML","dndFakeActivity","remove","itemid","currentitem","children","insertBefore","lastchild","lastChild","_lastchild$classList","contains","_lastchild$dataset","removeChild"],"mappings":";;;;;;;;;ihCAmCqBA,kBAAkBC,iBAOnCC,OAAOC,2CAEEC,KAAO,0BAEPC,UAAY,CACbC,+BACAC,0CACAC,qCACAC,qDACAC,yBACAC,aAEAC,YAAa,KACbC,WAAY,WAGXC,QAAU,CAGXC,oBACAC,yBACAV,wBAGCW,aAAe,QACfC,kBAAoB,QAEpBC,SAAW,QACXC,IAAM,QAENC,4CAAgBlB,WAAWkB,qEAAiB,cAWzCC,OAAQjB,UAAWgB,sBACpB,IAAIrB,UAAU,CACjBuB,QAASC,SAASC,eAAeH,QACjCI,UAAU,0CACVrB,UAAAA,UACAgB,cAAAA,gBAORM,kBACSC,iBAEDC,KAAKH,SAASI,oBAEVD,KAAKH,SAASK,eACVC,kBAAgBH,WAInBN,QAAQU,UAAUC,IAAIL,KAAKf,QAAQE,mBAIvCmB,iBACDN,KAAKN,QACLa,aAAaC,wBACbR,KAAKS,yBAIJH,iBACDX,SAASe,cAAcV,KAAKxB,UAAUM,MACtC,SACAkB,KAAKW,gBASbC,0BAGSf,SAASL,cAAgBQ,KAAKR,cAG9BQ,KAAKH,SAASI,kBAGZ,CAEH,CAACY,2BAA6BC,QAASd,KAAKe,WAC5C,CAACF,2BAA6BC,QAASd,KAAKe,WAE5C,CAACF,+BAAiCC,QAASd,KAAKgB,uBAEhD,CAACH,0BAA4BC,QAASd,KAAKiB,kBAC3C,CAACJ,mCAAqCC,QAASd,KAAKkB,2BACpD,CAACL,+BAAiCC,QAASd,KAAKmB,uBAEhD,CAACN,sBAAwBC,QAASd,KAAKD,gBAEvC,CAACc,2BAA6BC,QAASd,KAAKe,WAC5C,CAACF,6BAA+BC,QAASd,KAAKe,YAhBvC,GA2BfE,wBAGS7B,aAAe,QACfC,kBAAoB,GAQ7BoB,6BAAmBW,OAACA,kBACDC,IAAXD,aAGCvB,SAASyB,SAAS,eAAgB,CAACF,OAAOG,MAAOH,OAAOI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AGtBN,iBACAX,UAAUI,OAAOO"} \ No newline at end of file diff --git a/amd/build/popup.min.js b/amd/build/popup.min.js index 6be734c7..ff088ae2 100644 --- a/amd/build/popup.min.js +++ b/amd/build/popup.min.js @@ -5,6 +5,6 @@ define("format_grid/popup",["exports","core_course/events","jquery"],(function(_ * @module core_course/view * @copyright 2021 Jun Pataleta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */(CourseEvents),_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj};let registered=!1,mctFired=!1;_exports.init=showcompletion=>{registered||(document.addEventListener(CourseEvents.manualCompletionToggled,(()=>{mctFired=!0})),registered=!0,(0,_jquery.default)("#gridPopup").on("show.bs.modal",(function(event){var section=(0,_jquery.default)(event.relatedTarget).data("section"),gml=(0,_jquery.default)("#gridPopupLabel"),triggersectionname=(0,_jquery.default)("#gridpopupsection-"+section).data("sectiontitle");gml.text(triggersectionname),(0,_jquery.default)(this).find("#gridpopupsection-"+section).addClass("active"),(0,_jquery.default)("#gridPopupCarousel").on("slid.bs.carousel",(function(){var sno=(0,_jquery.default)(".gridcarousel-item.active").data("sectiontitle");gml.text(sno)}))})),(0,_jquery.default)("#gridPopup").on("hidden.bs.modal",(function(){(0,_jquery.default)(".gridcarousel-item").removeClass("active"),showcompletion&&mctFired&&(mctFired=!1,window.location.reload())})))}})); + */(CourseEvents),_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj};let registered=!1,mctFired=!1;_exports.init=showcompletion=>{if(!registered){document.addEventListener(CourseEvents.manualCompletionToggled,(()=>{mctFired=!0})),registered=!0;var currentsection=null;(0,_jquery.default)("#gridPopup").on("show.bs.modal",(function(event){var section=currentsection;null===section&&(section=(0,_jquery.default)(event.relatedTarget).data("section"));var gml=(0,_jquery.default)("#gridPopupLabel"),triggersectionname=(0,_jquery.default)("#gridpopupsection-"+section).data("sectiontitle");gml.text(triggersectionname),(0,_jquery.default)(this).find("#gridpopupsection-"+section).addClass("active"),(0,_jquery.default)("#gridPopupCarousel").on("slid.bs.carousel",(function(){var sno=(0,_jquery.default)(".gridcarousel-item.active").data("sectiontitle");gml.text(sno)}))})),(0,_jquery.default)("#gridPopup").on("hidden.bs.modal",(function(){null!==currentsection&&(currentsection=null),(0,_jquery.default)(".gridcarousel-item").removeClass("active"),showcompletion&&mctFired&&(mctFired=!1,window.location.reload())})),(0,_jquery.default)(".grid-section .grid-modal").keypress((function(event){if(13==event.which){event.preventDefault();var trigger=(0,_jquery.default)(event.currentTarget);currentsection=trigger.data("section"),(0,_jquery.default)("#gridPopup").modal("show")}}))}}})); //# sourceMappingURL=popup.min.js.map \ No newline at end of file diff --git a/amd/build/popup.min.js.map b/amd/build/popup.min.js.map index 721497e7..0f589f53 100644 --- a/amd/build/popup.min.js.map +++ b/amd/build/popup.min.js.map @@ -1 +1 @@ -{"version":3,"file":"popup.min.js","sources":["../src/popup.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * JS module for the course homepage.\n *\n * @module core_course/view\n * @copyright 2021 Jun Pataleta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as CourseEvents from 'core_course/events';\nimport jQuery from 'jquery';\n\n/**\n * Whether the event listener has already been registered for this module.\n *\n * @type {boolean}\n */\nlet registered = false;\n\n/**\n * If the manualCompletionToggled event has fired.\n *\n * @type {boolean}\n */\nlet mctFired = false;\n\n/**\n * Function to intialise and register event listeners for this module.\n *\n * @param {boolean} showcompletion Show completion is on.\n */\nexport const init = (showcompletion) => {\n if (registered) {\n return;\n }\n // Listen for toggled manual completion states of activities.\n document.addEventListener(CourseEvents.manualCompletionToggled, () => {\n mctFired = true;\n });\n registered = true;\n\n jQuery('#gridPopup').on('show.bs.modal', function(event) {\n var trigger = jQuery(event.relatedTarget);\n var section = trigger.data('section');\n\n var gml = jQuery('#gridPopupLabel');\n var triggersectionname = jQuery('#gridpopupsection-' + section).data('sectiontitle');\n gml.text(triggersectionname);\n\n var modal = jQuery(this);\n modal.find('#gridpopupsection-' + section).addClass('active');\n\n jQuery('#gridPopupCarousel').on('slid.bs.carousel', function() {\n var sno = jQuery('.gridcarousel-item.active').data('sectiontitle');\n gml.text(sno);\n });\n });\n jQuery('#gridPopup').on('hidden.bs.modal', function() {\n jQuery('.gridcarousel-item').removeClass('active');\n if (showcompletion && mctFired) {\n mctFired = false;\n window.location.reload();\n }\n });\n};\n"],"names":["registered","mctFired","showcompletion","document","addEventListener","CourseEvents","manualCompletionToggled","on","event","section","relatedTarget","data","gml","triggersectionname","text","this","find","addClass","sno","removeClass","window","location","reload"],"mappings":";;;;;;;gFA+BIA,YAAa,EAObC,UAAW,gBAOMC,iBACbF,aAIJG,SAASC,iBAAiBC,aAAaC,yBAAyB,KAC5DL,UAAW,CAAX,IAEJD,YAAa,sBAEN,cAAcO,GAAG,iBAAiB,SAASC,WAE1CC,SADU,mBAAOD,MAAME,eACLC,KAAK,WAEvBC,KAAM,mBAAO,mBACbC,oBAAqB,mBAAO,qBAAuBJ,SAASE,KAAK,gBACrEC,IAAIE,KAAKD,qBAEG,mBAAOE,MACbC,KAAK,qBAAuBP,SAASQ,SAAS,8BAE7C,sBAAsBV,GAAG,oBAAoB,eAC5CW,KAAM,mBAAO,6BAA6BP,KAAK,gBACnDC,IAAIE,KAAKI,+BAGV,cAAcX,GAAG,mBAAmB,+BAChC,sBAAsBY,YAAY,UACrCjB,gBAAkBD,WAClBA,UAAW,EACXmB,OAAOC,SAASC"} \ No newline at end of file +{"version":3,"file":"popup.min.js","sources":["../src/popup.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * JS module for the course homepage.\n *\n * @module core_course/view\n * @copyright 2021 Jun Pataleta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as CourseEvents from 'core_course/events';\nimport jQuery from 'jquery';\n\n/**\n * Whether the event listener has already been registered for this module.\n *\n * @type {boolean}\n */\nlet registered = false;\n\n/**\n * If the manualCompletionToggled event has fired.\n *\n * @type {boolean}\n */\nlet mctFired = false;\n\n/**\n * Function to intialise and register event listeners for this module.\n *\n * @param {boolean} showcompletion Show completion is on.\n */\nexport const init = (showcompletion) => {\n if (registered) {\n return;\n }\n // Listen for toggled manual completion states of activities.\n document.addEventListener(CourseEvents.manualCompletionToggled, () => {\n mctFired = true;\n });\n registered = true;\n\n // To pass the current section when using keyboard control.\n var currentsection = null;\n\n jQuery('#gridPopup').on('show.bs.modal', function(event) {\n var section = currentsection;\n if (section === null) {\n var trigger = jQuery(event.relatedTarget);\n section = trigger.data('section');\n }\n\n var gml = jQuery('#gridPopupLabel');\n var triggersectionname = jQuery('#gridpopupsection-' + section).data('sectiontitle');\n gml.text(triggersectionname);\n\n var modal = jQuery(this);\n modal.find('#gridpopupsection-' + section).addClass('active');\n\n jQuery('#gridPopupCarousel').on('slid.bs.carousel', function() {\n var sno = jQuery('.gridcarousel-item.active').data('sectiontitle');\n gml.text(sno);\n });\n });\n\n jQuery('#gridPopup').on('hidden.bs.modal', function() {\n if (currentsection !== null) {\n currentsection = null;\n }\n jQuery('.gridcarousel-item').removeClass('active');\n if (showcompletion && mctFired) {\n mctFired = false;\n window.location.reload();\n }\n });\n\n jQuery(\".grid-section .grid-modal\").keypress(function (event) {\n if (event.which == 13) {\n event.preventDefault();\n var trigger = jQuery(event.currentTarget);\n currentsection = trigger.data('section');\n jQuery('#gridPopup').modal('show');\n }\n });\n};\n"],"names":["registered","mctFired","showcompletion","document","addEventListener","CourseEvents","manualCompletionToggled","currentsection","on","event","section","relatedTarget","data","gml","triggersectionname","text","this","find","addClass","sno","removeClass","window","location","reload","keypress","which","preventDefault","trigger","currentTarget","modal"],"mappings":";;;;;;;gFA+BIA,YAAa,EAObC,UAAW,gBAOMC,qBACbF,YAIJG,SAASC,iBAAiBC,aAAaC,yBAAyB,KAC5DL,UAAW,KAEfD,YAAa,MAGTO,eAAiB,yBAEd,cAAcC,GAAG,iBAAiB,SAASC,WAC1CC,QAAUH,eACE,OAAZG,UAEAA,SADc,mBAAOD,MAAME,eACTC,KAAK,gBAGvBC,KAAM,mBAAO,mBACbC,oBAAqB,mBAAO,qBAAuBJ,SAASE,KAAK,gBACrEC,IAAIE,KAAKD,qBAEG,mBAAOE,MACbC,KAAK,qBAAuBP,SAASQ,SAAS,8BAE7C,sBAAsBV,GAAG,oBAAoB,eAC5CW,KAAM,mBAAO,6BAA6BP,KAAK,gBACnDC,IAAIE,KAAKI,+BAIV,cAAcX,GAAG,mBAAmB,WAChB,OAAnBD,iBACAA,eAAiB,0BAEd,sBAAsBa,YAAY,UACrClB,gBAAkBD,WAClBA,UAAW,EACXoB,OAAOC,SAASC,iCAIjB,6BAA6BC,UAAS,SAAUf,UAChC,IAAfA,MAAMgB,MAAa,CACnBhB,MAAMiB,qBACFC,SAAU,mBAAOlB,MAAMmB,eAC3BrB,eAAiBoB,QAAQf,KAAK,+BACvB,cAAciB,MAAM"} \ No newline at end of file diff --git a/amd/src/popup.js b/amd/src/popup.js index b9eedf94..3c38a8b3 100644 --- a/amd/src/popup.js +++ b/amd/src/popup.js @@ -53,9 +53,15 @@ export const init = (showcompletion) => { }); registered = true; + // To pass the current section when using keyboard control. + var currentsection = null; + jQuery('#gridPopup').on('show.bs.modal', function(event) { - var trigger = jQuery(event.relatedTarget); - var section = trigger.data('section'); + var section = currentsection; + if (section === null) { + var trigger = jQuery(event.relatedTarget); + section = trigger.data('section'); + } var gml = jQuery('#gridPopupLabel'); var triggersectionname = jQuery('#gridpopupsection-' + section).data('sectiontitle'); @@ -69,11 +75,24 @@ export const init = (showcompletion) => { gml.text(sno); }); }); + jQuery('#gridPopup').on('hidden.bs.modal', function() { + if (currentsection !== null) { + currentsection = null; + } jQuery('.gridcarousel-item').removeClass('active'); if (showcompletion && mctFired) { mctFired = false; window.location.reload(); } }); + + jQuery(".grid-section .grid-modal").keypress(function (event) { + if (event.which == 13) { + event.preventDefault(); + var trigger = jQuery(event.currentTarget); + currentsection = trigger.data('section'); + jQuery('#gridPopup').modal('show'); + } + }); };