Proyectos de Subversion Moodle

Rev

Autoría | 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 */\ndefine(\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-toggle=\"dropdown\" element\n     *                         to use it as the active option text placeholder otherwise the\n     *                         data-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        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');\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\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-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 (activeItemAriaLabelComponent) {\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","events","activate","on","e","option","target","closest","menuContainer","hasClass","dropdownItems","find","removeClass","removeAttr","attr","addClass","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,eAoGO,CACHC,KANO,WAvE2B,IAC9BC,KAAAA,KAAOL,EAAE,QAEbC,aAAaF,OAAOM,KAAM,CAACJ,aAAaK,OAAOC,WAC/CF,KAAKG,GAAGP,aAAaK,OAAOC,SAAU,2BAA2B,SAASE,OAElEC,OAASV,EAAES,EAAEE,QAAQC,QAAQ,kBAE7BC,cAAgBH,OAAOE,QAAQ,8BAE9BF,OAAOI,SAAS,mBAKjBJ,OAAOI,SAAS,eAMhBC,cAAgBF,cAAcG,KAAK,kBACvCD,cAAcE,YAAY,UAC1BF,cAAcG,WAAW,gBAEpBL,cAAcM,KAAK,2BAIpBT,OAAOU,SAAS,UAIpBV,OAAOS,KAAK,gBAAgB,OAExBE,iBAAmBX,OAAOY,OAC1BC,eAAiBV,cAAcW,SAASR,KAAK,4BAC7CS,mBAAqBF,eAAeP,KAAK,2BAEzCS,mBAAmBC,OAGnBD,mBAAmBE,KAAKN,kBAGxBE,eAAeI,KAAKN,sBAGpBO,6BAA+Bf,cAAcM,KAAK,oDAClDS,6BAA8B,KAG1BC,UAAYD,6BAA6BE,MAAM,KACnDD,UAAUE,KAAKV,kBAEfnB,IAAI8B,WAAWH,UAAU,GAAGI,OAAQJ,UAAU,GAAGI,OAAQJ,UAAU,GAAGI,QACjEC,MAAK,SAASC,eACXZ,eAAeJ,KAAK,aAAcgB,QAC3BA,UAEVC,OAAM,kBAEI,UAWvBjC,QAAQC"}