Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"move_options_tree.min.js","sources":["../../../../src/bulkactions/edit/tree/move_options_tree.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 * Keyboard navigation and aria-tree compatibility for the grade move options.\n *\n * @module     core_grades/bulkactions/edit/tree/move_options_tree\n * @copyright  2023 Mihail Geshoski <mihail@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Tree from 'core/tree';\nimport {getList} from 'core/normalise';\n\n/** @constant {Object} The object containing the relevant selectors. */\nconst Selectors = {\n    moveOptionsTree: '#destination-selector [role=\"tree\"]',\n    moveOption: '#destination-selector [role=\"treeitem\"]',\n    toggleGroupLink: '#destination-selector .collapse-list-link',\n};\n\nexport default class MoveOptionsTree extends Tree {\n\n    /** @property {function|null} afterSelectMoveOptionCallback Callback function to run after selecting a move option. */\n    afterSelectMoveOptionCallback = null;\n\n    /** @property {HTMLElement|null} selectedMoveOption The selected move option. */\n    selectedMoveOption = null;\n\n    /**\n     * The class constructor.\n     *\n     * @param {function|null} afterSelectMoveOptionCallback Callback function used to define actions that should be run\n     *                                                      after selecting a move option.\n     * @returns {void}\n     */\n    constructor(afterSelectMoveOptionCallback) {\n        super(Selectors.moveOptionsTree);\n        this.afterSelectMoveOptionCallback = afterSelectMoveOptionCallback;\n    }\n\n    /**\n     * Handle a key down event.\n     *\n     * @method handleKeyDown\n     * @param {Event} e The event.\n     */\n    handleKeyDown(e) {\n        // If the user presses enter or space, select the item.\n        if (e.keyCode === this.keys.enter || e.keyCode === this.keys.space) {\n            this.selectMoveOption(e.target);\n        } else { // Otherwise, let the default behaviour happen.\n            super.handleKeyDown(e);\n        }\n    }\n\n    /**\n     * Handle an item click.\n     *\n     * @param {Event} event The click event.\n     * @param {jQuery} item The item clicked.\n     * @returns {void}\n     */\n    handleItemClick(event, item) {\n        const isToggleGroupLink = event.target.closest(Selectors.toggleGroupLink);\n        // If the click is on the toggle group (chevron) link, let the default behaviour happen.\n        if (isToggleGroupLink) {\n            super.handleItemClick(event, item);\n            return;\n        }\n        // If the click is on the item itself, select it.\n        this.selectMoveOption(getList(item)[0]);\n    }\n\n    /**\n     * Select a move option.\n     *\n     * @method selectMoveOption\n     * @param {HTMLElement} moveOption The move option to select.\n     */\n    selectMoveOption(moveOption) {\n        // Create the cache of the visible items.\n        this.refreshVisibleItemsCache();\n        // Deselect all the move options.\n        document.querySelectorAll(Selectors.moveOption).forEach(item => {\n            item.dataset.selected = \"false\";\n        });\n        // Select and set the focus on the specified move option.\n        moveOption.dataset.selected = \"true\";\n        this.selectedMoveOption = moveOption;\n        moveOption.focus();\n        // Call the callback function if it is defined.\n        if (typeof this.afterSelectMoveOptionCallback === 'function') {\n            this.afterSelectMoveOptionCallback();\n        }\n    }\n}\n"],"names":["Selectors","MoveOptionsTree","Tree","constructor","afterSelectMoveOptionCallback","handleKeyDown","e","keyCode","this","keys","enter","space","selectMoveOption","target","handleItemClick","event","item","closest","moveOption","refreshVisibleItemsCache","document","querySelectorAll","forEach","dataset","selected","selectedMoveOption","focus"],"mappings":"icA2BMA,0BACe,sCADfA,qBAEU,0CAFVA,0BAGe,kDAGAC,wBAAwBC,cAezCC,YAAYC,qCACFJ,gFAbsB,gDAGX,WAWZI,8BAAgCA,8BASzCC,cAAcC,GAENA,EAAEC,UAAYC,KAAKC,KAAKC,OAASJ,EAAEC,UAAYC,KAAKC,KAAKE,WACpDC,iBAAiBN,EAAEO,cAElBR,cAAcC,GAW5BQ,gBAAgBC,MAAOC,MACOD,MAAMF,OAAOI,QAAQjB,iCAGrCc,gBAAgBC,MAAOC,WAI5BJ,kBAAiB,sBAAQI,MAAM,IASxCJ,iBAAiBM,iBAERC,2BAELC,SAASC,iBAAiBrB,sBAAsBsB,SAAQN,OACpDA,KAAKO,QAAQC,SAAW,WAG5BN,WAAWK,QAAQC,SAAW,YACzBC,mBAAqBP,WAC1BA,WAAWQ,QAEuC,mBAAvClB,KAAKJ,oCACPA"}