From cadca4c787474a140bce094ae529c99a4f1e6816 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Sun, 25 Aug 2024 21:03:16 +0200 Subject: [PATCH] Update for AMD remove console.log --- amd/build/commander.min.js | 15 ++++++-- amd/build/commander.min.js.map | 2 +- amd/build/settings.min.js | 14 ++++++-- amd/build/settings.min.js.map | 2 +- amd/src/commander.js | 66 ++++++++++++++-------------------- amd/src/settings.js | 37 +++++-------------- 6 files changed, 63 insertions(+), 73 deletions(-) diff --git a/amd/build/commander.min.js b/amd/build/commander.min.js index 1fd4c3b..8c053d1 100644 --- a/amd/build/commander.min.js +++ b/amd/build/commander.min.js @@ -1,2 +1,13 @@ -function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("local_commander/commander",["jquery","core/notification"],function(a,b){'use strict';a.fn.scrollTo=function(b,c){a(this).stop().animate({scrollTop:a(this).scrollTop()-a(this).offset().top+a(b).offset().top-10},c==void 0?1e3:c);return this};var c={courseid:"",keys:[]},d=function(a){var b,d;for(b in c){if(c.hasOwnProperty(b)&&a.hasOwnProperty(b)){d=_typeof(c[b]);if("boolean"===d){c[b]=!!a[b]}else if("number"===d){c[b]=+a[b]}else if("string"===d){c[b]=a[b]+""}else{c[b]=a[b]}}}},f={$mainModal:!1,$mainModalBackLayer:!1,$mainModalCommand:!1,$liSet:!1,isShow:!1,json:"",log:function log(){try{console.log.apply(console,arguments)}catch(a){throw a}},render:function render(){var b=0;f.log("render UI");a("body").append("

"+M.util.get_string("js:header","local_commander")+"

");f.$mainModal=a("#local_commander_modal");f.$mainModalBackLayer=a("#local_commander_back_layer");f.$mainModalCommand=a("#local_commander_command");f.setHeight();f.$mainModalBackLayer.on("click",function(){f.hide()});f.$mainModalCommand.on("keydown",function(a){var c=a.keyCode||a.which;f.log("Code pressed:",c);switch(c){case 27:case 13:case 38:case 40:return;}f.log("Searching");clearTimeout(b);b=setTimeout(function(){f.search(f.$mainModalCommand.val())},100)});if(""===f.json){f.loadMenu()}},start:function start(){f.$mainModal=a("#local_commander_modal");a(window).on("keydown",function(a){var b=a.keyCode||a.which;f.log("Code pressed:",b);f.log("Trigger keys:",c.keys);f.log("Commander is visible:",f.isShow);if(f.isShow){switch(b){case 27:f.hide();break;case 13:a.preventDefault();f.goToCommand();break;case 38:a.preventDefault();f.arrowUp();break;case 40:a.preventDefault();f.arrowDown();break;}return}if(-1!==c.keys.indexOf(b.toString())){f.log("Commander keyboard key triggered");if("INPUT"==a.target.tagName||"SELECT"==a.target.tagName||"TEXTAREA"==a.target.tagName||a.target.isContentEditable){f.log("Hide when we are in an editable element");return}a.preventDefault();if(0==f.$mainModal.length){f.render()}f.log("Open commander.");if(f.isShow){f.hide()}else{f.show()}}})},highlightWord:function highlightWord(a,b){if(3==a.nodeType){var c=a.data.toUpperCase().indexOf(b);if(0<=c){var d=document.createElement("span");d.className="highlight";d.style.backgroundColor="#f4bd21";var e=a.splitText(c),g=e.cloneNode(!0);d.appendChild(g);e.parentNode.replaceChild(d,e)}}else if(1==a.nodeType&&a.childNodes){for(var h=0;h";f.$mainModal.find(".local_commander-body").append(b);f.$liSet=a(".local_commander-body ul")},renderMenuItems:function renderMenuItems(b,c,d){var e="";if(!b.name){return e}if(!d){d=""}else{d+=" → "}e+="
  • ";if(b.name){e+=""+d+b.name+""}if(b.haschildren){a.each(b.children,function(a,g){e+=f.renderMenuItems(g,c+1,d+b.name)})}e+="
  • ";return e},show:function show(){f.$mainModal.show();f.$mainModalBackLayer.show();f.isShow=!0;f.$mainModalCommand.focus()},hide:function hide(){f.$mainModal.hide();f.$mainModalBackLayer.hide();f.isShow=!1},setHeight:function setHeight(){var b=Math.round(a(window).height()/2);f.$mainModal.height(b);a(".local_commander-body div").height(b-100)},removeHighlight:function removeHighlight(b){a(b).html(a(b).text())}};return{init:function init(b){d(b);a(document).ready(function(){f.log("ready() - local commander v3.82",c);f.start()})}}}); -//# sourceMappingURL=commander.min.js.map +/** + * 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 + **/ +define("local_commander/commander",["jquery","core/notification","core/log"],(function($,notification,Log){$.fn.scrollTo=function(elem,speed){return $(this).stop().animate({scrollTop:$(this).scrollTop()-$(this).offset().top+$(elem).offset().top-10},null==speed?1e3:speed),this};var commanderAppOptions={courseid:"",keys:[]};const commanderApp={$mainModal:!1,$mainModalBackLayer:!1,$mainModalCommand:!1,$liSet:!1,isShow:!1,json:"",render:function(){var timer=0;Log.debug("render UI"),$("body").append('

    '+M.util.get_string("js:header","local_commander")+'

    '),commanderApp.$mainModal=$("#local_commander_modal"),commanderApp.$mainModalBackLayer=$("#local_commander_back_layer"),commanderApp.$mainModalCommand=$("#local_commander_command"),commanderApp.setHeight(),commanderApp.$mainModalBackLayer.on("click",(function(){commanderApp.hide()})),commanderApp.$mainModalCommand.on("keydown",(function(e){var keyboardCode=e.keyCode||e.which;switch(Log.debug("Code pressed:"+keyboardCode),keyboardCode){case 27:case 13:case 38:case 40:return}Log.debug("Searching"),clearTimeout(timer),timer=setTimeout((function(){commanderApp.search(commanderApp.$mainModalCommand.val())}),100)})),""===commanderApp.json&&commanderApp.loadMenu()},start:function(){commanderApp.$mainModal=$("#local_commander_modal"),$(window).on("keydown",(function(e){var keyboardCode=e.keyCode||e.which;if(Log.debug("Code pressed:",keyboardCode),Log.debug("Trigger keys:",commanderAppOptions.keys),Log.debug("Commander is visible:",commanderApp.isShow),commanderApp.isShow)switch(keyboardCode){case 27:commanderApp.hide();break;case 13:e.preventDefault(),commanderApp.goToCommand();break;case 38:e.preventDefault(),commanderApp.arrowUp();break;case 40:e.preventDefault(),commanderApp.arrowDown()}else if(-1!==commanderAppOptions.keys.indexOf(keyboardCode.toString())){if(Log.debug("Commander keyboard key triggered"),"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");e.preventDefault(),0==commanderApp.$mainModal.length&&commanderApp.render(),Log.debug("Open commander."),commanderApp.isShow?commanderApp.hide():commanderApp.show()}}))},highlightWord:function(node,word){if(3==node.nodeType){var pos=node.data.toUpperCase().indexOf(word);if(pos>=0){var spannode=document.createElement("span");spannode.className="highlight",spannode.style.backgroundColor="#f4bd21";var middlebit=node.splitText(pos),middleclone=middlebit.cloneNode(!0);spannode.appendChild(middleclone),middlebit.parentNode.replaceChild(spannode,middlebit)}}else if(1==node.nodeType&&node.childNodes)for(var i=0;i0&&(Log.debug("Has course param."),html+=commanderApp.renderMenuItems(commanderApp.json.courseadmin,1)),html+=commanderApp.renderMenuItems(commanderApp.json.admin,1),html+="",commanderApp.$mainModal.find(".local_commander-body").append(html),commanderApp.$liSet=$(".local_commander-body ul")},renderMenuItems:function(child,depth,parentName){var html="";return child.name?(parentName?parentName+=" → ":parentName="",html+="
  • ",child.name&&(html+=''+parentName+child.name+""),child.haschildren&&$.each(child.children,(function(i,el){html+=commanderApp.renderMenuItems(el,depth+1,parentName+child.name)})),html+="
  • "):html},show:function(){commanderApp.$mainModal.show(),commanderApp.$mainModalBackLayer.show(),commanderApp.isShow=!0,commanderApp.$mainModalCommand.focus()},hide:function(){commanderApp.$mainModal.hide(),commanderApp.$mainModalBackLayer.hide(),commanderApp.isShow=!1},setHeight:function(){var height=Math.round($(window).height()/2);commanderApp.$mainModal.height(height),$(".local_commander-body div").height(height-100)},removeHighlight:function(node){$(node).html($(node).text())}};return{init:function(params){!function(options){var key,vartype;for(key in commanderAppOptions)commanderAppOptions.hasOwnProperty(key)&&options.hasOwnProperty(key)&&(vartype=typeof commanderAppOptions[key],commanderAppOptions[key]="boolean"===vartype?Boolean(options[key]):"number"===vartype?Number(options[key]):"string"===vartype?String(options[key]):options[key])}(params),$(document).ready((function(){Log.debug("ready() - local commander v4.4"),Log.debug(commanderAppOptions),commanderApp.start()}))}}})); + +//# 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 ae49c5d..122631a 100644 --- a/amd/build/commander.min.js.map +++ b/amd/build/commander.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/commander.js"],"names":["define","$","notification","fn","scrollTo","elem","speed","stop","animate","scrollTop","offset","top","commanderAppOptions","courseid","keys","setOptions","options","key","vartype","hasOwnProperty","commanderApp","$mainModal","$mainModalBackLayer","$mainModalCommand","$liSet","isShow","json","log","console","apply","arguments","exc","render","timer","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","ready"],"mappings":"mSA6BAA,OAAM,6BAAC,CAAC,QAAD,CAAW,mBAAX,CAAD,CAAkC,SAASC,CAAT,CAAYC,CAAZ,CAA0B,CAC9D,aASAD,CAAC,CAACE,EAAF,CAAKC,QAAL,CAAgB,SAASC,CAAT,CAAeC,CAAf,CAAsB,CAClCL,CAAC,CAAC,IAAD,CAAD,CAAQM,IAAR,GAAeC,OAAf,CAAuB,CACnBC,SAAS,CAAER,CAAC,CAAC,IAAD,CAAD,CAAQQ,SAAR,GAAsBR,CAAC,CAAC,IAAD,CAAD,CAAQS,MAAR,GAAiBC,GAAvC,C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hac,CAsaff,eAAe,CAAE,yBAAS/C,CAAT,CAAe,CAC5B/D,CAAC,CAAC+D,CAAD,CAAD,CAAQmD,IAAR,CAAalH,CAAC,CAAC+D,CAAD,CAAD,CAAQiE,IAAR,EAAb,CACH,CAxac,CAvD2C,CAke9D,MAAO,CAMHC,IAAI,CAAE,cAASC,CAAT,CAAiB,CAKnBpH,CAAU,CAACoH,CAAD,CAAV,CAKAlI,CAAC,CAACsE,QAAD,CAAD,CAAY6D,KAAZ,CAAkB,UAAW,CACzBhH,CAAY,CAACO,GAAb,CAAiB,iCAAjB,CAAoDf,CAApD,EACAQ,CAAY,CAAC8B,KAAb,EACH,CAHD,CAIH,CApBE,CAsBV,CAxfK,CAAN","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 *\n * @package local_commander\n * @copyright 2018 MFreak.nl\n * @author Luuk Verhoeven\n **/\n/* eslint no-console: [\"error\", { allow: [\"warn\", \"error\" , \"log\"] }] */\n/* eslint-disable no-invalid-this */\ndefine(['jquery', 'core/notification'], function($, notification) {\n 'use strict';\n\n // Keyboard codes.\n var ESCAPE = 27,\n ENTER = 13,\n ARROWUP = 38,\n ARROWDOWN = 40;\n\n // Fix scrolling.\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 var 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 * Internal logging\n * @param {*} val\n */\n log: function() {\n \"use strict\";\n\n // Check if we can the log.\n try {\n // TODO Only if debugging enabled in cfg.\n console.log.apply(console, arguments);\n } catch (exc) {\n throw exc;\n }\n },\n\n /**\n * Render UI.\n */\n render: function() {\n \"use strict\";\n var timer = 0;\n commanderApp.log('render UI');\n\n // @TODO we should use mustache.\n $('body').append('
    ' +\n '

    ' + M.util.get_string('js:header', 'local_commander') + '

    ' +\n '
    ' +\n '
    ' +\n '' +\n '
    ');\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 commanderApp.log('Code pressed:', keyboardCode);\n\n switch (keyboardCode) {\n case ESCAPE:\n case ENTER:\n case ARROWUP:\n case ARROWDOWN:\n return;\n }\n\n commanderApp.log('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 commanderApp.log('Code pressed:', keyboardCode);\n commanderApp.log('Trigger keys:', commanderAppOptions.keys);\n commanderApp.log('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 commanderApp.log('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 commanderApp.log('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 commanderApp.log('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 commanderApp.log('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 commanderApp.log('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 commanderApp.log('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 commanderApp.log(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 commanderApp.log('setMenu() ');\n\n var html = '
      ';\n\n // Only do things when needed.\n if (commanderAppOptions.courseid > 0) {\n commanderApp.log('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 commanderApp.log('ready() - local commander v3.82', commanderAppOptions);\n commanderApp.start();\n });\n }\n };\n});"],"file":"commander.min.js"} \ 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/**\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 '

    ' + M.util.get_string('js:header', 'local_commander') + '

    ' +\n '
    ' +\n '
    ' +\n '' +\n '
    ');\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,0BAE5BA,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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 diff --git a/amd/build/settings.min.js b/amd/build/settings.min.js index f5d5b66..82cb239 100644 --- a/amd/build/settings.min.js +++ b/amd/build/settings.min.js @@ -1,2 +1,12 @@ -define ("local_commander/settings",["jquery","core/str","core/notification"],function(a,b,c){'use strict';var d={log:function log(){try{console.log.apply(console,arguments)}catch(a){throw a}},init:function init(){var e=a("#id_s_local_commander_keys");if(0===e.length){return}b.get_string("js:keycode_help","local_commander").then(function(a){e.before("
    "+a+"
    ");return a}).fail(c.exception);a(document).on("keydown",function(b){if("INPUT"==b.target.tagName||"SELECT"==b.target.tagName||"TEXTAREA"==b.target.tagName||b.target.isContentEditable){d.log("Hide when we are in an editable element");return}var c=b.keyCode||b.which;a("#key-monitor div").text("key = "+b.key+" | code = "+c)})}};return{init:function init(){a(document).ready(function(){d.log("ready() - setting local commander v3.82");d.init()})}}}); -//# sourceMappingURL=settings.min.js.map +/** + * 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()}))}}})); + +//# 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 6587ab7..c47b9ce 100644 --- a/amd/build/settings.min.js.map +++ b/amd/build/settings.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/settings.js"],"names":["define","$","str","Notification","commanderSettings","log","console","apply","arguments","exc","init","$el","length","get_string","then","message","before","fail","exception","document","on","e","target","tagName","isContentEditable","keyboardCode","keyCode","which","text","key","ready"],"mappings":"AA4BAA,OAAM,4BAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,mBAAvB,CAAD,CAA8C,SAASC,CAAT,CAAYC,CAAZ,CAAiBC,CAAjB,CAA+B,CAC/E,aAMA,GAAIC,CAAAA,CAAiB,CAAG,CAMpBC,GAAG,CAAE,cAAW,CAIZ,GAAI,CAEAC,OAAO,CAACD,GAAR,CAAYE,KAAZ,CAAkBD,OAAlB,CAA2BE,SAA3B,CACH,CAAC,MAAOC,CAAP,CAAY,CACV,KAAMA,CAAAA,CACT,CACJ,CAhBmB,CAqBpBC,IAAI,CAAE,eAAW,CACb,GAAIC,CAAAA,CAAG,CAAGV,CAAC,CAAC,4BAAD,CAAX,CAEA,GAAmB,CAAf,GAAAU,CAAG,CAACC,MAAR,CAAsB,CAClB,MACH,CAEDV,CAAG,CAACW,UAAJ,CAAe,iBAAf,CAAkC,iBAAlC,EAAqDC,IAArD,CAA0D,SAASC,CAAT,CAAkB,CACxEJ,CAAG,CAACK,MAAJ,CAAW,yDAAuDD,CAAvD,CAAiE,uBAA5E,EACA,MAAOA,CAAAA,CACV,CAHD,EAGGE,IAHH,CAGQd,CAAY,CAACe,SAHrB,EAKAjB,CAAC,CAACkB,QAAD,CAAD,CAAYC,EAAZ,CAAe,SAAf,CAA0B,SAASC,CAAT,CAAY,CAElC,GAAwB,OAApB,EAAAA,CAAC,CAACC,MAAF,CAASC,OAAT,EAAmD,QAApB,EAAAF,CAAC,CAACC,MAAF,CAASC,OAAxC,EACuB,UAApB,EAAAF,CAAC,CAACC,MAAF,CAASC,OADZ,EACqCF,CAAC,CAACC,MAAF,CAASE,iBADlD,CACqE,CACjEpB,CAAiB,CAACC,GAAlB,CAAsB,yCAAtB,EACA,MACH,CAED,GAAIoB,CAAAA,CAAY,CAAGJ,CAAC,CAACK,OAAF,EAAaL,CAAC,CAACM,KAAlC,CACA1B,CAAC,CAAC,kBAAD,CAAD,CAAsB2B,IAAtB,CAA2B,SAAWP,CAAC,CAACQ,GAAb,CAAmB,YAAnB,CAAkCJ,CAA7D,CACH,CAVD,CAWH,CA5CmB,CAAxB,CA+CA,MAAO,CAKHf,IAAI,CAAE,eAAW,CAKbT,CAAC,CAACkB,QAAD,CAAD,CAAYW,KAAZ,CAAkB,UAAW,CACzB1B,CAAiB,CAACC,GAAlB,CAAsB,yCAAtB,EACAD,CAAiB,CAACM,IAAlB,EACH,CAHD,CAIH,CAdE,CAgBV,CAtEK,CAAN","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 *\n * @package local_commander\n * @copyright 2019 MFreak.nl\n * @author Luuk Verhoeven\n **/\n/* eslint no-console: [\"error\", { allow: [\"warn\", \"error\" , \"log\"] }] */\n/* eslint-disable no-invalid-this */\ndefine(['jquery', 'core/str', 'core/notification'], function($, str, Notification) {\n 'use strict';\n\n /**\n *\n * @type {{}}\n */\n var commanderSettings = {\n\n /**\n * Internal logging\n * @param {*} val\n */\n log: function() {\n \"use strict\";\n\n // Check if we can show the log.\n try {\n // TODO Only show if debugging enabled in cfg.\n console.log.apply(console, arguments);\n } catch (exc) {\n throw exc;\n }\n },\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 commanderSettings.log('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 commanderSettings.log('ready() - setting local commander v3.82');\n commanderSettings.init();\n });\n }\n };\n});"],"file":"settings.min.js"} \ 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/* 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 diff --git a/amd/src/commander.js b/amd/src/commander.js index 97359b0..3303e82 100644 --- a/amd/src/commander.js +++ b/amd/src/commander.js @@ -20,14 +20,11 @@ * Tested in Moodle 3.8 * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * - * @package local_commander * @copyright 2018 MFreak.nl * @author Luuk Verhoeven **/ -/* eslint no-console: ["error", { allow: ["warn", "error" , "log"] }] */ /* eslint-disable no-invalid-this */ -define(['jquery', 'core/notification'], function($, notification) { +define(['jquery', 'core/notification', 'core/log'], function($, notification, Log) { 'use strict'; // Keyboard codes. @@ -36,7 +33,13 @@ define(['jquery', 'core/notification'], function($, notification) { ARROWUP = 38, ARROWDOWN = 40; - // Fix scrolling. + /** + * scroll to element. + * + * @param {string} elem + * @param {int} speed + * @returns {$} + */ $.fn.scrollTo = function(elem, speed) { $(this).stop().animate({ scrollTop: $(this).scrollTop() - $(this).offset().top + $(elem).offset().top - 10 @@ -82,7 +85,7 @@ define(['jquery', 'core/notification'], function($, notification) { * Commander plugin. * @type {{}} */ - var commanderApp = { + const commanderApp = { /** * Modal jQuery element instance. @@ -114,29 +117,13 @@ define(['jquery', 'core/notification'], function($, notification) { */ json: '', - /** - * Internal logging - * @param {*} val - */ - log: function() { - "use strict"; - - // Check if we can the log. - try { - // TODO Only if debugging enabled in cfg. - console.log.apply(console, arguments); - } catch (exc) { - throw exc; - } - }, - /** * Render UI. */ render: function() { "use strict"; var timer = 0; - commanderApp.log('render UI'); + Log.debug('render UI'); // @TODO we should use mustache. $('body').append('
    ' + @@ -161,7 +148,7 @@ define(['jquery', 'core/notification'], function($, notification) { // Search set some timeout optimize speed. commanderApp.$mainModalCommand.on('keydown', function(e) { var keyboardCode = e.keyCode || e.which; - commanderApp.log('Code pressed:', keyboardCode); + Log.debug('Code pressed:' + keyboardCode); switch (keyboardCode) { case ESCAPE: @@ -171,7 +158,7 @@ define(['jquery', 'core/notification'], function($, notification) { return; } - commanderApp.log('Searching'); + Log.debug('Searching'); clearTimeout(timer); timer = setTimeout(function() { @@ -195,9 +182,9 @@ define(['jquery', 'core/notification'], function($, notification) { $(window).on('keydown', function(e) { var keyboardCode = e.keyCode || e.which; - commanderApp.log('Code pressed:', keyboardCode); - commanderApp.log('Trigger keys:', commanderAppOptions.keys); - commanderApp.log('Commander is visible:', commanderApp.isShow); + Log.debug('Code pressed:', keyboardCode); + Log.debug('Trigger keys:', commanderAppOptions.keys); + Log.debug('Commander is visible:', commanderApp.isShow); // Check for arrow keys. if (commanderApp.isShow) { @@ -226,12 +213,12 @@ define(['jquery', 'core/notification'], function($, notification) { if (commanderAppOptions.keys.indexOf(keyboardCode.toString()) !== -1) { - commanderApp.log('Commander keyboard key triggered'); + Log.debug('Commander keyboard key triggered'); // Validate we not triggered in an editable area. if (e.target.tagName == 'INPUT' || e.target.tagName == 'SELECT' || e.target.tagName == 'TEXTAREA' || e.target.isContentEditable) { - commanderApp.log('Hide when we are in an editable element'); + Log.debug('Hide when we are in an editable element'); return; } @@ -242,7 +229,7 @@ define(['jquery', 'core/notification'], function($, notification) { commanderApp.render(); } - commanderApp.log('Open commander.'); + Log.debug('Open commander.'); if (commanderApp.isShow) { commanderApp.hide(); @@ -283,7 +270,7 @@ define(['jquery', 'core/notification'], function($, notification) { * Action on keyboard arrow key UP. */ arrowUp: function() { - commanderApp.log('arrowUp'); + Log.debug('arrowUp'); var $el = $('#local_commander_modal ul li.active'), $prev = $el.closest("li").prevAll("li:visible").eq(0); @@ -305,7 +292,7 @@ define(['jquery', 'core/notification'], function($, notification) { * Action on keyboard arrow key DOWN. */ arrowDown: function() { - commanderApp.log('arrowDown'); + Log.debug('arrowDown'); var $el = $('#local_commander_modal ul li.active'), $next = $el.closest("li").nextAll("li:visible").eq(0); @@ -332,7 +319,7 @@ define(['jquery', 'core/notification'], function($, notification) { * The command that we need to execute. */ goToCommand: function() { - commanderApp.log('goToCommand'); + Log.debug('goToCommand'); // Check if there is a element selected. // Check if the element has link. // TODO maybe add way to execute other type of commands. @@ -360,7 +347,7 @@ define(['jquery', 'core/notification'], function($, notification) { }, dataType: "json", }).done(function(response) { - commanderApp.log(response); + Log.debug(response); commanderApp.json = response; commanderApp.setMenu(); @@ -405,13 +392,13 @@ define(['jquery', 'core/notification'], function($, notification) { */ setMenu: function() { "use strict"; - commanderApp.log('setMenu() '); + Log.debug('setMenu() '); var html = '
      '; // Only do things when needed. if (commanderAppOptions.courseid > 0) { - commanderApp.log('Has course param.'); + Log.debug('Has course param.'); html += commanderApp.renderMenuItems(commanderApp.json.courseadmin, 1); } @@ -526,9 +513,10 @@ define(['jquery', 'core/notification'], function($, notification) { * Wait for jQuery */ $(document).ready(function() { - commanderApp.log('ready() - local commander v3.82', commanderAppOptions); + Log.debug('ready() - local commander v4.4'); + Log.debug(commanderAppOptions); commanderApp.start(); }); } }; -}); \ No newline at end of file +}); diff --git a/amd/src/settings.js b/amd/src/settings.js index 2ca2059..94fb476 100644 --- a/amd/src/settings.js +++ b/amd/src/settings.js @@ -19,37 +19,18 @@ * Tested in Moodle 3.8 * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * - * @package local_commander * @copyright 2019 MFreak.nl * @author Luuk Verhoeven **/ -/* eslint no-console: ["error", { allow: ["warn", "error" , "log"] }] */ /* eslint-disable no-invalid-this */ -define(['jquery', 'core/str', 'core/notification'], function($, str, Notification) { +define(['jquery', 'core/str', 'core/notification', 'core/log'], + function($, str, Notification, Log) { 'use strict'; /** - * - * @type {{}} + * commanderSettings */ - var commanderSettings = { - - /** - * Internal logging - * @param {*} val - */ - log: function() { - "use strict"; - - // Check if we can show the log. - try { - // TODO Only show if debugging enabled in cfg. - console.log.apply(console, arguments); - } catch (exc) { - throw exc; - } - }, + const commanderSettings = { /** * Init @@ -68,9 +49,9 @@ define(['jquery', 'core/str', 'core/notification'], function($, str, Notificatio $(document).on('keydown', function(e) { - if (e.target.tagName == 'INPUT' || e.target.tagName == 'SELECT' - || e.target.tagName == 'TEXTAREA' || e.target.isContentEditable) { - commanderSettings.log('Hide when we are in an editable element'); + if (e.target.tagName === 'INPUT' || e.target.tagName === 'SELECT' + || e.target.tagName === 'TEXTAREA' || e.target.isContentEditable) { + Log.debug('Hide when we are in an editable element'); return; } @@ -91,9 +72,9 @@ define(['jquery', 'core/str', 'core/notification'], function($, str, Notificatio * Wait for jQuery */ $(document).ready(function() { - commanderSettings.log('ready() - setting local commander v3.82'); + Log.debug('ready() - setting local commander v4.4'); commanderSettings.init(); }); } }; -}); \ No newline at end of file +});