"),item.haschildren&&item.children.forEach((child=>{html+=this.renderMenuItems(child,fullName)})),html},show(){this.mainModal.style.display="block",this.mainModalBackLayer.style.display="block",this.isShow=!0,this.mainModalCommand.focus()},hide(){this.mainModal.style.display="none",this.mainModalBackLayer.style.display="none",this.isShow=!1},setHeight(){const height=Math.round(window.innerHeight/2);this.mainModal.style.height="".concat(height,"px");const bodyDiv=this.mainModal.querySelector(".local_commander-body div");bodyDiv&&(bodyDiv.style.height="".concat(height-100,"px"))},removeHighlight(node){node.innerHTML=node.textContent}};var _default={init:function(params){var options;options=params,Object.keys(commanderAppOptions).forEach((key=>{if(options.hasOwnProperty(key)){const vartype=typeof commanderAppOptions[key];commanderAppOptions[key]="boolean"===vartype?Boolean(options[key]):"number"===vartype?Number(options[key]):"string"===vartype?String(options[key]):options[key]}})),document.addEventListener("DOMContentLoaded",(()=>{_log.default.debug("DOM fully loaded - initializing commanderApp"),_log.default.debug(commanderAppOptions),commanderApp.start()}))}};return _exports.default=_default,_exports.default}));
//# sourceMappingURL=commander.min.js.map
\ No newline at end of file
diff --git a/amd/build/commander.min.js.map b/amd/build/commander.min.js.map
index 122631a..5956168 100644
--- a/amd/build/commander.min.js.map
+++ b/amd/build/commander.min.js.map
@@ -1 +1 @@
-{"version":3,"file":"commander.min.js","sources":["../src/commander.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 to the popup and interact with it.\n *\n *\n * Tested in Moodle 3.8\n *\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @copyright 2018 MFreak.nl\n * @author Luuk Verhoeven\n **/\n/* eslint-disable no-invalid-this */\ndefine(['jquery', 'core/notification', 'core/log'], function($, notification, Log) {\n 'use strict';\n\n // Keyboard codes.\n var ESCAPE = 27,\n ENTER = 13,\n ARROWUP = 38,\n ARROWDOWN = 40;\n\n /**\n * scroll to element.\n *\n * @param {string} elem\n * @param {int} speed\n * @returns {$}\n */\n $.fn.scrollTo = function(elem, speed) {\n $(this).stop().animate({\n scrollTop: $(this).scrollTop() - $(this).offset().top + $(elem).offset().top - 10\n }, speed == undefined ? 1000 : speed);\n return this;\n };\n\n /**\n * Options we can set from amd.\n * @type {{selector: string, blockid: number}}\n */\n var commanderAppOptions = {\n courseid: '',\n keys: [],\n };\n\n /**\n * Set options base on listed options\n * @param {object} options\n */\n var setOptions = function(options) {\n \"use strict\";\n var key, vartype;\n for (key in commanderAppOptions) {\n if (commanderAppOptions.hasOwnProperty(key) && options.hasOwnProperty(key)) {\n\n // Casting to prevent errors.\n vartype = typeof commanderAppOptions[key];\n if (vartype === \"boolean\") {\n commanderAppOptions[key] = Boolean(options[key]);\n } else if (vartype === 'number') {\n commanderAppOptions[key] = Number(options[key]);\n } else if (vartype === 'string') {\n commanderAppOptions[key] = String(options[key]);\n } else {\n commanderAppOptions[key] = options[key];\n }\n }\n }\n };\n\n /**\n * Commander plugin.\n * @type {{}}\n */\n const commanderApp = {\n\n /**\n * Modal jQuery element instance.\n */\n $mainModal: false,\n\n /**\n * Modal BG jQuery element instance.\n */\n $mainModalBackLayer: false,\n\n /**\n * Input field\n */\n $mainModalCommand: false,\n\n /**\n * Stores all li elements\n */\n $liSet: false,\n\n /**\n * Flag to check if modal is open.\n */\n isShow: false,\n\n /**\n * Save response\n */\n json: '',\n\n /**\n * Render UI.\n */\n render: function() {\n \"use strict\";\n var timer = 0;\n Log.debug('render UI');\n\n // @TODO we should use mustache.\n $('body').append('
');\n\n // Set references.\n commanderApp.$mainModal = $('#local_commander_modal');\n commanderApp.$mainModalBackLayer = $('#local_commander_back_layer');\n commanderApp.$mainModalCommand = $('#local_commander_command');\n\n commanderApp.setHeight();\n\n commanderApp.$mainModalBackLayer.on('click', function() {\n commanderApp.hide();\n });\n\n // Search set some timeout optimize speed.\n commanderApp.$mainModalCommand.on('keydown', function(e) {\n var keyboardCode = e.keyCode || e.which;\n Log.debug('Code pressed:' + keyboardCode);\n\n switch (keyboardCode) {\n case ESCAPE:\n case ENTER:\n case ARROWUP:\n case ARROWDOWN:\n return;\n }\n\n Log.debug('Searching');\n\n clearTimeout(timer);\n timer = setTimeout(function() {\n commanderApp.search(commanderApp.$mainModalCommand.val());\n }, 100);\n });\n\n // Loading the menu content once.\n if (commanderApp.json === '') {\n commanderApp.loadMenu();\n }\n },\n\n /**\n * Start the commander.\n */\n start: function() {\n // Set holders.\n commanderApp.$mainModal = $('#local_commander_modal');\n\n $(window).on('keydown', function(e) {\n\n var keyboardCode = e.keyCode || e.which;\n Log.debug('Code pressed:', keyboardCode);\n Log.debug('Trigger keys:', commanderAppOptions.keys);\n Log.debug('Commander is visible:', commanderApp.isShow);\n\n // Check for arrow keys.\n if (commanderApp.isShow) {\n switch (keyboardCode) {\n case ESCAPE:\n commanderApp.hide();\n break;\n\n case ENTER:\n e.preventDefault();\n commanderApp.goToCommand();\n break;\n\n case ARROWUP:\n e.preventDefault();\n commanderApp.arrowUp();\n break;\n\n case ARROWDOWN:\n e.preventDefault();\n commanderApp.arrowDown();\n break;\n }\n return;\n }\n\n if (commanderAppOptions.keys.indexOf(keyboardCode.toString()) !== -1) {\n\n Log.debug('Commander keyboard key triggered');\n\n // Validate we not triggered in an editable area.\n if (e.target.tagName == 'INPUT' || e.target.tagName == 'SELECT'\n || e.target.tagName == 'TEXTAREA' || e.target.isContentEditable) {\n Log.debug('Hide when we are in an editable element');\n return;\n }\n\n e.preventDefault();\n\n // Only render if needed.\n if (commanderApp.$mainModal.length == 0) {\n commanderApp.render();\n }\n\n Log.debug('Open commander.');\n\n if (commanderApp.isShow) {\n commanderApp.hide();\n } else {\n commanderApp.show();\n }\n }\n });\n },\n\n /**\n * Highlight words\n *\n * @param {object} node\n * @param {string} word\n */\n highlightWord: function(node, word) {\n if (node.nodeType == 3) {\n var pos = node.data.toUpperCase().indexOf(word);\n if (pos >= 0) {\n var spannode = document.createElement('span');\n spannode.className = 'highlight';\n spannode.style.backgroundColor = '#f4bd21';\n var middlebit = node.splitText(pos);\n var middleclone = middlebit.cloneNode(true);\n spannode.appendChild(middleclone);\n middlebit.parentNode.replaceChild(spannode, middlebit);\n }\n\n } else if (node.nodeType == 1 && node.childNodes) {\n for (var i = 0; i < node.childNodes.length; ++i) {\n i += commanderApp.highlightWord(node.childNodes[i], word);\n }\n }\n },\n\n /**\n * Action on keyboard arrow key UP.\n */\n arrowUp: function() {\n Log.debug('arrowUp');\n var $el = $('#local_commander_modal ul li.active'),\n $prev = $el.closest(\"li\").prevAll(\"li:visible\").eq(0);\n\n if ($el.length) {\n $el.removeClass('active');\n }\n\n if ($prev.length) {\n $prev.addClass('active');\n } else {\n $el.addClass('active');\n }\n\n //\n commanderApp.scrollTo();\n },\n\n /**\n * Action on keyboard arrow key DOWN.\n */\n arrowDown: function() {\n Log.debug('arrowDown');\n var $el = $('#local_commander_modal ul li.active'),\n $next = $el.closest(\"li\").nextAll(\"li:visible\").eq(0);\n\n if ($el.length) {\n $el.removeClass('active');\n }\n if ($next.length) {\n $next.addClass('active');\n } else {\n $('#local_commander_modal ul li:visible').last().addClass('active');\n }\n //\n commanderApp.scrollTo();\n },\n\n /**\n * Scroll to active item.\n */\n scrollTo: function() {\n $('#local_commander_modal .local_commander-body div').scrollTo('#local_commander_modal li.active', 200);\n },\n\n /**\n * The command that we need to execute.\n */\n goToCommand: function() {\n Log.debug('goToCommand');\n // Check if there is a element selected.\n // Check if the element has link.\n // TODO maybe add way to execute other type of commands.\n var $el = $('#local_commander_modal ul li.active a');\n if ($el) {\n var link = $el.attr('href');\n if (link != '#') {\n window.location = link;\n }\n }\n },\n\n /**\n * Load menu\n */\n loadMenu: function() {\n \"use strict\";\n\n // TODO use the default webservice from Moodle instead.\n $.ajax({\n url: M.cfg.wwwroot + '/local/commander/ajax.php',\n method: \"GET\",\n data: {\n 'courseid': commanderAppOptions.courseid\n },\n dataType: \"json\",\n }).done(function(response) {\n Log.debug(response);\n commanderApp.json = response;\n\n commanderApp.setMenu();\n commanderApp.setHeight();\n }).fail(function() {\n notification.alert('js:error_parsing', 'local_commander');\n });\n },\n\n /**\n * Search in the commands.\n * @param {string} word\n */\n search: function(word) {\n \"use strict\";\n\n // Remove active.\n $('.local_commander-body ul li').show();\n commanderApp.$liSet.find('li.active').removeClass('active');\n\n // Remove highlights.\n commanderApp.$liSet.find(\"span.highlight\").each(function() {\n commanderApp.removeHighlight(this.parentNode);\n });\n\n if (word !== '') {\n\n commanderApp.$liSet.children().each(function() {\n commanderApp.highlightWord(this, word.toUpperCase());\n });\n\n // Set active li item.\n $('.local_commander-body span.highlight').first().parent().parent().addClass('active');\n\n // Hide others.\n $('.local_commander-body ul li:not(:has(span))').hide();\n }\n },\n\n /**\n * Build the ul command list.\n */\n setMenu: function() {\n \"use strict\";\n Log.debug('setMenu() ');\n\n var html = '
';\n\n // Only do things when needed.\n if (commanderAppOptions.courseid > 0) {\n Log.debug('Has course param.');\n html += commanderApp.renderMenuItems(commanderApp.json.courseadmin, 1);\n }\n\n // Always try adding admin menu.\n html += commanderApp.renderMenuItems(commanderApp.json.admin, 1);\n\n html += '
';\n commanderApp.$mainModal.find('.local_commander-body').append(html);\n\n commanderApp.$liSet = $('.local_commander-body ul');\n },\n\n /**\n * Render items and add the correct attr.\n *\n * @param {object} child\n * @param {int} depth\n * @param {string} parentName\n *\n * @returns {string}\n */\n renderMenuItems: function(child, depth, parentName) {\n \"use strict\";\n var html = '';\n\n // Check child.\n if (!child.name) {\n return html;\n }\n\n // Set parentName.\n if (!parentName) {\n parentName = '';\n } else {\n parentName += ' → ';\n }\n\n html += '
';\n\n if (child.name) {\n // Add the same to buffer.\n //\n html += '' + parentName + child.name + '';\n }\n\n if (child.haschildren) {\n $.each(child.children, function(i, el) {\n html += commanderApp.renderMenuItems(el, depth + 1, parentName + child.name);\n });\n }\n\n html += '
';\n return html;\n },\n\n /**\n * Show the modal\n */\n show: function() {\n \"use strict\";\n commanderApp.$mainModal.show();\n commanderApp.$mainModalBackLayer.show();\n\n commanderApp.isShow = true;\n\n // Focus on search field.\n commanderApp.$mainModalCommand.focus();\n },\n\n /**\n * Hide the modal\n */\n hide: function() {\n commanderApp.$mainModal.hide();\n commanderApp.$mainModalBackLayer.hide();\n\n commanderApp.isShow = false;\n },\n\n /**\n * Set 50% of viewport height\n */\n setHeight: function() {\n var height = Math.round($(window).height() / 2);\n commanderApp.$mainModal.height(height);\n $('.local_commander-body div').height(height - 100);\n },\n\n /**\n * Remove highlight\n * @param {object} node\n */\n removeHighlight: function(node) {\n $(node).html($(node).text());\n }\n };\n\n return {\n\n /**\n * Called from Moodle.\n * @param {array} params\n */\n init: function(params) {\n\n /**\n * Set the options.\n */\n setOptions(params);\n\n /**\n * Wait for jQuery\n */\n $(document).ready(function() {\n Log.debug('ready() - local commander v4.4');\n Log.debug(commanderAppOptions);\n commanderApp.start();\n });\n }\n };\n});\n"],"names":["define","$","notification","Log","fn","scrollTo","elem","speed","this","stop","animate","scrollTop","offset","top","undefined","commanderAppOptions","courseid","keys","commanderApp","$mainModal","$mainModalBackLayer","$mainModalCommand","$liSet","isShow","json","render","timer","debug","append","M","util","get_string","setHeight","on","hide","e","keyboardCode","keyCode","which","clearTimeout","setTimeout","search","val","loadMenu","start","window","preventDefault","goToCommand","arrowUp","arrowDown","indexOf","toString","target","tagName","isContentEditable","length","show","highlightWord","node","word","nodeType","pos","data","toUpperCase","spannode","document","createElement","className","style","backgroundColor","middlebit","splitText","middleclone","cloneNode","appendChild","parentNode","replaceChild","childNodes","i","$el","$prev","closest","prevAll","eq","removeClass","addClass","$next","nextAll","last","link","attr","location","ajax","url","cfg","wwwroot","method","dataType","done","response","setMenu","fail","alert","find","each","removeHighlight","children","first","parent","html","renderMenuItems","courseadmin","admin","child","depth","parentName","name","haschildren","el","focus","height","Math","round","text","init","params","options","key","vartype","hasOwnProperty","Boolean","Number","String","setOptions","ready"],"mappings":";;;;;;;;;;AA0BAA,mCAAO,CAAC,SAAU,oBAAqB,aAAa,SAASC,EAAGC,aAAcC,KAgB1EF,EAAEG,GAAGC,SAAW,SAASC,KAAMC,cAC3BN,EAAEO,MAAMC,OAAOC,QAAQ,CACnBC,UAAWV,EAAEO,MAAMG,YAAcV,EAAEO,MAAMI,SAASC,IAAMZ,EAAEK,MAAMM,SAASC,IAAM,IACvEC,MAATP,MAAqB,IAAOA,OACxBC,UAOPO,oBAAsB,CACtBC,SAAU,GACVC,KAAM,UAgCJC,aAAe,CAKjBC,YAAY,EAKZC,qBAAqB,EAKrBC,mBAAmB,EAKnBC,QAAQ,EAKRC,QAAQ,EAKRC,KAAM,GAKNC,OAAQ,eAEAC,MAAQ,EACZvB,IAAIwB,MAAM,aAGV1B,EAAE,QAAQ2B,OAAO,mGACgCC,EAAEC,KAAKC,WAAW,YAAa,mBAD/D,kJAKbF,EAAEC,KAAKC,WAAW,yBAA0B,mBAL/B,uDASjBb,aAAaC,WAAalB,EAAE,0BAC5BiB,aAAaE,oBAAsBnB,EAAE,+BACrCiB,aAAaG,kBAAoBpB,EAAE,4BAEnCiB,aAAac,YAEbd,aAAaE,oBAAoBa,GAAG,SAAS,WACzCf,aAAagB,UAIjBhB,aAAaG,kBAAkBY,GAAG,WAAW,SAASE,OAC9CC,aAAeD,EAAEE,SAAWF,EAAEG,aAClCnC,IAAIwB,MAAM,gBAAkBS,cAEpBA,mBA1HP,QACD,QACE,QACE,UA+HJjC,IAAIwB,MAAM,aAEVY,aAAab,OACbA,MAAQc,YAAW,WACftB,aAAauB,OAAOvB,aAAaG,kBAAkBqB,SACpD,QAImB,KAAtBxB,aAAaM,MACbN,aAAayB,YAOrBC,MAAO,WAEH1B,aAAaC,WAAalB,EAAE,0B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AGlEC,eAAiBjH,oBAAoBgH,KAEjChH,oBAAoBgH,KADR,YAAZC,QAC2BE,QAAQJ,QAAQC,MACxB,WAAZC,QACoBG,OAAOL,QAAQC,MACvB,WAAZC,QACoBI,OAAON,QAAQC,MAEfD,QAAQC,MAgb3CM,CAAWR,QAKX5H,EAAEgE,UAAUqE,OAAM,WACdnI,IAAIwB,MAAM,kCACVxB,IAAIwB,MAAMZ,qBACVG,aAAa0B"}
\ No newline at end of file
+{"version":3,"file":"commander.min.js","sources":["../src/commander.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// Initialize the module with imports.\nimport notification from 'core/notification';\nimport Log from 'core/log';\n\n/**\n * Keyboard key codes.\n */\nconst ESCAPE = 27;\nconst ENTER = 13;\nconst ARROWUP = 38;\nconst ARROWDOWN = 40;\n\n/**\n * Options we can set from AMD.\n */\nconst commanderAppOptions = {\n courseid: '',\n keys: [],\n};\n\n/**\n * Set options based on provided parameters.\n * @param {object} options\n */\nfunction setOptions(options) {\n Object.keys(commanderAppOptions).forEach((key) => {\n if (options.hasOwnProperty(key)) {\n const vartype = typeof commanderAppOptions[key];\n if (vartype === 'boolean') {\n commanderAppOptions[key] = Boolean(options[key]);\n } else if (vartype === 'number') {\n commanderAppOptions[key] = Number(options[key]);\n } else if (vartype === 'string') {\n commanderAppOptions[key] = String(options[key]);\n } else {\n commanderAppOptions[key] = options[key];\n }\n }\n });\n}\n\n/**\n * The main commander application.\n */\nconst commanderApp = {\n /**\n * Modal DOM element instance.\n */\n mainModal: null,\n\n /**\n * Modal background layer DOM element.\n */\n mainModalBackLayer: null,\n\n /**\n * Input field element.\n */\n mainModalCommand: null,\n\n /**\n * Stores all list item elements.\n */\n liSet: null,\n\n /**\n * Flag to check if the modal is open.\n */\n isShow: false,\n\n /**\n * Stores the response JSON.\n */\n json: '',\n\n /**\n * Render the UI.\n */\n render() {\n let timer = 0;\n Log.debug('Rendering UI');\n\n // Create the modal HTML.\n const modalHtml = `\n
`;\n\n if (item.haschildren) {\n item.children.forEach((child) => {\n html += this.renderMenuItems(child, fullName);\n });\n }\n\n return html;\n },\n\n /**\n * Show the modal.\n */\n show() {\n this.mainModal.style.display = 'block';\n this.mainModalBackLayer.style.display = 'block';\n this.isShow = true;\n\n // Focus on the search field.\n this.mainModalCommand.focus();\n },\n\n /**\n * Hide the modal.\n */\n hide() {\n this.mainModal.style.display = 'none';\n this.mainModalBackLayer.style.display = 'none';\n this.isShow = false;\n },\n\n /**\n * Set the modal height to 50% of the viewport.\n */\n setHeight() {\n const height = Math.round(window.innerHeight / 2);\n this.mainModal.style.height = `${height}px`;\n const bodyDiv = this.mainModal.querySelector('.local_commander-body div');\n if (bodyDiv) {\n bodyDiv.style.height = `${height - 100}px`;\n }\n },\n\n /**\n * Remove highlights from text nodes.\n * @param {Node} node\n */\n removeHighlight(node) {\n node.innerHTML = node.textContent;\n },\n};\n\n/**\n * Initialize the module.\n * @param {object} params\n */\nfunction init(params) {\n // Set the options.\n setOptions(params);\n\n // Wait for the DOM to be fully loaded.\n document.addEventListener('DOMContentLoaded', () => {\n Log.debug('DOM fully loaded - initializing commanderApp');\n Log.debug(commanderAppOptions);\n commanderApp.start();\n });\n}\n\nexport default {\n init,\n};\n"],"names":["ESCAPE","ENTER","ARROWUP","ARROWDOWN","commanderAppOptions","courseid","keys","commanderApp","mainModal","mainModalBackLayer","mainModalCommand","liSet","isShow","json","render","timer","debug","modalHtml","M","util","get_string","document","body","insertAdjacentHTML","getElementById","setHeight","addEventListener","hide","e","keyboardCode","keyCode","which","includes","clearTimeout","setTimeout","search","this","value","loadMenu","start","window","preventDefault","goToCommand","arrowUp","arrowDown","toString","target","tagName","toUpperCase","isContentEditable","show","highlightWord","node","word","nodeType","Node","TEXT_NODE","pos","data","indexOf","spannode","createElement","className","middlebit","splitText","length","middleclone","cloneNode","appendChild","parentNode","replaceChild","ELEMENT_NODE","childNodes","forEach","child","activeItem","querySelector","prevItem","classList","remove","previousElementSibling","style","display","add","scrollToActiveItem","nextItem","nextElementSibling","lastVisibleItem","Array","from","querySelectorAll","reverse","find","item","container","scrollTop","offsetTop","activeLink","link","getAttribute","location","href","fetch","cfg","wwwroot","method","credentials","then","response","setMenu","catch","alert","listItems","li","span","removeHighlight","wordUpper","firstHighlighted","html","renderMenuItems","courseadmin","admin","innerHTML","parentName","name","fullName","haschildren","children","focus","height","Math","round","innerHeight","bodyDiv","textContent","init","params","options","Object","key","hasOwnProperty","vartype","Boolean","Number","String"],"mappings":"mXAsBMA,OAAS,GACTC,MAAQ,GACRC,QAAU,GACVC,UAAY,GAKZC,oBAAsB,CACxBC,SAAU,GACVC,KAAM,UA2BJC,aAAe,CAIjBC,UAAW,KAKXC,mBAAoB,KAKpBC,iBAAkB,KAKlBC,MAAO,KAKPC,QAAQ,EAKRC,KAAM,GAKNC,aACQC,MAAQ,eACRC,MAAM,sBAGJC,0KAGYC,EAAEC,KAAKC,WAAW,YAAa,iTAMzBF,EAAEC,KAAKC,WAAW,yBAA0B,gHAMpEC,SAASC,KAAKC,mBAAmB,YAAaN,gBAGzCT,UAAYa,SAASG,eAAe,8BACpCf,mBAAqBY,SAASG,eAAe,mCAC7Cd,iBAAmBW,SAASG,eAAe,gCAG3CC,iBAGAhB,mBAAmBiB,iBAAiB,SAAS,UACzCC,eAIJjB,iBAAiBgB,iBAAiB,WAAYE,UACzCC,aAAeD,EAAEE,SAAWF,EAAEG,mBAChCf,8BAAuBa,eAEvB,CAAC7B,OAAQC,MAAOC,QAASC,WAAW6B,SAASH,6BAI7Cb,MAAM,aAEViB,aAAal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S,YAQ3Cd,gBAAgB/D,MACZA,KAAKsE,UAAYtE,KAAKkF,2BAoBf,CACXC,cAbUC,YAlbMC,QAAAA,QAobLD,OAnbXE,OAAOpI,KAAKF,qBAAqBqE,SAASkE,SAClCF,QAAQG,eAAeD,KAAM,OACvBE,eAAiBzI,oBAAoBuI,KAEvCvI,oBAAoBuI,KADR,YAAZE,QAC2BC,QAAQL,QAAQE,MACxB,WAAZE,QACoBE,OAAON,QAAQE,MACvB,WAAZE,QACoBG,OAAOP,QAAQE,MAEfF,QAAQE,SA4a/CtH,SAASK,iBAAiB,oBAAoB,kBACtCV,MAAM,6DACNA,MAAMZ,qBACVG,aAAagC"}
\ No newline at end of file
diff --git a/amd/build/settings.min.js b/amd/build/settings.min.js
index 82cb239..de22013 100644
--- a/amd/build/settings.min.js
+++ b/amd/build/settings.min.js
@@ -1,12 +1,12 @@
+define("local_commander/settings",["exports","core/str","core/notification","core/log"],(function(_exports,_str,_notification,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
- * Helper for keycodes
- *
- * Tested in Moodle 3.8
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @copyright 2019 MFreak.nl
- * @author Luuk Verhoeven
- **/
-define("local_commander/settings",["jquery","core/str","core/notification","core/log"],(function($,str,Notification,Log){const commanderSettings_init=function(){let $el=$("#id_s_local_commander_keys");0!==$el.length&&(str.get_string("js:keycode_help","local_commander").then((function(message){return $el.before('
'+message+"
"),message})).fail(Notification.exception),$(document).on("keydown",(function(e){if("INPUT"===e.target.tagName||"SELECT"===e.target.tagName||"TEXTAREA"===e.target.tagName||e.target.isContentEditable)return void Log.debug("Hide when we are in an editable element");let keyboardCode=e.keyCode||e.which;$("#key-monitor div").text("key = "+e.key+" | code = "+keyboardCode)})))};return{init:function(){$(document).ready((function(){Log.debug("ready() - setting local commander v4.4"),commanderSettings_init()}))}}}));
+ * Helper for keycodes
+ *
+ * Tested in Moodle 3.8
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @copyright 2019 MFreak.nl
+ * @author Luuk Verhoeven
+ **/function init(){const el=document.getElementById("id_s_local_commander_keys");el&&(_str.default.get_string("js:keycode_help","local_commander").then((message=>{el.insertAdjacentHTML("beforebegin",'\n
\n '.concat(message,"\n \n
\n "))})).catch(_notification.default.exception),document.addEventListener("keydown",(e=>{const tagName=e.target.tagName.toUpperCase();if("INPUT"===tagName||"SELECT"===tagName||"TEXTAREA"===tagName||e.target.isContentEditable)return void _log.default.debug("Key event ignored in editable element");const keyboardCode=e.keyCode||e.which,monitorDiv=document.querySelector("#key-monitor div");monitorDiv&&(monitorDiv.textContent="key = ".concat(e.key," | code = ").concat(keyboardCode))})))}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_str=_interopRequireDefault(_str),_notification=_interopRequireDefault(_notification),_log=_interopRequireDefault(_log),document.addEventListener("DOMContentLoaded",(()=>{_log.default.debug("DOM fully loaded - initializing commander settings"),init()}));var _default={init:init};return _exports.default=_default,_exports.default}));
//# sourceMappingURL=settings.min.js.map
\ No newline at end of file
diff --git a/amd/build/settings.min.js.map b/amd/build/settings.min.js.map
index c47b9ce..9930949 100644
--- a/amd/build/settings.min.js.map
+++ b/amd/build/settings.min.js.map
@@ -1 +1 @@
-{"version":3,"file":"settings.min.js","sources":["../src/settings.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 * Helper for keycodes\n *\n * Tested in Moodle 3.8\n *\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @copyright 2019 MFreak.nl\n * @author Luuk Verhoeven\n **/\n/* eslint-disable no-invalid-this */\ndefine(['jquery', 'core/str', 'core/notification', 'core/log'],\n function($, str, Notification, Log) {\n 'use strict';\n\n /**\n * commanderSettings\n */\n const commanderSettings = {\n\n /**\n * Init\n */\n init: function() {\n let $el = $('#id_s_local_commander_keys');\n\n if ($el.length === 0) {\n return;\n }\n\n str.get_string('js:keycode_help', 'local_commander').then(function(message) {\n $el.before('
' + message + '
');\n return message;\n }).fail(Notification.exception);\n\n $(document).on('keydown', function(e) {\n\n if (e.target.tagName === 'INPUT' || e.target.tagName === 'SELECT'\n || e.target.tagName === 'TEXTAREA' || e.target.isContentEditable) {\n Log.debug('Hide when we are in an editable element');\n return;\n }\n\n let keyboardCode = e.keyCode || e.which;\n $('#key-monitor div').text('key = ' + e.key + ' | code = ' + keyboardCode);\n });\n }\n };\n\n return {\n\n /**\n * Called from Moodle.\n */\n init: function() {\n\n /**\n * Wait for jQuery\n */\n $(document).ready(function() {\n Log.debug('ready() - setting local commander v4.4');\n commanderSettings.init();\n });\n }\n };\n});\n"],"names":["define","$","str","Notification","Log","commanderSettings","$el","length","get_string","then","message","before","fail","exception","document","on","e","target","tagName","isContentEditable","debug","keyboardCode","keyCode","which","text","key","init","ready"],"mappings":";;;;;;;;;AAyBAA,kCAAO,CAAC,SAAU,WAAY,oBAAqB,aAC/C,SAASC,EAAGC,IAAKC,aAAcC,WAMzBC,uBAKI,eACEC,IAAML,EAAE,8BAEO,IAAfK,IAAIC,SAIRL,IAAIM,WAAW,kBAAmB,mBAAmBC,MAAK,SAASC,gBAC/DJ,IAAIK,OAAO,qDAAuDD,QAAU,yBACrEA,WACRE,KAAKT,aAAaU,WAErBZ,EAAEa,UAAUC,GAAG,WAAW,SAASC,MAEN,UAArBA,EAAEC,OAAOC,SAA4C,WAArBF,EAAEC,OAAOC,SACjB,aAArBF,EAAEC,OAAOC,SAA0BF,EAAEC,OAAOE,8BAC/Cf,IAAIgB,MAAM,+CAIVC,aAAeL,EAAEM,SAAWN,EAAEO,MAClCtB,EAAE,oBAAoBuB,KAAK,SAAWR,EAAES,IAAM,aAAeJ,yBAKlE,CAKHK,KAAM,WAKFzB,EAAEa,UAAUa,OAAM,WACdvB,IAAIgB,MAAM,0CACVf"}
\ No newline at end of file
+{"version":3,"file":"settings.min.js","sources":["../src/settings.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 * Helper for keycodes\n *\n * Tested in Moodle 3.8\n *\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @copyright 2019 MFreak.nl\n * @author Luuk Verhoeven\n **/\n\nimport str from 'core/str';\nimport Notification from 'core/notification';\nimport Log from 'core/log';\n\n/**\n * Initialize the commander settings.\n */\nfunction init() {\n const el = document.getElementById('id_s_local_commander_keys');\n\n if (!el) {\n return;\n }\n\n str.get_string('js:keycode_help', 'local_commander')\n .then((message) => {\n el.insertAdjacentHTML('beforebegin', `\n
\n ${message}\n \n
\n `);\n })\n .catch(Notification.exception);\n\n document.addEventListener('keydown', (e) => {\n const tagName = e.target.tagName.toUpperCase();\n\n if (\n tagName === 'INPUT' ||\n tagName === 'SELECT' ||\n tagName === 'TEXTAREA' ||\n e.target.isContentEditable\n ) {\n Log.debug('Key event ignored in editable element');\n return;\n }\n\n const keyboardCode = e.keyCode || e.which;\n const monitorDiv = document.querySelector('#key-monitor div');\n if (monitorDiv) {\n monitorDiv.textContent = `key = ${e.key} | code = ${keyboardCode}`;\n }\n });\n}\n\ndocument.addEventListener('DOMContentLoaded', () => {\n Log.debug('DOM fully loaded - initializing commander settings');\n init();\n});\n\nexport default {\n init,\n};\n"],"names":["init","el","document","getElementById","get_string","then","message","insertAdjacentHTML","catch","Notification","exception","addEventListener","e","tagName","target","toUpperCase","isContentEditable","debug","keyboardCode","keyCode","which","monitorDiv","querySelector","textContent","key"],"mappings":";;;;;;;;;eAgCSA,aACCC,GAAKC,SAASC,eAAe,6BAE9BF,kBAIDG,WAAW,kBAAmB,mBAC7BC,MAAMC,UACHL,GAAGM,mBAAmB,kHAETD,2FAKhBE,MAAMC,sBAAaC,WAExBR,SAASS,iBAAiB,WAAYC,UAC5BC,QAAUD,EAAEE,OAAOD,QAAQE,iBAGjB,UAAZF,SACY,WAAZA,SACY,aAAZA,SACAD,EAAEE,OAAOE,2CAELC,MAAM,+CAIRC,aAAeN,EAAEO,SAAWP,EAAEQ,MAC9BC,WAAanB,SAASoB,cAAc,oBACtCD,aACAA,WAAWE,4BAAuBX,EAAEY,yBAAgBN,2NAKhEhB,SAASS,iBAAiB,oBAAoB,kBACtCM,MAAM,sDACVjB,uBAGW,CACXA,KAAAA"}
\ No newline at end of file
diff --git a/amd/src/commander.js b/amd/src/commander.js
index 3303e82..0183446 100644
--- a/amd/src/commander.js
+++ b/amd/src/commander.js
@@ -13,510 +13,476 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+// Initialize the module with imports.
+import notification from 'core/notification';
+import Log from 'core/log';
+
+/**
+ * Keyboard key codes.
+ */
+const ESCAPE = 27;
+const ENTER = 13;
+const ARROWUP = 38;
+const ARROWDOWN = 40;
+
/**
- * JS to the popup and interact with it.
- *
- *
- * Tested in Moodle 3.8
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @copyright 2018 MFreak.nl
- * @author Luuk Verhoeven
- **/
-/* eslint-disable no-invalid-this */
-define(['jquery', 'core/notification', 'core/log'], function($, notification, Log) {
- 'use strict';
-
- // Keyboard codes.
- var ESCAPE = 27,
- ENTER = 13,
- ARROWUP = 38,
- ARROWDOWN = 40;
+ * Options we can set from AMD.
+ */
+const commanderAppOptions = {
+ courseid: '',
+ keys: [],
+};
+
+/**
+ * Set options based on provided parameters.
+ * @param {object} options
+ */
+function setOptions(options) {
+ Object.keys(commanderAppOptions).forEach((key) => {
+ if (options.hasOwnProperty(key)) {
+ const vartype = typeof commanderAppOptions[key];
+ if (vartype === 'boolean') {
+ commanderAppOptions[key] = Boolean(options[key]);
+ } else if (vartype === 'number') {
+ commanderAppOptions[key] = Number(options[key]);
+ } else if (vartype === 'string') {
+ commanderAppOptions[key] = String(options[key]);
+ } else {
+ commanderAppOptions[key] = options[key];
+ }
+ }
+ });
+}
+/**
+ * The main commander application.
+ */
+const commanderApp = {
/**
- * scroll to element.
- *
- * @param {string} elem
- * @param {int} speed
- * @returns {$}
+ * Modal DOM element instance.
*/
- $.fn.scrollTo = function(elem, speed) {
- $(this).stop().animate({
- scrollTop: $(this).scrollTop() - $(this).offset().top + $(elem).offset().top - 10
- }, speed == undefined ? 1000 : speed);
- return this;
- };
+ mainModal: null,
/**
- * Options we can set from amd.
- * @type {{selector: string, blockid: number}}
+ * Modal background layer DOM element.
*/
- var commanderAppOptions = {
- courseid: '',
- keys: [],
- };
+ mainModalBackLayer: null,
/**
- * Set options base on listed options
- * @param {object} options
+ * Input field element.
*/
- var setOptions = function(options) {
- "use strict";
- var key, vartype;
- for (key in commanderAppOptions) {
- if (commanderAppOptions.hasOwnProperty(key) && options.hasOwnProperty(key)) {
-
- // Casting to prevent errors.
- vartype = typeof commanderAppOptions[key];
- if (vartype === "boolean") {
- commanderAppOptions[key] = Boolean(options[key]);
- } else if (vartype === 'number') {
- commanderAppOptions[key] = Number(options[key]);
- } else if (vartype === 'string') {
- commanderAppOptions[key] = String(options[key]);
- } else {
- commanderAppOptions[key] = options[key];
- }
- }
- }
- };
+ mainModalCommand: null,
/**
- * Commander plugin.
- * @type {{}}
+ * Stores all list item elements.
*/
- const commanderApp = {
-
- /**
- * Modal jQuery element instance.
- */
- $mainModal: false,
-
- /**
- * Modal BG jQuery element instance.
- */
- $mainModalBackLayer: false,
-
- /**
- * Input field
- */
- $mainModalCommand: false,
-
- /**
- * Stores all li elements
- */
- $liSet: false,
-
- /**
- * Flag to check if modal is open.
- */
- isShow: false,
-
- /**
- * Save response
- */
- json: '',
-
- /**
- * Render UI.
- */
- render: function() {
- "use strict";
- var timer = 0;
- Log.debug('render UI');
-
- // @TODO we should use mustache.
- $('body').append('