Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
{"version":3,"file":"controls.min.js","sources":["../../../src/local/collapsable_section/controls.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 * The collapsable sections controls.\n *\n * @module     core/local/collapsable_section/controls\n * @copyright  2024 Ferran Recio <ferran@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n * @example <caption>Example of controlling a collapsable section.</caption>\n *\n * import CollapsableSection from 'core/local/collapsable_section/controls';\n *\n * const section = CollapsableSection.instanceFromSelector('#MyCollapsableSection');\n *\n * // Use hide, show and toggle methods to control the section.\n * section.hide();\n */\n\nimport {\n    eventTypes,\n    notifyCollapsableSectionHidden,\n    notifyCollapsableSectionShown\n} from 'core/local/collapsable_section/events';\nimport Collapse from 'theme_boost/bootstrap/collapse';\n\nlet initialized = false;\n\nexport default class {\n    /**\n     * Create a new instance from a query selector.\n     *\n     * @param {String} selector The selector of the collapsable section.\n     * @return {CollapsableSection} The collapsable section controls.\n     * @throws {Error} If no elements are found with the selector.\n     */\n    static instanceFromSelector(selector) {\n        const elements = document.querySelector(selector);\n        if (!elements) {\n            throw new Error('No elements found with the selector: ' + selector);\n        }\n        return new this(elements);\n    }\n\n    /**\n     * Initialize the collapsable section controls.\n     */\n    static init() {\n        if (initialized) {\n            return;\n        }\n        initialized = true;\n\n        // We want to add extra events to the standard bootstrap collapsable events.\n        document.addEventListener(eventTypes.hiddenBsCollapse, event => {\n            if (!this.isCollapsableComponent(event.target)) {\n                return;\n            }\n            notifyCollapsableSectionHidden(event.target);\n        });\n        document.addEventListener(eventTypes.shownBsCollapse, event => {\n            if (!this.isCollapsableComponent(event.target)) {\n                return;\n            }\n            notifyCollapsableSectionShown(event.target);\n        });\n    }\n\n    /**\n     * Check if the element is a collapsable section.\n     *\n     * @private\n     * @param {HTMLElement} element The element to check.\n     * @return {boolean} True if the element is a collapsable section.\n     */\n    static isCollapsableComponent(element) {\n        return element.hasAttribute('data-mdl-component')\n            && element.getAttribute('data-mdl-component') === 'core/local/collapsable_section';\n    }\n\n    /**\n     * Creates an instance of the controls for a collapsable section.\n     *\n     * @param {HTMLElement} element - The DOM element that this control will manage.\n     */\n    constructor(element) {\n        this.element = element;\n    }\n\n    /**\n     * Hides the collapsible section element.\n     */\n    hide() {\n        Collapse.getOrCreateInstance(this.element).hide();\n    }\n\n    /**\n     * Shows the collapsible section element.\n     */\n    show() {\n        Collapse.getOrCreateInstance(this.element).show();\n    }\n\n    /**\n     * Toggle the collapsible section element.\n     */\n    toggle() {\n        Collapse.getOrCreateInstance(this.element).toggle();\n    }\n\n    /**\n     * Check if the collapsable section is visible.\n     *\n     * @return {boolean} True if the collapsable section is visible.\n     */\n    isVisible() {\n        return Collapse.getOrCreateInstance(this.element)._isShown();\n    }\n}\n"],"names":["initialized","selector","elements","document","querySelector","Error","this","addEventListener","eventTypes","hiddenBsCollapse","event","isCollapsableComponent","target","shownBsCollapse","element","hasAttribute","getAttribute","constructor","hide","getOrCreateInstance","show","toggle","isVisible","Collapse","_isShown"],"mappings":";;;;;;;;;;;;;;;;qJAuCIA,aAAc,4DAUcC,gBAClBC,SAAWC,SAASC,cAAcH,cACnCC,eACK,IAAIG,MAAM,wCAA0CJ,iBAEvD,IAAIK,KAAKJ,wBAOZF,cAGJA,aAAc,EAGdG,SAASI,iBAAiBC,mBAAWC,kBAAkBC,QAC9CJ,KAAKK,uBAAuBD,MAAME,oDAGRF,MAAME,WAEzCT,SAASI,iBAAiBC,mBAAWK,iBAAiBH,QAC7CJ,KAAKK,uBAAuBD,MAAME,mDAGTF,MAAME,0CAWdE,gBACnBA,QAAQC,aAAa,uBAC0B,mCAA/CD,QAAQE,aAAa,sBAQhCC,YAAYH,cACHA,QAAUA,QAMnBI,yBACaC,oBAAoBb,KAAKQ,SAASI,OAM/CE,yBACaD,oBAAoBb,KAAKQ,SAASM,OAM/CC,2BACaF,oBAAoBb,KAAKQ,SAASO,SAQ/CC,mBACWC,kBAASJ,oBAAoBb,KAAKQ,SAASU"}