From 45906644be6eede2dc26c0de90bfedc6359eda9d Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 1 Jun 2021 12:44:36 +0800 Subject: [PATCH] MDL-71669 editor_atto: Create an events module for the atto editor --- lib/editor/atto/amd/build/events.min.js | 2 + lib/editor/atto/amd/build/events.min.js.map | 1 + lib/editor/atto/amd/src/events.js | 65 +++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/editor/atto/amd/build/events.min.js create mode 100644 lib/editor/atto/amd/build/events.min.js.map create mode 100644 lib/editor/atto/amd/src/events.js diff --git a/lib/editor/atto/amd/build/events.min.js b/lib/editor/atto/amd/build/events.min.js new file mode 100644 index 00000000000..bf154d39561 --- /dev/null +++ b/lib/editor/atto/amd/build/events.min.js @@ -0,0 +1,2 @@ +define ("editor_atto/events",["exports","core/event_dispatcher"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.notifyButtonHighlightToggled=a.eventTypes=void 0;var c={attoButtonHighlightToggled:"editor_atto/attoButtonHighlightToggled"};a.eventTypes=c;a.notifyButtonHighlightToggled=function notifyButtonHighlightToggled(a,d,e){return(0,b.dispatchEvent)(c.attoButtonHighlightToggled,{buttonName:d,highlight:e},a)}}); +//# sourceMappingURL=events.min.js.map diff --git a/lib/editor/atto/amd/build/events.min.js.map b/lib/editor/atto/amd/build/events.min.js.map new file mode 100644 index 00000000000..b6873fc76ee --- /dev/null +++ b/lib/editor/atto/amd/build/events.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/events.js"],"names":["eventTypes","attoButtonHighlightToggled","notifyButtonHighlightToggled","attoButton","buttonName","highlight"],"mappings":"gMA+BO,GAAMA,CAAAA,CAAU,CAAG,CAWtBC,0BAA0B,CAAE,wCAXN,CAAnB,C,8CAwBqC,QAA/BC,CAAAA,4BAA+B,CAACC,CAAD,CAAaC,CAAb,CAAyBC,CAAzB,CAAuC,CAC/E,MAAO,oBACHL,CAAU,CAACC,0BADR,CAEH,CACIG,UAAU,CAAVA,CADJ,CAEIC,SAAS,CAATA,CAFJ,CAFG,CAMHF,CANG,CAQV,C","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 .\n\n/**\n * Javascript events for the `editor_atto` plugin.\n *\n * @module editor_atto/events\n * @copyright 2021 Jun Pataleta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.10.5\n */\n\nimport {dispatchEvent} from 'core/event_dispatcher';\n\n/**\n * Events for the `editor_atto` plugin.\n *\n * @constant\n * @property {String} attoButtonHighlightToggled See {@link event:attoButtonHighlightToggled}\n */\nexport const eventTypes = {\n /**\n * An event triggered when a toolbar button's highlight gets toggled.\n *\n * @event attoButtonHighlightToggled\n * @type {CustomEvent}\n * @property {HTMLElement} target The button which had its highlight toggled.\n * @property {object} detail\n * @property {String} detail.buttonName The name of the Atto button that has had its highlight toggled.\n * @property {Boolean} detail.highlight True when the button was highlighted. False, otherwise.\n */\n attoButtonHighlightToggled: 'editor_atto/attoButtonHighlightToggled',\n};\n\n/**\n * Trigger an event to indicate that a button's highlight was toggled.\n *\n * @method notifyButtonHighlightToggled\n * @returns {CustomEvent}\n * @fires attoButtonHighlightToggled\n * @param {HTMLElement} attoButton The button object.\n * @param {String} buttonName The button name.\n * @param {Boolean} highlight True when the button was highlighted. False, otherwise.\n */\nexport const notifyButtonHighlightToggled = (attoButton, buttonName, highlight) => {\n return dispatchEvent(\n eventTypes.attoButtonHighlightToggled,\n {\n buttonName,\n highlight,\n },\n attoButton\n );\n};\n"],"file":"events.min.js"} \ No newline at end of file diff --git a/lib/editor/atto/amd/src/events.js b/lib/editor/atto/amd/src/events.js new file mode 100644 index 00000000000..05ca6045c22 --- /dev/null +++ b/lib/editor/atto/amd/src/events.js @@ -0,0 +1,65 @@ +// This file is part of Moodle - http://moodle.org/ // +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Javascript events for the `editor_atto` plugin. + * + * @module editor_atto/events + * @copyright 2021 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since 3.10.5 + */ + +import {dispatchEvent} from 'core/event_dispatcher'; + +/** + * Events for the `editor_atto` plugin. + * + * @constant + * @property {String} attoButtonHighlightToggled See {@link event:attoButtonHighlightToggled} + */ +export const eventTypes = { + /** + * An event triggered when a toolbar button's highlight gets toggled. + * + * @event attoButtonHighlightToggled + * @type {CustomEvent} + * @property {HTMLElement} target The button which had its highlight toggled. + * @property {object} detail + * @property {String} detail.buttonName The name of the Atto button that has had its highlight toggled. + * @property {Boolean} detail.highlight True when the button was highlighted. False, otherwise. + */ + attoButtonHighlightToggled: 'editor_atto/attoButtonHighlightToggled', +}; + +/** + * Trigger an event to indicate that a button's highlight was toggled. + * + * @method notifyButtonHighlightToggled + * @returns {CustomEvent} + * @fires attoButtonHighlightToggled + * @param {HTMLElement} attoButton The button object. + * @param {String} buttonName The button name. + * @param {Boolean} highlight True when the button was highlighted. False, otherwise. + */ +export const notifyButtonHighlightToggled = (attoButton, buttonName, highlight) => { + return dispatchEvent( + eventTypes.attoButtonHighlightToggled, + { + buttonName, + highlight, + }, + attoButton + ); +};