{"version":3,"file":"collapsenavdrawernodes.min.js","sources":["https:\/\/edujustic.justicia.es\/local\/boostnavigation\/amd\/src\/collapsenavdrawernodes.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 * Local plugin \"Boost navigation fumbling\" - JS code for collapsing nav drawer nodes\n *\n * @module local_boostnavigation\/collapsenavdrawernodes\n * @copyright 2017 Alexander Bias, Ulm University \n * @copyright 2017 Kathrin Osswald, Ulm University \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\ndefine(['jquery'], function($) {\n \"use strict\";\n\n \/**\n * Click handler to toggle the given nav node.\n * @param {Object} node The nav node which should be toggled.\n * @param {string} nodename The nav node's nodename.\n *\/\n function toggleClickHandler(node, nodename) {\n node.click(function(e) {\n \/\/ Prevent that the browser opens the node's default action link (if existing).\n e.preventDefault();\n\n \/\/ If the parent node is currently expanded.\n if (node.hasClass('localboostnavigationcollapsedparent') === false) {\n \/\/ Collapse the node.\n collapseNode(node, nodename);\n\n \/\/ If the parent node is currently collapsed.\n } else if (node.hasClass('localboostnavigationcollapsedparent') === true) {\n \/\/ Expand the node.\n expandNode(node, nodename);\n\n \/\/ If the parent node is configured to act as accordion.\n var accordionTarget = node.attr('data-localboostnavigation-accordion');\n if (typeof accordionTarget !== \"undefined\") {\n \/\/ Collapse all sibling parent nodes.\n $('.list-group-item.localboostnavigationcollapsibleparent[data-key^=\"' + accordionTarget + '\"]')\n .each(\/* @this *\/function() {\n \/\/ But not the node which has been clicked by the user.\n if ($(this).attr('data-key') !== node.attr('data-key')) {\n collapseNode($(this), $(this).attr('data-key'));\n }\n });\n }\n }\n });\n }\n\n \/**\n * Helper function to collapse the given nav node.\n * @param {Object} node The nav node which should be toggled.\n * @param {string} nodename The nav node's nodename.\n *\/\n function collapseNode(node, nodename) {\n \/\/ Set the localboostnavigationcollapsedchild class for all elements which have the nodename as their data-parent-key\n \/\/ attribute.\n $('.list-group-item[data-parent-key=' + nodename + ']').addClass('localboostnavigationcollapsedchild');\n \/\/ Set the localboostnavigationcollapsedparent class of the node itself.\n node.addClass('localboostnavigationcollapsedparent');\n \/\/ Change the aria-expanded attribute of the node itself to false.\n node.attr(\"aria-expanded\", \"0\");\n \/\/ Save this state to the user preferences.\n M.util.set_user_preference('local_boostnavigation-collapse_' + nodename + 'node', 1);\n }\n\n \/**\n * Helper function to expand the given nav node.\n * @param {Object} node The nav node which should be toggled.\n * @param {string} nodename The nav node's nodename.\n *\/\n function expandNode(node, nodename) {\n \/\/ Remove the localboostnavigationcollapsedchild class from all elements which have the nodename as their data-parent-key\n \/\/ attribute.\n $('.list-group-item[data-parent-key=' + nodename + ']').removeClass('localboostnavigationcollapsedchild');\n \/\/ Remove the localboostnavigationcollapsedparent class of the node itself.\n node.removeClass('localboostnavigationcollapsedparent');\n \/\/ Change the aria-expanded attribute of the node itself to true.\n node.attr(\"aria-expanded\", \"1\");\n \/\/ Save this state to the user preferences.\n M.util.set_user_preference('local_boostnavigation-collapse_' + nodename + 'node', 0);\n }\n\n \/**\n * Add aria-attributes to a parent node.\n * @param {Object} node The nav node which should get the aria-attributes.\n * @param {string} nodename The nav node's nodename.\n *\/\n function addAriaToParent(node, nodename) {\n \/\/ Add ids to the child nodes for referencing in aria-controls.\n \/\/ Initialize string variable to remember the child node ids.\n var ids = '';\n \/\/ Get the elements which have the nodename as their data-parent-key attribute.\n $('.list-group-item[data-parent-key=' + nodename + ']').each(function(index, element) {\n \/\/ Get its data-key attribute (which should be unique) to be used as id attribute.\n var id = $(element).attr('data-key');\n \/\/ Prefix the id attribute if it wasn't built by us.\n if (id.substring(0, 10) !== 'localboost') {\n id = 'localboostnavigation' + id;\n }\n \/\/ Set the id attribute.\n $(element).attr('id', id);\n \/\/ Remember the id attribute for later use.\n ids = ids + id + ' ';\n });\n\n \/\/ Add aria-controls attribute if we have ids to reference.\n if (ids !== '') {\n node.attr('aria-controls', ids.trim());\n }\n\n \/\/ Add aria-expanded attribute.\n \/\/ If the parent node is currently expanded.\n if (node.hasClass('localboostnavigationcollapsedparent') === false) {\n \/\/ Set the aria-expanded attribute of the node itself to false.\n node.attr('aria-expanded', '1');\n\n \/\/ If the parent node is currently collapsed.\n } else if (node.hasClass('localboostnavigationcollapsedparent') === true) {\n \/\/ Set the aria-expanded attribute of the node itself to true.\n node.attr('aria-expanded', '0');\n }\n }\n\n \/**\n * Add accessibility to a div node which doesn't behave like an a node.\n * @param {Object} node The nav node which should be made tabbable.\n *\/\n function tabbableDiv(node) {\n \/\/ Add tabindex attribute so that it will be respected by the browser when the user tabs through the page's elements.\n node.attr('tabindex', '0');\n\n \/\/ Also call the click handler when the user presses the Enter button.\n node.keydown(function(e) {\n if (e.which === 13) {\n e.currentTarget.click();\n }\n });\n\n \/\/ As we added a tabindex attribute, the element gets an element focus outline as soon as it's clicked, too.\n \/\/ Try to prevent this hereby.\n node.mousedown(function() {\n node.css('outline', 'none');\n });\n node.mouseup(function() {\n node.css('outline', '');\n node.blur();\n });\n }\n\n \/**\n * Init function of this AMD module which initializes the click handlers.\n * @param {string} nodename The nav node's nodename.\n *\/\n function initToggleNodes(nodename) {\n \/\/ Search node to be collapsible.\n var node = $('.list-group-item[data-key=\"' + nodename + '\"]');\n\n \/\/ Add a click handler to this node.\n toggleClickHandler(node, nodename);\n\n \/\/ Add aria-attributes to this node.\n addAriaToParent(node, nodename);\n\n \/\/ Make the mycourses node accessible (all other nodes are fine).\n if (nodename == 'mycourses') {\n tabbableDiv(node);\n }\n }\n\n \/**\n * Init function of this AMD module which marks the accordion nodes.\n * @param {string} nodename The nav node's nodename.\n *\/\n function initAccordionNodes(nodename) {\n \/\/ Mark node as accordion.\n $('.list-group-item.localboostnavigationcollapsibleparent[data-key^=\"' + nodename + '\"]')\n .attr('data-localboostnavigation-accordion', nodename);\n }\n\n return {\n init: function(toggleNodes, accordionNodes) {\n \/\/ Initialize toggle nodes.\n for (var i = 0, tLen = toggleNodes.length; i < tLen; i++) {\n initToggleNodes(toggleNodes[i]);\n }\n \/\/ Initialize accordion nodes.\n for (var j = 0, aLen = accordionNodes.length; j < aLen; j++) {\n initAccordionNodes(accordionNodes[j]);\n }\n }\n };\n});\n"],"names":["define","$","toggleClickHandler","node","nodename","click","e","preventDefault","hasClass","collapseNode","removeClass","attr","M","util","set_user_preference","expandNode","accordionTarget","each","this","addClass","initToggleNodes","ids","index","element","id","substring","trim","addAriaToParent","keydown","which","currentTarget","mousedown","css","mouseup","blur","tabbableDiv","init","toggleNodes","accordionNodes","i","tLen","length","j","aLen"],"mappings":";;;;;;;;AAwBAA,sDAAO,CAAC,WAAW,SAASC,YAQfC,mBAAmBC,KAAMC,UAC9BD,KAAKE,OAAM,SAASC,MAEhBA,EAAEC,kBAG2D,IAAzDJ,KAAKK,SAAS,uCAEdC,aAAaN,KAAMC,eAGhB,IAA6D,IAAzDD,KAAKK,SAAS,uCAAiD,WA0C9DL,KAAMC,UAGtBH,EAAE,oCAAsCG,SAAW,KAAKM,YAAY,sCAEpEP,KAAKO,YAAY,uCAEjBP,KAAKQ,KAAK,gBAAiB,KAE3BC,EAAEC,KAAKC,oBAAoB,kCAAoCV,SAAW,OAAQ,GAjD1EW,CAAWZ,KAAMC,cAGbY,gBAAkBb,KAAKQ,KAAK,4CACD,IAApBK,iBAEPf,EAAE,qEAAuEe,gBAAkB,MAClFC,MAAgB,WAEjBhB,EAAEiB,MAAMP,KAAK,cAAgBR,KAAKQ,KAAK,aACvCF,aAA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