diff --git a/amd/build/thegrid.min.js b/amd/build/thegrid.min.js index 0387d3c7..8d3d7a6d 100644 --- a/amd/build/thegrid.min.js +++ b/amd/build/thegrid.min.js @@ -6,6 +6,6 @@ define("format_grid/thegrid",["exports","core_course/events","jquery","core/log" * @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 - */(CourseEvents),_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log);let registered=!1,mctFired=!1;_exports.init=(sectionnumbers,ispopup,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 currentmodalsection=null,modalshown=!1,popup=ispopup,currentsection=null,currentsectionshown=!1,endsection=sectionnumbers.length-1,sectionchange=function(direction){null===currentsection&&(currentsection=direction<0?endsection:0),null!==currentsection&&((0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),(currentsection+=direction)<0?currentsection=endsection:currentsection>endsection&&(currentsection=0),(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section"))};popup&&((0,_jquery.default)("#gridPopup").on("show.bs.modal",(function(event){if(modalshown=!0,null===currentmodalsection){var trigger=(0,_jquery.default)(event.relatedTarget);currentmodalsection=trigger.data("section")}currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=currentmodalsection-1,currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section");var gml=(0,_jquery.default)("#gridPopupLabel"),triggersectionname=(0,_jquery.default)("#gridpopupsection-"+currentmodalsection).data("sectiontitle");gml.text(triggersectionname),(0,_jquery.default)(this).find("#gridpopupsection-"+currentmodalsection).addClass("active"),(0,_jquery.default)("#gridPopupCarousel").on("slid.bs.carousel",(function(event){var item=(0,_jquery.default)(".gridcarousel-item.active"),st=item.data("sectiontitle");gml.text(st),_log.default.debug("Carousel direction: "+event.direction),currentmodalsection=item.data("section"),currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=currentmodalsection-1,currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")}))})),(0,_jquery.default)("#gridPopup").on("hidden.bs.modal",(function(){currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=currentmodalsection-1,currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section"),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"),(0,_jquery.default)("#gridPopup").modal("show")}}))),(0,_jquery.default)(document).on("keydown",(function(event){37==event.which?(event.preventDefault(),currentsectionshown=!0,sectionchange(-1),_log.default.debug("Left: "+sectionnumbers[currentsection]),modalshown&&(0,_jquery.default)("#gridPopupCarouselLeft").trigger("click")):39==event.which?(event.preventDefault(),currentsectionshown=!0,sectionchange(1),_log.default.debug("Right: "+sectionnumbers[currentsection]),modalshown&&(0,_jquery.default)("#gridPopupCarouselRight").trigger("click")):13!=event.which&&27!=event.which||popup&&!modalshown&¤tsectionshown&&(null===currentmodalsection&&(currentmodalsection=sectionnumbers[currentsection]),(0,_jquery.default)("#gridPopup").modal("show"))}))}}})); + */(CourseEvents),_jquery=_interopRequireDefault(_jquery),_log=_interopRequireDefault(_log);let registered=!1,mctFired=!1;_exports.init=(sectionnumbers,popup,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 currentmodalsection=null,modalshown=!1,currentsection=null,currentsectionshown=!1,endsection=sectionnumbers.length-1,sectionchange=function(direction){null===currentsection&&(currentsection=direction<0?endsection:0),null!==currentsection&&((0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),(currentsection+=direction)<0?currentsection=endsection:currentsection>endsection&&(currentsection=0),(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section"))};if(popup){var updatecurrentsection=function(){currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).removeClass("grid-current-section"),currentsection=currentmodalsection-1,currentsectionshown&&(0,_jquery.default)("#section-"+sectionnumbers[currentsection]).addClass("grid-current-section")};(0,_jquery.default)("#gridPopup").on("show.bs.modal",(function(event){if(modalshown=!0,null===currentmodalsection){var trigger=(0,_jquery.default)(event.relatedTarget);currentmodalsection=trigger.data("section")}updatecurrentsection();var gml=(0,_jquery.default)("#gridPopupLabel"),triggersectionname=(0,_jquery.default)("#gridpopupsection-"+currentmodalsection).data("sectiontitle");gml.text(triggersectionname),(0,_jquery.default)(this).find("#gridpopupsection-"+currentmodalsection).addClass("active"),(0,_jquery.default)("#gridPopupCarousel").on("slid.bs.carousel",(function(event){var item=(0,_jquery.default)(".gridcarousel-item.active"),st=item.data("sectiontitle");gml.text(st),_log.default.debug("Carousel direction: "+event.direction),currentmodalsection=item.data("section"),updatecurrentsection()}))})),(0,_jquery.default)("#gridPopup").on("hidden.bs.modal",(function(){updatecurrentsection(),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"),(0,_jquery.default)("#gridPopup").modal("show")}}))}(0,_jquery.default)(document).on("keydown",(function(event){37==event.which?(event.preventDefault(),currentsectionshown=!0,sectionchange(-1),_log.default.debug("Left: "+sectionnumbers[currentsection]),modalshown&&(0,_jquery.default)("#gridPopupCarouselLeft").trigger("click")):39==event.which?(event.preventDefault(),currentsectionshown=!0,sectionchange(1),_log.default.debug("Right: "+sectionnumbers[currentsection]),modalshown&&(0,_jquery.default)("#gridPopupCarouselRight").trigger("click")):13!=event.which&&27!=event.which||popup&&!modalshown&¤tsectionshown&&(null===currentmodalsection&&(currentmodalsection=sectionnumbers[currentsection]),(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 abf8d3f6..63245c4b 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 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} ispopup Popup is used.\n * @param {boolean} showcompletion Show completion is on.\n */\nexport const init = (sectionnumbers, ispopup, 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 // Modal.\n var currentmodalsection = null;\n var modalshown = false;\n var popup = ispopup;\n\n // Grid current section.\n var currentsection = null;\n var currentsectionshown = false;\n var endsection = sectionnumbers.length - 1;\n\n /**\n * Change the current selected section, arrow keys only.\n * If the modal is shown then will also move the carousel.\n * @param {int} direction -1 = left and 1 = right.\n */\n var sectionchange = function (direction) {\n if (currentsection === null) {\n if (direction < 0) {\n currentsection = endsection;\n } else {\n currentsection = 0;\n }\n }\n if (currentsection !== null) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n currentsection = currentsection + direction;\n if (currentsection < 0) {\n currentsection = endsection;\n } else if (currentsection > endsection) {\n currentsection = 0;\n }\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n };\n\n if (popup) {\n jQuery('#gridPopup').on('show.bs.modal', function (event) {\n modalshown = true;\n if (currentmodalsection === null) {\n var trigger = jQuery(event.relatedTarget);\n currentmodalsection = trigger.data('section');\n }\n // Section highlighting is been used (arrow keys) and possibly a different section has been selected.\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = currentmodalsection - 1;\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n\n var gml = jQuery('#gridPopupLabel');\n var triggersectionname = jQuery('#gridpopupsection-' + currentmodalsection).data('sectiontitle');\n gml.text(triggersectionname);\n\n var modal = jQuery(this);\n modal.find('#gridpopupsection-' + currentmodalsection).addClass('active');\n\n jQuery('#gridPopupCarousel').on('slid.bs.carousel', function (event) {\n var item = jQuery('.gridcarousel-item.active');\n var st = item.data('sectiontitle');\n gml.text(st);\n log.debug(\"Carousel direction: \" + event.direction);\n currentmodalsection = item.data('section');\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = currentmodalsection - 1;\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n });\n });\n\n jQuery('#gridPopup').on('hidden.bs.modal', function () {\n // Section highlighting is been used (arrow keys) and possibly a different section has been selected.\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = currentmodalsection - 1;\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\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 // Clicked within the modal\n if ((event.which == 13) || (event.which == 27)) {\n event.preventDefault();\n var trigger = jQuery(event.currentTarget);\n currentmodalsection = trigger.data('section');\n jQuery('#gridPopup').modal('show');\n }\n });\n }\n\n jQuery(document).on('keydown', function (event) {\n if (event.which == 37) {\n // Left.\n event.preventDefault();\n currentsectionshown = true;\n sectionchange(-1);\n log.debug(\"Left: \" + sectionnumbers[currentsection]);\n if (modalshown) {\n jQuery('#gridPopupCarouselLeft').trigger('click');\n }\n } else if (event.which == 39) {\n // Right.\n event.preventDefault();\n currentsectionshown = true;\n sectionchange(1);\n log.debug(\"Right: \" + sectionnumbers[currentsection]);\n if (modalshown) {\n jQuery('#gridPopupCarouselRight').trigger('click');\n }\n } else if ((event.which == 13) || (event.which == 27)) {\n // Enter (13) and ESC keys (27).\n if ((popup) && (!modalshown)) {\n if (currentsectionshown) {\n if (currentmodalsection === null) {\n currentmodalsection = sectionnumbers[currentsection];\n }\n jQuery('#gridPopup').modal('show');\n }\n }\n }\n });\n};\n"],"names":["registered","mctFired","sectionnumbers","ispopup","showcompletion","debug","document","addEventListener","CourseEvents","manualCompletionToggled","currentmodalsection","modalshown","popup","currentsection","currentsectionshown","endsection","length","sectionchange","direction","removeClass","addClass","on","event","trigger","relatedTarget","data","gml","triggersectionname","text","this","find","item","st","window","location","reload","which","preventDefault","currentTarget","modal"],"mappings":";;;;;;;;kGAiCIA,YAAa,EAObC,UAAW,gBASK,CAACC,eAAgBC,QAASC,kCACtCC,MAAM,wBACNL,wBACIK,MAAM,6DAGNA,MAAM,+BAAiCH,gBAG/CI,SAASC,iBAAiBC,aAAaC,yBAAyB,KAC5DR,UAAW,KAEfD,YAAa,MAGTU,oBAAsB,KACtBC,YAAa,EACbC,MAAQT,QAGRU,eAAiB,KACjBC,qBAAsB,EACtBC,WAAab,eAAec,OAAS,EAOrCC,cAAgB,SAAUC,WACH,OAAnBL,iBAEIA,eADAK,UAAY,EACKH,WAEA,GAGF,OAAnBF,qCACO,YAAcX,eAAeW,iBAAiBM,YAAY,yBACjEN,gBAAkCK,WACb,EACjBL,eAAiBE,WACVF,eAAiBE,aACxBF,eAAiB,uBAEd,YAAcX,eAAeW,iBAAiBO,SAAS,0BAIlER,4BACO,cAAcS,GAAG,iBAAiB,SAAUC,UAC/CX,YAAa,EACe,OAAxBD,oBAA8B,KAC1Ba,SAAU,mBAAOD,MAAME,eAC3Bd,oBAAsBa,QAAQE,KAAK,WAGnCX,yCACO,YAAcZ,eAAeW,iBAAiBM,YAAY,wBAErEN,eAAiBH,oBAAsB,EACnCI,yCAC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AAMc,OAAgC,IAAfd,MAAMc,OAEhCxB,QAAYD,YACTG,sBAC4B,OAAxBJ,sBACAA,oBAAsBR,eAAeW,qCAElC,cAAc0B,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} popup Popup is used.\n * @param {boolean} showcompletion Show completion is on.\n */\nexport const init = (sectionnumbers, popup, 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 // Modal.\n var currentmodalsection = null;\n var modalshown = false;\n\n // Grid current section.\n var currentsection = null;\n var currentsectionshown = false;\n var endsection = sectionnumbers.length - 1;\n\n /**\n * Change the current selected section, arrow keys only.\n * If the modal is shown then will also move the carousel.\n * @param {int} direction -1 = left and 1 = right.\n */\n var sectionchange = function (direction) {\n if (currentsection === null) {\n if (direction < 0) {\n currentsection = endsection;\n } else {\n currentsection = 0;\n }\n }\n if (currentsection !== null) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n currentsection = currentsection + direction;\n if (currentsection < 0) {\n currentsection = endsection;\n } else if (currentsection > endsection) {\n currentsection = 0;\n }\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n };\n\n if (popup) {\n var updatecurrentsection = function () {\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section');\n }\n currentsection = currentmodalsection - 1;\n if (currentsectionshown) {\n jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section');\n }\n };\n\n jQuery('#gridPopup').on('show.bs.modal', function (event) {\n modalshown = true;\n if (currentmodalsection === null) {\n var trigger = jQuery(event.relatedTarget);\n currentmodalsection = trigger.data('section');\n }\n\n updatecurrentsection();\n\n var gml = jQuery('#gridPopupLabel');\n var triggersectionname = jQuery('#gridpopupsection-' + currentmodalsection).data('sectiontitle');\n gml.text(triggersectionname);\n\n var modal = jQuery(this);\n modal.find('#gridpopupsection-' + currentmodalsection).addClass('active');\n\n jQuery('#gridPopupCarousel').on('slid.bs.carousel', function (event) {\n var item = jQuery('.gridcarousel-item.active');\n var st = item.data('sectiontitle');\n gml.text(st);\n log.debug(\"Carousel direction: \" + event.direction);\n currentmodalsection = item.data('section');\n updatecurrentsection();\n });\n });\n\n jQuery('#gridPopup').on('hidden.bs.modal', function () {\n updatecurrentsection();\n\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 // Clicked within the modal\n if ((event.which == 13) || (event.which == 27)) {\n event.preventDefault();\n var trigger = jQuery(event.currentTarget);\n currentmodalsection = trigger.data('section');\n jQuery('#gridPopup').modal('show');\n }\n });\n }\n\n jQuery(document).on('keydown', function (event) {\n if (event.which == 37) {\n // Left.\n event.preventDefault();\n currentsectionshown = true;\n sectionchange(-1);\n log.debug(\"Left: \" + sectionnumbers[currentsection]);\n if (modalshown) {\n jQuery('#gridPopupCarouselLeft').trigger('click');\n }\n } else if (event.which == 39) {\n // Right.\n event.preventDefault();\n currentsectionshown = true;\n sectionchange(1);\n log.debug(\"Right: \" + sectionnumbers[currentsection]);\n if (modalshown) {\n jQuery('#gridPopupCarouselRight').trigger('click');\n }\n } else if ((event.which == 13) || (event.which == 27)) {\n // Enter (13) and ESC keys (27).\n if ((popup) && (!modalshown)) {\n if (currentsectionshown) {\n if (currentmodalsection === null) {\n currentmodalsection = sectionnumbers[currentsection];\n }\n jQuery('#gridPopup').modal('show');\n }\n }\n }\n });\n};\n"],"names":["registered","mctFired","sectionnumbers","popup","showcompletion","debug","document","addEventListener","CourseEvents","manualCompletionToggled","currentmodalsection","modalshown","currentsection","currentsectionshown","endsection","length","sectionchange","direction","removeClass","addClass","updatecurrentsection","on","event","trigger","relatedTarget","data","gml","triggersectionname","text","this","find","item","st","window","location","reload","which","preventDefault","currentTarget","modal"],"mappings":";;;;;;;;kGAiCIA,YAAa,EAObC,UAAW,gBASK,CAACC,eAAgBC,MAAOC,kCACpCC,MAAM,wBACNL,wBACIK,MAAM,6DAGNA,MAAM,+BAAiCH,gBAG/CI,SAASC,iBAAiBC,aAAaC,yBAAyB,KAC5DR,UAAW,KAEfD,YAAa,MAGTU,oBAAsB,KACtBC,YAAa,EAGbC,eAAiB,KACjBC,qBAAsB,EACtBC,WAAaZ,eAAea,OAAS,EAOrCC,cAAgB,SAAUC,WACH,OAAnBL,iBAEIA,eADAK,UAAY,EACKH,WAEA,GAGF,OAA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AeU,iBAChCD,gCACO,0BAA0BY,QAAQ,UAEvB,IAAfD,MAAMc,OAEbd,MAAMe,iBACNxB,qBAAsB,EACtBG,cAAc,gBACVX,MAAM,UAAYH,eAAeU,iBACjCD,gCACO,2BAA2BY,QAAQ,UAEvB,IAAfD,MAAMc,OAAgC,IAAfd,MAAMc,OAEhCjC,QAAYQ,YACTE,sBAC4B,OAAxBH,sBACAA,oBAAsBR,eAAeU,qCAElC,cAAc2B,MAAM"} \ No newline at end of file diff --git a/amd/src/thegrid.js b/amd/src/thegrid.js index fc1f69ad..08df8fd9 100644 --- a/amd/src/thegrid.js +++ b/amd/src/thegrid.js @@ -44,10 +44,10 @@ let mctFired = false; * Function to intialise and register event listeners for this module. * * @param {array} sectionnumbers Show completion is on. - * @param {boolean} ispopup Popup is used. + * @param {boolean} popup Popup is used. * @param {boolean} showcompletion Show completion is on. */ -export const init = (sectionnumbers, ispopup, showcompletion) => { +export const init = (sectionnumbers, popup, showcompletion) => { log.debug('Grid thegrid JS init'); if (registered) { log.debug('Grid thegrid JS init already registered'); @@ -64,7 +64,6 @@ export const init = (sectionnumbers, ispopup, showcompletion) => { // Modal. var currentmodalsection = null; var modalshown = false; - var popup = ispopup; // Grid current section. var currentsection = null; @@ -97,13 +96,7 @@ export const init = (sectionnumbers, ispopup, showcompletion) => { }; if (popup) { - jQuery('#gridPopup').on('show.bs.modal', function (event) { - modalshown = true; - if (currentmodalsection === null) { - var trigger = jQuery(event.relatedTarget); - currentmodalsection = trigger.data('section'); - } - // Section highlighting is been used (arrow keys) and possibly a different section has been selected. + var updatecurrentsection = function () { if (currentsectionshown) { jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section'); } @@ -111,6 +104,16 @@ export const init = (sectionnumbers, ispopup, showcompletion) => { if (currentsectionshown) { jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section'); } + }; + + jQuery('#gridPopup').on('show.bs.modal', function (event) { + modalshown = true; + if (currentmodalsection === null) { + var trigger = jQuery(event.relatedTarget); + currentmodalsection = trigger.data('section'); + } + + updatecurrentsection(); var gml = jQuery('#gridPopupLabel'); var triggersectionname = jQuery('#gridpopupsection-' + currentmodalsection).data('sectiontitle'); @@ -125,25 +128,13 @@ export const init = (sectionnumbers, ispopup, showcompletion) => { gml.text(st); log.debug("Carousel direction: " + event.direction); currentmodalsection = item.data('section'); - if (currentsectionshown) { - jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section'); - } - currentsection = currentmodalsection - 1; - if (currentsectionshown) { - jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section'); - } + updatecurrentsection(); }); }); jQuery('#gridPopup').on('hidden.bs.modal', function () { - // Section highlighting is been used (arrow keys) and possibly a different section has been selected. - if (currentsectionshown) { - jQuery('#section-' + sectionnumbers[currentsection]).removeClass('grid-current-section'); - } - currentsection = currentmodalsection - 1; - if (currentsectionshown) { - jQuery('#section-' + sectionnumbers[currentsection]).addClass('grid-current-section'); - } + updatecurrentsection(); + if (currentmodalsection !== null) { currentmodalsection = null; }