Rev 1 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
{"version":3,"file":"page_global.min.js","sources":["../src/page_global.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 <http://www.gnu.org/licenses/>.\n\n/**\n * Provide global helper code to enhance page elements.\n *\n * @module core/page_global\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n
define(\n[\n 'jquery',\n 'core/custom_interaction_events',\n 'core/str',\n 'core/network'\n],\nfunction(\n $,\n CustomEvents,\n Str,\n Network\n) {\n\n /**\n * Add an event handler for dropdown menus that wish to show their active item\n * in the dropdown toggle element.\n *\n * By default the handler will add the \"active\" class to the selected dropdown\n * item and set it's text as the HTML for the dropdown toggle.\n *\n * The behaviour of this handler is controlled by adding data attributes to\n * the HTML and requires the typically Bootstrap dropdown markup.\n *\n * data-show-active-item - Add to the .dropdown-menu element to enable default\n * functionality.\n * data-skip-active-class - Add to the .dropdown-menu to prevent this code from\n * adding the active class to the dropdown items\n * data-active-item-text - Add to an element within the data-bs-toggle=\"dropdown\" el
ement\n * to use it as the active option text placeholder otherwise the\n * data-bs-toggle=\"dropdown\" element itself will be used.\n * data-active-item-button-aria-label-components - String components to set the aria\n * lable on the dropdown button. The string will be given the\n * active item text.\n */\n var initActionOptionDropdownHandler = function() {\n var body = $('body');\n\n // Ensure on load that the \"current\" item is always marked to ensure we make space for active item indicator.\n body.find('.dropdown-menu').each(function() {\n $(this).find('[aria-current=\"true\"]').addClass('dropdown-item-active');\n });\n\n CustomEvents.define(body, [CustomEvents.events.activate]);\n body.on(CustomEvents.events.activate, '[data-show-active-item]', function(e) {\n // The dropdown item that the user clicked on.\n
var option = $(e.target).closest('.dropdown-item');\n // The dropdown menu element.\n var menuContainer = option.closest('[data-show-active-item]');\n\n if (!option.hasClass('dropdown-item')) {\n // Ignore non Bootstrap dropdowns.\n return;\n }\n\n if (option.hasClass('active')) {\n // If it's already active then we don't need to do anything.\n return;\n }\n\n // Clear the active class from all other options.\n var dropdownItems = menuContainer.find('.dropdown-item');\n dropdownItems.removeClass(['active', 'dropdown-item-active']);\n dropdownItems.removeAttr('aria-current');\n\n if (!menuContainer.attr('data-skip-active-class')) {\n // Make this option active unless configured to ignore it.\n // Some code, for example the Bootstrap tabs, may want to handle\n // adding the active class
itself.\n option.addClass('active');\n }\n option.addClass('dropdown-item-active');\n\n // Update aria attribute for active item.\n option.attr('aria-current', true);\n\n var activeOptionText = option.text();\n var dropdownToggle = menuContainer.parent().find('[data-bs-toggle=\"dropdown\"]');\n var dropdownToggleText = dropdownToggle.find('[data-active-item-text]');\n\n if (dropdownToggleText.length) {\n // We have a specific placeholder for the active item text so\n // use that.\n dropdownToggleText.html(activeOptionText);\n } else {\n // Otherwise just replace all of the toggle text with the active item.\n dropdownToggle.html(activeOptionText);\n }\n\n var activeItemAriaLabelComponent = menuContainer.attr('data-active-item-button-aria-label-components');\n if (activeItemAriaLabelComponen
t) {\n // If we have string components for the aria label then load the string\n // and set the label on the dropdown toggle.\n var strParams = activeItemAriaLabelComponent.split(',');\n strParams.push(activeOptionText);\n\n Str.get_string(strParams[0].trim(), strParams[1].trim(), strParams[2].trim())\n .then(function(string) {\n dropdownToggle.attr('aria-label', string);\n return string;\n })\n .catch(function() {\n // Silently ignore that we couldn't load the string.\n return false;\n });\n }\n });\n };\n\n /**\n * Initialise the global helper functions.\n */\n var init = function() {\n initActionOptionDropdownHandler();\n Network.init();\n };\n\n return {\n init: init\n };\n});\n"],"names":["define","$"
,"CustomEvents","Str","Network","init","body","find","each","this","addClass","events","activate","on","e","option","target","closest","menuContainer","hasClass","dropdownItems","removeClass","removeAttr","attr","activeOptionText","text","dropdownToggle","parent","dropdownToggleText","length","html","activeItemAriaLabelComponent","strParams","split","push","get_string","trim","then","string","catch"],"mappings":";;;;;;;AAsBAA,0BACA,CACI,SACA,iCACA,WACA,iBAEJ,SACIC,EACAC,aACAC,IACAC,eA0GO,CACHC,KANO,WA7E2B,IAC9BC,MAAAA,KAAOL,EAAE,SAGRM,KAAK,kBAAkBC,MAAK,WAC7BP,EAAEQ,MAAMF,KAAK,yBAAyBG,SAAS,2BAGnDR,aAAaF,OAAOM,KAAM,CAACJ,aAAaS,OAAOC,WAC/CN,KAAKO,GAAGX,aAAaS,OAAOC,SAAU,2BAA2B,SAASE,OAElEC,OAASd,EAAEa,EAAEE,QAAQC,QAAQ,kBAE7BC,cAAgBH,OAAOE,QAAQ,8BAE9BF,OAAOI,SAAS,mBAKjBJ,OAAOI,SAAS,eAMhBC,cAAgBF,cAAcX,KAAK,kBACvCa,cAAcC,YAAY,CAAC,SAAU,yBACrCD,cAAcE,WAAW,gBAEpBJ,cAAcK,KAAK,2BAIpBR,OAAOL,SAAS,UAEpBK,OAAOL,SAAS,wBAGhBK,OAAOQ,KAAK,gBAAgB,OAExBC,iBAAmBT,OAAOU,OAC1BC,eAAiBR,cAAcS,SAASpB,KAAK,+BAC7CqB,mBAAqBF,eAAenB,KAA
K,2BAEzCqB,mBAAmBC,OAGnBD,mBAAmBE,KAAKN,kBAGxBE,eAAeI,KAAKN,sBAGpBO,6BAA+Bb,cAAcK,KAAK,oDAClDQ,6BAA8B,KAG1BC,UAAYD,6BAA6BE,MAAM,KACnDD,UAAUE,KAAKV,kBAEfrB,IAAIgC,WAAWH,UAAU,GAAGI,OAAQJ,UAAU,GAAGI,OAAQJ,UAAU,GAAGI,QACjEC,MAAK,SAASC,eACXZ,eAAeH,KAAK,aAAce,QAC3BA,UAEVC,OAAM,kBAEI,UAWvBnC,QAAQC"}