From b586ec8760565d50caaa70c5b3967156cfb56648 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Thu, 28 Sep 2023 19:50:02 +0100 Subject: [PATCH] Work in progress. --- amd/build/thegrid.min.js | 11 +++-- amd/build/thegrid.min.js.map | 2 +- amd/src/thegrid.js | 90 +++++++++++++++++++++++++++++++++--- templates/grid.mustache | 8 ++-- 4 files changed, 95 insertions(+), 16 deletions(-) diff --git a/amd/build/thegrid.min.js b/amd/build/thegrid.min.js index 4443258a..34f8b4fd 100644 --- a/amd/build/thegrid.min.js +++ b/amd/build/thegrid.min.js @@ -1,10 +1,11 @@ -define("format_grid/thegrid",["exports","jquery","core/log"],(function(_exports,_jquery,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} +define("format_grid/thegrid",["exports","core_course/events","jquery","core/log"],(function(_exports,CourseEvents,_jquery,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}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)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,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} /** - * JS module for the course homepage. + * JS module for the grid. * - * @module core_course/view - * @copyright 2021 Jun Pataleta + * @module format_grid/thegrid + * @copyright © 2023-onwards G J Barnard. + * @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log);let registered=!1;_exports.init=sectionnumbers=>{if(_log.default.debug("Grid thegrid JS init"),registered)_log.default.debug("Grid thegrid JS init already registered");else{_log.default.debug("Grid thegrid sectionnumbers "+sectionnumbers),registered=!0;var currentsection=-1,endsection=sectionnumbers.length-1;(0,_jquery.default)(document).on("keydown",(function(event){37==event.which?(event.preventDefault(),-1==currentsection||0==currentsection?(0==currentsection&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=endsection,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")):((0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection-=1,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")),_log.default.debug("Left: "+sectionnumbers[currentsection])):39==event.which?(event.preventDefault(),-1==currentsection||currentsection==endsection?(currentsection==endsection&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=0,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")):((0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection+=1,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")),_log.default.debug("Right: "+sectionnumbers[currentsection])):13!=event.which&&27!=event.which||(event.preventDefault(),(0,_jquery.default)("#gridPopup").modal("show"))}))}}})); + */(CourseEvents),_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log);let registered=!1,mctFired=!1;_exports.init=(sectionnumbers,showcompletion)=>{if(_log.default.debug("Grid thegrid JS init"),registered)_log.default.debug("Grid thegrid JS init already registered");else{_log.default.debug("Grid thegrid sectionnumbers "+sectionnumbers),document.addEventListener(CourseEvents.manualCompletionToggled,(()=>{mctFired=!0})),registered=!0;var currentsection=-1,endsection=sectionnumbers.length-1,currentmodalsection=null,modalshown=!1;(0,_jquery.default)("#gridPopup").on("show.bs.modal",(function(event){var section=currentmodalsection;null===section&&(section=(0,_jquery.default)(event.relatedTarget).data("section"));currentsection=section-1;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!==currentmodalsection&&(currentmodalsection=null),(0,_jquery.default)(".gridcarousel-item").removeClass("active"),showcompletion&&mctFired&&(mctFired=!1,window.location.reload()),modalshown=!1})),(0,_jquery.default)(".grid-section .grid-modal").on("keydown",(function(event){if(13==event.which||27==event.which){event.preventDefault();var trigger=(0,_jquery.default)(event.currentTarget);currentmodalsection=trigger.data("section"),modalshown=!0,(0,_jquery.default)("#gridPopup").modal("show")}})),(0,_jquery.default)("#gridPopup").on("keydown",(function(event){37==event.which?(event.preventDefault(),(0,_jquery.default)("#gridPopupCarouselLeft").trigger("click")):39==event.which&&(event.preventDefault(),(0,_jquery.default)("#gridPopupCarouselRight").trigger("click"))})),(0,_jquery.default)(document).on("keydown",(function(event){37==event.which?(event.preventDefault(),-1==currentsection||0==currentsection?(0==currentsection&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=endsection,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")):((0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection-=1,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")),_log.default.debug("Left: "+sectionnumbers[currentsection])):39==event.which?(event.preventDefault(),-1==currentsection||currentsection==endsection?(currentsection==endsection&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=0,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")):((0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection+=1,(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")),_log.default.debug("Right: "+sectionnumbers[currentsection])):13!=event.which&&27!=event.which||(event.preventDefault(),-1===currentsection||modalshown||(currentmodalsection=sectionnumbers[currentsection]),modalshown=!0,(0,_jquery.default)("#gridPopup").modal("show"))}))}}})); //# sourceMappingURL=thegrid.min.js.map \ No newline at end of file diff --git a/amd/build/thegrid.min.js.map b/amd/build/thegrid.min.js.map index f0bc7d10..dac56068 100644 --- a/amd/build/thegrid.min.js.map +++ b/amd/build/thegrid.min.js.map @@ -1 +1 @@ -{"version":3,"file":"thegrid.min.js","sources":["../src/thegrid.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 jQuery from 'jquery';\nimport log from 'core/log';\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 * Function to intialise and register event listeners for this module.\n *\n * @param {array} sectionnumbers Show completion is on.\n */\nexport const init = (sectionnumbers) => {\n log.debug('Grid thegrid JS init');\n if (registered) {\n log.debug('Grid thegrid JS init already registered');\n return;\n } else {\n log.debug('Grid thegrid sectionnumbers ' + sectionnumbers);\n }\n registered = true;\n\n var currentsection = -1;\n var endsection = sectionnumbers.length - 1;\n\n jQuery(document).on('keydown', function(event) {\n if (event.which == 37) {\n // Left.\n event.preventDefault();\n if ((currentsection == -1) || (currentsection == 0)) {\n if (currentsection == 0) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = endsection;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n } else {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n currentsection = currentsection - 1;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n log.debug(\"Left: \" + sectionnumbers[currentsection]);\n } else if (event.which == 39) {\n // Right.\n event.preventDefault();\n if ((currentsection == -1) || (currentsection == endsection)) {\n if (currentsection == endsection) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = 0;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n } else {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n currentsection = currentsection + 1;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n log.debug(\"Right: \" + sectionnumbers[currentsection]);\n } else if ((event.which == 13) || (event.which == 27)) {\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","sectionnumbers","debug","currentsection","endsection","length","document","on","event","which","preventDefault","removeClass","addClass","modal"],"mappings":";;;;;;;gKA+BIA,YAAa,gBAOIC,iCACbC,MAAM,wBACNF,wBACIE,MAAM,6DAGNA,MAAM,+BAAiCD,gBAE/CD,YAAa,MAETG,gBAAkB,EAClBC,WAAaH,eAAeI,OAAS,sBAElCC,UAAUC,GAAG,WAAW,SAASC,OACjB,IAAfA,MAAMC,OAEND,MAAME,kBACkB,GAAnBP,gBAA4C,GAAlBA,gBACL,GAAlBA,oCACO,YAAcF,eAAeE,iBAAiBQ,YAAY,wBAErER,eAAiBC,+BACV,YAAcH,eAAeE,iBAAiBS,SAAS,8CAEvD,YAAcX,eAAeE,iBAAiBQ,YAAY,wBACjER,gBAAkC,sBAC3B,YAAcF,eAAeE,iBAAiBS,SAAS,sCAE9DV,MAAM,SAAWD,eAAeE,kBACd,IAAfK,MAAMC,OAEbD,MAAME,kBACkB,GAAnBP,gBAA0BA,gBAAkBC,YACzCD,gBAAkBC,gCACX,YAAcH,eAAeE,iBAAiBQ,YAAY,wBAErER,eAAiB,sBACV,YAAcF,eAAeE,iBAAiBS,SAAS,8CAEvD,YAAcX,eAAeE,iBAAiBQ,YAAY,wBACjER,gBAAkC,sBAC3B,YAAcF,eAAeE,iBAAiBS,SAAS,sCAE9DV,MAAM,UAAYD,eAAeE,kBACd,IAAfK,MAAMC,OAAgC,IAAfD,MAAMC,QACrCD,MAAME,qCAGC,cAAcG,MAAM"} \ No newline at end of file +{"version":3,"file":"thegrid.min.js","sources":["../src/thegrid.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 grid.\n *\n * @module format_grid/thegrid\n * @copyright © 2023-onwards G J Barnard.\n * @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}\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';\nimport log from 'core/log';\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 {array} sectionnumbers Show completion is on.\n * @param {boolean} showcompletion Show completion is on.\n */\nexport const init = (sectionnumbers, showcompletion) => {\n log.debug('Grid thegrid JS init');\n if (registered) {\n log.debug('Grid thegrid JS init already registered');\n return;\n } else {\n log.debug('Grid thegrid sectionnumbers ' + sectionnumbers);\n }\n // Listen for toggled manual completion states of activities.\n document.addEventListener(CourseEvents.manualCompletionToggled, () => {\n mctFired = true;\n });\n registered = true;\n\n // Grid current section.\n var currentsection = -1;\n var endsection = sectionnumbers.length - 1;\n\n // Modal.\n var currentmodalsection = null;\n var modalshown = false;\n\n jQuery('#gridPopup').on('show.bs.modal', function(event) {\n var section = currentmodalsection;\n if (section === null) {\n var trigger = jQuery(event.relatedTarget);\n section = trigger.data('section');\n }\n currentsection = section - 1;\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 (currentmodalsection !== null) {\n currentmodalsection = null;\n }\n jQuery('.gridcarousel-item').removeClass('active');\n if (showcompletion && mctFired) {\n mctFired = false;\n window.location.reload();\n }\n modalshown = false;\n });\n\n jQuery(\".grid-section .grid-modal\").on('keydown', function (event) {\n if ((event.which == 13) || (event.which == 27)) {\n event.preventDefault();\n var trigger = jQuery(event.currentTarget);\n currentmodalsection = trigger.data('section');\n modalshown = true;\n jQuery('#gridPopup').modal('show');\n }\n });\n\n jQuery(\"#gridPopup\").on('keydown', function(event) {\n if (event.which == 37) {\n // Left.\n event.preventDefault();\n jQuery('#gridPopupCarouselLeft').trigger('click');\n }\n else if (event.which == 39) {\n // Right.\n event.preventDefault();\n jQuery('#gridPopupCarouselRight').trigger('click');\n }\n });\n\n jQuery(document).on('keydown', function (event) {\n if (event.which == 37) {\n // Left.\n event.preventDefault();\n if ((currentsection == -1) || (currentsection == 0)) {\n if (currentsection == 0) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = endsection;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n } else {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n currentsection = currentsection - 1;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n log.debug(\"Left: \" + sectionnumbers[currentsection]);\n } else if (event.which == 39) {\n // Right.\n event.preventDefault();\n if ((currentsection == -1) || (currentsection == endsection)) {\n if (currentsection == endsection) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = 0;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n } else {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n currentsection = currentsection + 1;\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n log.debug(\"Right: \" + sectionnumbers[currentsection]);\n } else if ((event.which == 13) || (event.which == 27)) {\n event.preventDefault();\n //var trigger = jQuery(event.currentTarget);\n if ((currentsection !== -1) && (!modalshown)) {\n currentmodalsection = sectionnumbers[currentsection];\n }\n modalshown = true;\n jQuery('#gridPopup').modal('show');\n }\n });\n};\n"],"names":["registered","mctFired","sectionnumbers","showcompletion","debug","document","addEventListener","CourseEvents","manualCompletionToggled","currentsection","endsection","length","currentmodalsection","modalshown","on","event","section","relatedTarget","data","gml","triggersectionname","text","this","find","addClass","sno","removeClass","window","location","reload","which","preventDefault","trigger","currentTarget","modal"],"mappings":";;;;;;;;kGAiCIA,YAAa,EAObC,UAAW,gBAQK,CAACC,eAAgBC,kCAC7BC,MAAM,wBACNJ,wBACII,MAAM,6DAGNA,MAAM,+BAAiCF,gBAG/CG,SAASC,iBAAiBC,aAAaC,yBAAyB,KAC5DP,UAAW,KAEfD,YAAa,MAGTS,gBAAkB,EAClBC,WAAaR,eAAeS,OAAS,EAGrCC,oBAAsB,KACtBC,YAAa,sBAEV,cAAcC,GAAG,iBAAiB,SAASC,WAC1CC,QAAUJ,oBACE,OAAZI,UAEAA,SADc,mBAAOD,MAAME,eACTC,KAAK,YAE3BT,eAAiBO,QAAU,MAEvBG,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,WACX,OAAxBF,sBACAA,oBAAsB,0BAEnB,sBAAsBc,YAAY,UACrCvB,gBAAkBF,WAClBA,UAAW,EACX0B,OAAOC,SAASC,UAEpBhB,YAAa,yBAGV,6BAA6BC,GAAG,WAAW,SAAUC,UACpC,IAAfA,MAAMe,OAAgC,IAAff,MAAMe,MAAc,CAC5Cf,MAAMgB,qBACFC,SAAU,mBAAOjB,MAAMkB,eAC3BrB,oBAAsBoB,QAAQd,KAAK,WACnCL,YAAa,sBACN,cAAcqB,MAAM,gCAI5B,cAAcpB,GAAG,WAAW,SAASC,OACrB,IAAfA,MAAMe,OAENf,MAAMgB,qCACC,0BAA0BC,QAAQ,UAErB,IAAfjB,MAAMe,QAEXf,MAAMgB,qCACC,2BAA2BC,QAAQ,iCAI3C3B,UAAUS,GAAG,WAAW,SAAUC,OAClB,IAAfA,MAAMe,OAENf,MAAMgB,kBACkB,GAAnBtB,gBAA4C,GAAlBA,gBACL,GAAlBA,oCACO,YAAcP,eAAeO,iBAAiBiB,YAAY,wBAErEjB,eAAiBC,+BACV,YAAcR,eAAeO,iBAAiBe,SAAS,8CAEvD,YAActB,eAAeO,iBAAiBiB,YAAY,wBACjEjB,gBAAkC,sBAC3B,YAAcP,eAAeO,iBAAiBe,SAAS,sCAE9DpB,MAAM,SAAWF,eAAeO,kBACd,IAAfM,MAAMe,OAEbf,MAAMgB,kBACkB,GAAnBtB,gBAA0BA,gBAAkBC,YACzCD,gBAAkBC,gCACX,YAAcR,eAAeO,iBAAiBiB,YAAY,wBAErEjB,eAAiB,sBACV,YAAcP,eAAeO,iBAAiBe,SAAS,8CAEvD,YAActB,eAAeO,iBAAiBiB,YAAY,wBACjEjB,gBAAkC,sBAC3B,YAAcP,eAAeO,iBAAiBe,SAAS,sCAE9DpB,MAAM,UAAYF,eAAeO,kBACd,IAAfM,MAAMe,OAAgC,IAAff,MAAMe,QACrCf,MAAMgB,kBAEmB,IAApBtB,gBAA4BI,aAC7BD,oBAAsBV,eAAeO,iBAEzCI,YAAa,sBACN,cAAcqB,MAAM"} \ No newline at end of file diff --git a/amd/src/thegrid.js b/amd/src/thegrid.js index 07f059e2..6042e90d 100644 --- a/amd/src/thegrid.js +++ b/amd/src/thegrid.js @@ -14,13 +14,15 @@ // along with Moodle. If not, see . /** - * JS module for the course homepage. + * JS module for the grid. * - * @module core_course/view - * @copyright 2021 Jun Pataleta + * @module format_grid/thegrid + * @copyright © 2023-onwards G J Barnard. + * @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +import * as CourseEvents from 'core_course/events'; import jQuery from 'jquery'; import log from 'core/log'; @@ -31,12 +33,20 @@ import log from 'core/log'; */ let registered = false; +/** + * If the manualCompletionToggled event has fired. + * + * @type {boolean} + */ +let mctFired = false; + /** * Function to intialise and register event listeners for this module. * * @param {array} sectionnumbers Show completion is on. + * @param {boolean} showcompletion Show completion is on. */ -export const init = (sectionnumbers) => { +export const init = (sectionnumbers, showcompletion) => { log.debug('Grid thegrid JS init'); if (registered) { log.debug('Grid thegrid JS init already registered'); @@ -44,12 +54,77 @@ export const init = (sectionnumbers) => { } else { log.debug('Grid thegrid sectionnumbers ' + sectionnumbers); } + // Listen for toggled manual completion states of activities. + document.addEventListener(CourseEvents.manualCompletionToggled, () => { + mctFired = true; + }); registered = true; + // Grid current section. var currentsection = -1; var endsection = sectionnumbers.length - 1; - jQuery(document).on('keydown', function(event) { + // Modal. + var currentmodalsection = null; + var modalshown = false; + + jQuery('#gridPopup').on('show.bs.modal', function(event) { + var section = currentmodalsection; + if (section === null) { + var trigger = jQuery(event.relatedTarget); + section = trigger.data('section'); + } + currentsection = section - 1; + + var gml = jQuery('#gridPopupLabel'); + var triggersectionname = jQuery('#gridpopupsection-' + section).data('sectiontitle'); + gml.text(triggersectionname); + + var modal = jQuery(this); + modal.find('#gridpopupsection-' + section).addClass('active'); + + jQuery('#gridPopupCarousel').on('slid.bs.carousel', function() { + var sno = jQuery('.gridcarousel-item.active').data('sectiontitle'); + gml.text(sno); + }); + }); + + jQuery('#gridPopup').on('hidden.bs.modal', function() { + if (currentmodalsection !== null) { + currentmodalsection = null; + } + jQuery('.gridcarousel-item').removeClass('active'); + if (showcompletion && mctFired) { + mctFired = false; + window.location.reload(); + } + modalshown = false; + }); + + jQuery(".grid-section .grid-modal").on('keydown', function (event) { + if ((event.which == 13) || (event.which == 27)) { + event.preventDefault(); + var trigger = jQuery(event.currentTarget); + currentmodalsection = trigger.data('section'); + modalshown = true; + jQuery('#gridPopup').modal('show'); + } + }); + + jQuery("#gridPopup").on('keydown', function(event) { + if (event.which == 37) { + // Left. + event.preventDefault(); + jQuery('#gridPopupCarouselLeft').trigger('click'); + } + else if (event.which == 39) { + // Right. + event.preventDefault(); + jQuery('#gridPopupCarouselRight').trigger('click'); + } + }); + + jQuery(document).on('keydown', function (event) { if (event.which == 37) { // Left. event.preventDefault(); @@ -83,7 +158,10 @@ export const init = (sectionnumbers) => { } else if ((event.which == 13) || (event.which == 27)) { event.preventDefault(); //var trigger = jQuery(event.currentTarget); - //currentsection = trigger.data('section'); + if ((currentsection !== -1) && (!modalshown)) { + currentmodalsection = sectionnumbers[currentsection]; + } + modalshown = true; jQuery('#gridPopup').modal('show'); } }); diff --git a/templates/grid.mustache b/templates/grid.mustache index 7bf986b2..0bb749ce 100644 --- a/templates/grid.mustache +++ b/templates/grid.mustache @@ -175,14 +175,14 @@ {{#js}} -require(['format_grid/popup'], function(popuphandler) { - popuphandler.init({{#showcompletion}}true{{/showcompletion}}{{^showcompletion}}false{{/showcompletion}}); -}); +//require(['format_grid/popup'], function(popuphandler) { +// popuphandler.init({{#showcompletion}}true{{/showcompletion}}{{^showcompletion}}false{{/showcompletion}}); +//}); {{/js}} {{/popup}} {{#js}} require(['format_grid/thegrid'], function(gridhandler) { var sectionnumbers = [{{gridsectionnumbers}}]; - gridhandler.init(sectionnumbers); + gridhandler.init(sectionnumbers, {{#popup}}{{#showcompletion}}true{{/showcompletion}}{{^showcompletion}}false{{/showcompletion}}{{/popup}}{{^popup}}false{{/popup}}); }); {{/js}}