From 66ed5449dfbea1dfdfaf66245ff24b38c43c32ad Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Thu, 28 Sep 2023 19:14:01 +0100 Subject: [PATCH] Work in progress. --- amd/build/popup.min.js | 2 +- amd/build/popup.min.js.map | 2 +- amd/build/thegrid.min.js | 10 +++ amd/build/thegrid.min.js.map | 1 + amd/src/popup.js | 13 ++-- amd/src/thegrid.js | 90 +++++++++++++++++++++++++ classes/output/courseformat/content.php | 5 ++ styles.css | 4 ++ templates/grid.mustache | 6 ++ 9 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 amd/build/thegrid.min.js create mode 100644 amd/build/thegrid.min.js.map create mode 100644 amd/src/thegrid.js diff --git a/amd/build/popup.min.js b/amd/build/popup.min.js index d1dc1f93..6aabce3a 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","core/log"], * @module core_course/view * @copyright 2021 Jun Pataleta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */(CourseEvents),_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log);let registered=!1,mctFired=!1;_exports.init=showcompletion=>{if(_log.default.debug("Grid popup JS init"),registered)_log.default.debug("Grid popup JS init already registered");else{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").on("keydown",(function(event){if(13==event.which||27==event.which){event.preventDefault();var trigger=(0,_jquery.default)(event.currentTarget);currentsection=trigger.data("section"),(0,_jquery.default)("#gridPopup").modal("show")}})),(0,_jquery.default)("#gridPopup").on("keydown",(function(event){39==event.which?(event.preventDefault(),(0,_jquery.default)("#gridPopupCarouselRight").trigger("click")):37==event.which&&(event.preventDefault(),(0,_jquery.default)("#gridPopupCarouselLeft").trigger("click"))}))}}})); + */(CourseEvents),_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log);let registered=!1,mctFired=!1;_exports.init=showcompletion=>{if(_log.default.debug("Grid popup JS init"),registered)_log.default.debug("Grid popup JS init already registered");else{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").on("keydown",(function(event){if(13==event.which||27==event.which){event.preventDefault();var trigger=(0,_jquery.default)(event.currentTarget);currentsection=trigger.data("section")}})),(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"))}))}}})); //# 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 52d9d725..a858416e 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';\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 {boolean} showcompletion Show completion is on.\n */\nexport const init = (showcompletion) => {\n log.debug('Grid popup JS init');\n if (registered) {\n log.debug('Grid popup JS init already 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\").on('keydown', function (event) {\n 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 jQuery(\"#gridPopup\").on('keydown', function(event) {\n if (event.which == 39) {\n event.preventDefault();\n jQuery('#gridPopupCarouselRight').trigger('click');\n }\n\n else if (event.which == 37) {\n event.preventDefault();\n jQuery('#gridPopupCarouselLeft').trigger('click');\n }\n });\n};\n"],"names":["registered","mctFired","showcompletion","debug","document","addEventListener","CourseEvents","manualCompletionToggled","currentsection","on","event","section","relatedTarget","data","gml","triggersectionname","text","this","find","addClass","sno","removeClass","window","location","reload","which","preventDefault","trigger","currentTarget","modal"],"mappings":";;;;;;;kGAgCIA,YAAa,EAObC,UAAW,gBAOMC,iCACbC,MAAM,sBACNH,wBACIG,MAAM,8CAIdC,SAASC,iBAAiBC,aAAaC,yBAAyB,KAC5DN,UAAW,KAEfD,YAAa,MAGTQ,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,UACrCnB,gBAAkBD,WAClBA,UAAW,EACXqB,OAAOC,SAASC,iCAIjB,6BAA6Bf,GAAG,WAAW,SAAUC,UACpC,IAAfA,MAAMe,OAAgC,IAAff,MAAMe,MAAc,CAC5Cf,MAAMgB,qBACFC,SAAU,mBAAOjB,MAAMkB,eAC3BpB,eAAiBmB,QAAQd,KAAK,+BACvB,cAAcgB,MAAM,gCAI5B,cAAcpB,GAAG,WAAW,SAASC,OACrB,IAAfA,MAAMe,OACNf,MAAMgB,qCACC,2BAA2BC,QAAQ,UAGtB,IAAfjB,MAAMe,QACXf,MAAMgB,qCACC,0BAA0BC,QAAQ"} \ 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';\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 {boolean} showcompletion Show completion is on.\n */\nexport const init = (showcompletion) => {\n log.debug('Grid popup JS init');\n if (registered) {\n log.debug('Grid popup JS init already 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\").on('keydown', function (event) {\n 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 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"],"names":["registered","mctFired","showcompletion","debug","document","addEventListener","CourseEvents","manualCompletionToggled","currentsection","on","event","section","relatedTarget","data","gml","triggersectionname","text","this","find","addClass","sno","removeClass","window","location","reload","which","preventDefault","trigger","currentTarget"],"mappings":";;;;;;;kGAgCIA,YAAa,EAObC,UAAW,gBAOMC,iCACbC,MAAM,sBACNH,wBACIG,MAAM,8CAIdC,SAASC,iBAAiBC,aAAaC,yBAAyB,KAC5DN,UAAW,KAEfD,YAAa,MAGTQ,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,UACrCnB,gBAAkBD,WAClBA,UAAW,EACXqB,OAAOC,SAASC,iCAIjB,6BAA6Bf,GAAG,WAAW,SAAUC,UACpC,IAAfA,MAAMe,OAAgC,IAAff,MAAMe,MAAc,CAC5Cf,MAAMgB,qBACFC,SAAU,mBAAOjB,MAAMkB,eAC3BpB,eAAiBmB,QAAQd,KAAK,mCAK/B,cAAcJ,GAAG,WAAW,SAASC,OACrB,IAAfA,MAAMe,OAENf,MAAMgB,qCACC,0BAA0BC,QAAQ,UAErB,IAAfjB,MAAMe,QAEXf,MAAMgB,qCACC,2BAA2BC,QAAQ"} \ No newline at end of file diff --git a/amd/build/thegrid.min.js b/amd/build/thegrid.min.js new file mode 100644 index 00000000..4443258a --- /dev/null +++ b/amd/build/thegrid.min.js @@ -0,0 +1,10 @@ +define("format_grid/thegrid",["exports","jquery","core/log"],(function(_exports,_jquery,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} +/** + * JS module for the course homepage. + * + * @module core_course/view + * @copyright 2021 Jun Pataleta + * @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"))}))}}})); + +//# 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 new file mode 100644 index 00000000..f0bc7d10 --- /dev/null +++ b/amd/build/thegrid.min.js.map @@ -0,0 +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 diff --git a/amd/src/popup.js b/amd/src/popup.js index 7ded66b2..bf7b7c6b 100644 --- a/amd/src/popup.js +++ b/amd/src/popup.js @@ -95,19 +95,20 @@ export const init = (showcompletion) => { event.preventDefault(); var trigger = jQuery(event.currentTarget); currentsection = trigger.data('section'); - jQuery('#gridPopup').modal('show'); + //jQuery('#gridPopup').modal('show'); } }); jQuery("#gridPopup").on('keydown', function(event) { - if (event.which == 39) { + if (event.which == 37) { + // Left. event.preventDefault(); - jQuery('#gridPopupCarouselRight').trigger('click'); + jQuery('#gridPopupCarouselLeft').trigger('click'); } - - else if (event.which == 37) { + else if (event.which == 39) { + // Right. event.preventDefault(); - jQuery('#gridPopupCarouselLeft').trigger('click'); + jQuery('#gridPopupCarouselRight').trigger('click'); } }); }; diff --git a/amd/src/thegrid.js b/amd/src/thegrid.js new file mode 100644 index 00000000..07f059e2 --- /dev/null +++ b/amd/src/thegrid.js @@ -0,0 +1,90 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * JS module for the course homepage. + * + * @module core_course/view + * @copyright 2021 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import jQuery from 'jquery'; +import log from 'core/log'; + +/** + * Whether the event listener has already been registered for this module. + * + * @type {boolean} + */ +let registered = false; + +/** + * Function to intialise and register event listeners for this module. + * + * @param {array} sectionnumbers Show completion is on. + */ +export const init = (sectionnumbers) => { + log.debug('Grid thegrid JS init'); + if (registered) { + log.debug('Grid thegrid JS init already registered'); + return; + } else { + log.debug('Grid thegrid sectionnumbers ' + sectionnumbers); + } + registered = true; + + var currentsection = -1; + var endsection = sectionnumbers.length - 1; + + jQuery(document).on('keydown', function(event) { + if (event.which == 37) { + // Left. + event.preventDefault(); + if ((currentsection == -1) || (currentsection == 0)) { + if (currentsection == 0) { + jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section'); + } + currentsection = endsection; + jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section'); + } else { + jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section'); + currentsection = currentsection - 1; + jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section'); + } + log.debug("Left: " + sectionnumbers[currentsection]); + } else if (event.which == 39) { + // Right. + event.preventDefault(); + if ((currentsection == -1) || (currentsection == endsection)) { + if (currentsection == endsection) { + jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section'); + } + currentsection = 0; + jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section'); + } else { + jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section'); + currentsection = currentsection + 1; + jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section'); + } + log.debug("Right: " + sectionnumbers[currentsection]); + } else if ((event.which == 13) || (event.which == 27)) { + event.preventDefault(); + //var trigger = jQuery(event.currentTarget); + //currentsection = trigger.data('section'); + jQuery('#gridPopup').modal('show'); + } + }); +}; diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index 75d7f4a6..4a00cdd2 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -235,6 +235,11 @@ public function export_for_template(\renderer_base $output) { if ((!empty($coursesettings['showcompletion'])) && ($coursesettings['showcompletion'] == 2) && ($completionshown)) { $data->showcompletion = true; } + $gridsectionnums = []; + foreach ($data->gridsections as $gridsection) { + $gridsectionnums[] = $gridsection->number; + } + $data->gridsectionnumbers = implode(',', $gridsectionnums); } if ($headerimages) { diff --git a/styles.css b/styles.css index 922b9cf0..46a218e3 100644 --- a/styles.css +++ b/styles.css @@ -68,6 +68,10 @@ border: 2px solid var(--primary); } +.format-grid .thegrid .grid-current-section { + border: 5px solid #fab; +} + .format-grid .thegrid .grid-image { height: 140px; position: relative; diff --git a/templates/grid.mustache b/templates/grid.mustache index d9092c0c..7bf986b2 100644 --- a/templates/grid.mustache +++ b/templates/grid.mustache @@ -180,3 +180,9 @@ require(['format_grid/popup'], function(popuphandler) { }); {{/js}} {{/popup}} +{{#js}} +require(['format_grid/thegrid'], function(gridhandler) { + var sectionnumbers = [{{gridsectionnumbers}}]; + gridhandler.init(sectionnumbers); +}); +{{/js}}