lib/editor/atto/amd/src/events.js

  1. // This file is part of Moodle - http://moodle.org/ //
  2. // Moodle is free software: you can redistribute it and/or modify
  3. // it under the terms of the GNU General Public License as published by
  4. // the Free Software Foundation, either version 3 of the License, or
  5. // (at your option) any later version.
  6. //
  7. // Moodle is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU General Public License
  13. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  14. /**
  15. * Javascript events for the `editor_atto` plugin.
  16. *
  17. * @module editor_atto/events
  18. * @copyright 2021 Jun Pataleta <jun@moodle.com>
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  20. * @since 3.10.5
  21. */
  22. import {dispatchEvent} from 'core/event_dispatcher';
  23. /**
  24. * Events for the `editor_atto` plugin.
  25. *
  26. * @constant
  27. * @property {String} attoButtonHighlightToggled See {@link event:attoButtonHighlightToggled}
  28. */
  29. export const eventTypes = {
  30. /**
  31. * An event triggered when a toolbar button's highlight gets toggled.
  32. *
  33. * @event attoButtonHighlightToggled
  34. * @type {CustomEvent}
  35. * @property {HTMLElement} target The button which had its highlight toggled.
  36. * @property {object} detail
  37. * @property {String} detail.buttonName The name of the Atto button that has had its highlight toggled.
  38. * @property {Boolean} detail.highlight True when the button was highlighted. False, otherwise.
  39. */
  40. attoButtonHighlightToggled: 'editor_atto/attoButtonHighlightToggled',
  41. };
  42. /**
  43. * Trigger an event to indicate that a button's highlight was toggled.
  44. *
  45. * @method notifyButtonHighlightToggled
  46. * @returns {CustomEvent}
  47. * @fires attoButtonHighlightToggled
  48. * @param {HTMLElement} attoButton The button object.
  49. * @param {String} buttonName The button name.
  50. * @param {Boolean} highlight True when the button was highlighted. False, otherwise.
  51. */
  52. export const notifyButtonHighlightToggled = (attoButton, buttonName, highlight) => {
  53. return dispatchEvent(
  54. eventTypes.attoButtonHighlightToggled,
  55. {
  56. buttonName,
  57. highlight,
  58. },
  59. attoButton
  60. );
  61. };