lib/editor/tiny/plugins/noautolink/amd/src/commands.js

  1. // This file is part of Moodle - http://moodle.org/
  2. //
  3. // Moodle is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // Moodle is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  15. import {getButtonImage} from 'editor_tiny/utils';
  16. import {get_string as getString} from 'core/str';
  17. import {component, buttonName, buttonIcon} from 'tiny_noautolink/common';
  18. import {handleAction, toggleActiveState} from 'tiny_noautolink/noautolink';
  19. /**
  20. * Tiny noautolink commands.
  21. *
  22. * @module tiny_noautolink/commands
  23. * @copyright 2023 Meirza <meirza.arson@moodle.com>
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25. */
  26. export const getSetup = async() => {
  27. const [
  28. buttonText,
  29. infoEmptySelection,
  30. infoAddSuccess,
  31. infoRemoveSuccess,
  32. buttonImage,
  33. ] = await Promise.all([
  34. getString('buttontitle', component),
  35. getString('infoemptyselection', component),
  36. getString('infoaddsuccess', component),
  37. getString('inforemovesuccess', component),
  38. getButtonImage('icon', component),
  39. ]);
  40. return (editor) => {
  41. const messages = {
  42. infoEmptySelection: infoEmptySelection,
  43. infoAddSuccess: infoAddSuccess,
  44. infoRemoveSuccess: infoRemoveSuccess
  45. };
  46. // Register the noautolink Icon.
  47. editor.ui.registry.addIcon(buttonIcon, buttonImage.html);
  48. // Register the noautolink button.
  49. editor.ui.registry.addToggleButton(buttonName, {
  50. icon: buttonIcon,
  51. tooltip: buttonText,
  52. onAction: () => {
  53. handleAction(editor, messages);
  54. },
  55. onSetup: toggleActiveState(editor),
  56. });
  57. // Register the noautolink item.
  58. editor.ui.registry.addMenuItem(buttonName, {
  59. icon: buttonIcon,
  60. text: buttonText,
  61. onAction: () => {
  62. handleAction(editor, messages);
  63. },
  64. });
  65. };
  66. };