Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"events.min.js","sources":["../src/events.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/ //\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 * Javascript events for the `core_editor` subsystem.\n *\n * @module     core_editor/events\n * @copyright  2021 Andrew Nicols <andrew@nicols.co.uk>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since      4.0\n */\n\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport jQuery from 'jquery';\nimport Y from 'core/yui';\n\n/**\n * Events for the `core_editor` subsystem.\n *\n * @constant\n * @property {String} editorContentRestored See {@link event:editorContentRestored}\n */\nexport const eventTypes = {\n    /**\n     * An event triggered when an editor restores auto-saved content.\n     *\n     * @event editorContentRestored\n     */\n    editorContentRestored: 'core_editor/contentRestored',\n};\n\n/**\n * Trigger an event to indicate that editor content was restored.\n *\n * @method  notifyEditorContentRestored\n * @param   {HTMLElement|null} editor The element that was modified\n * @returns {CustomEvent}\n * @fires   editorContentRestored\n */\nexport const notifyEditorContentRestored = editor => {\n    if (!editor) {\n        window.console.warn(\n            `The HTMLElement representing the editor that was modified should be provided to notifyEditorContentRestored.`\n        );\n    }\n    return dispatchEvent(\n        eventTypes.editorContentRestored,\n        {},\n        editor || document\n    );\n};\n\nlet legacyEventsRegistered = false;\nif (!legacyEventsRegistered) {\n    // The following event triggers are legacy and will be removed in the future.\n    // The following approach provides a backwards-compatability layer for the new events.\n    // Code should be updated to make use of native events.\n\n    Y.use('event', 'moodle-core-event', () => {\n        // Provide a backwards-compatability layer for YUI Events.\n        document.addEventListener(eventTypes.editorContentRestored, () => {\n            // Trigger a legacy AMD event.\n            jQuery(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);\n\n            // Trigger a legacy YUI event.\n            Y.fire(M.core.event.EDITOR_CONTENT_RESTORED);\n        });\n    });\n\n    legacyEventsRegistered = true;\n}\n"],"names":["eventTypes","editorContentRestored","editor","window","console","warn","document","legacyEventsRegistered","use","addEventListener","trigger","M","core","event","EDITOR_CONTENT_RESTORED","fire"],"mappings":";;;;;;;;6MAiCaA,WAAa,CAMtBC,sBAAuB,mGAWgBC,SAClCA,QACDC,OAAOC,QAAQC,sHAIZ,mCACHL,WAAWC,sBACX,GACAC,QAAUI,eAIdC,wBAAyB,EACxBA,sCAKCC,IAAI,QAAS,qBAAqB,KAEhCF,SAASG,iBAAiBT,WAAWC,uBAAuB,yBAEjDK,UAAUI,QAAQC,EAAEC,KAAKC,MAAMC,sCAGpCC,KAAKJ,EAAEC,KAAKC,MAAMC,+BAI5BP,wBAAyB"}