Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"modal_copy_to_clipboard.min.js","sources":["../src/modal_copy_to_clipboard.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 * Contain the logic for the copy to clipboard modal, i.e. the modal contains a\n * readonly input text field, that contains a value. Clicking on the single\n * button \"Copy to clipboard\" in the footer, puts the content of the input\n * text field into the clipboard and closes the modal.\n *\n * Usage:\n * ModalCopyToClipboard.create(string:<stringToCopy>, string:<modalTitle>|null);\n *\n * @module     core/modal_copy_to_clipboard\n * @copyright  2023 Stephan Robotta <stephan.robotta@bfh.ch>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Modal from 'core/modal';\nimport 'core/copy_to_clipboard';\n\nexport default class CopyToClipboardModal extends Modal {\n    static TYPE = 'core/copytoclipboard';\n    static TEMPLATE = 'core/modal_copytoclipboard';\n\n    constructor(...config) {\n        // Override the constructor to set the removeOnClose property, and show the modal.\n        super(...config);\n        this.setRemoveOnClose(true);\n    }\n\n    /**\n     * Set up all the event handling for the modal.\n     * This is an override of the parent method, adding an event listener to close upon the action.\n     *\n     * @param {array} args\n     */\n    registerEventListeners(...args) {\n        super.registerEventListeners(...args);\n\n        this.getRoot().get(0).addEventListener('click', (e) => {\n            if (!e.target.closest('[data-action=\"copytoclipboard\"]')) {\n                return;\n            }\n\n            if (!this.getRoot().get(0).contains(e.target)) {\n                return;\n            }\n\n            // Note: We must call destroy() here, because the copy-to-clipboard action listens on the document,\n            // which will be processed after this event listener has been processed.\n            // By placing this in a setTimeout we move its processing to after the event loop has finished.\n            setTimeout(this.destroy.bind(this));\n        });\n    }\n\n    /**\n     * Create a new instance of the Modal. Set the text that is being copied. By default, the text is put into the\n     * value of an input readonly field. If useTextArea is set to true, the text is rendered in a textarea element.\n     * The optional title argument is for the modal title. If not set, the generic string \"copy to clipboard\" is used.\n     *\n     * @param {Object} data used in the template\n     * @param {string} data.text the text to copy to the clipboard\n     * @param {boolean} data.useTextArea when the text to copy is displayed in a textarea, default is input\n     * @param {string|null} title\n     * @returns {Promise<void>}\n     */\n    static async create(\n        {\n            text,\n            useTextArea = false,\n        } = {},\n        title,\n    ) {\n        const modalConfig = {\n            templateContext: {\n                text,\n                useTextArea,\n            },\n        };\n        if (title) {\n            modalConfig.title = title;\n        }\n\n        return super.create(modalConfig);\n    }\n\n    configure(modalConfig) {\n        modalConfig.show = true;\n        modalConfig.removeOnClose = true;\n\n        super.configure(modalConfig);\n    }\n}\n\nCopyToClipboardModal.registerModalType();\n"],"names":["CopyToClipboardModal","Modal","constructor","setRemoveOnClose","registerEventListeners","getRoot","get","addEventListener","e","target","closest","this","contains","setTimeout","destroy","bind","text","useTextArea","title","modalConfig","templateContext","super","create","configure","show","removeOnClose","registerModalType"],"mappings":"8bAgCqBA,6BAA6BC,eAI9CC,uCAGSC,kBAAiB,GAS1BC,+BACUA,0CAEDC,UAAUC,IAAI,GAAGC,iBAAiB,SAAUC,IACxCA,EAAEC,OAAOC,QAAQ,oCAIjBC,KAAKN,UAAUC,IAAI,GAAGM,SAASJ,EAAEC,SAOtCI,WAAWF,KAAKG,QAAQC,KAAKJ,oCAgBjCK,KACIA,KADJC,YAEIA,aAAc,0DACd,GACJC,mDAEMC,YAAc,CAChBC,gBAAiB,CACbJ,KAAAA,KACAC,YAAAA,qBAGJC,QACAC,YAAYD,MAAQA,OAGjBG,MAAMC,OAAOH,aAGxBI,UAAUJ,aACNA,YAAYK,MAAO,EACnBL,YAAYM,eAAgB,QAEtBF,UAAUJ,2EAtEHnB,4BACH,wCADGA,gCAEC,8BAwEtBA,qBAAqB0B"}