lib/editor/tiny/plugins/recordrtc/amd/src/configuration.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. /**
  16. * Tiny Record RTC configuration.
  17. *
  18. * @module tiny_recordrtc/configuration
  19. * @copyright 2022, Stevani Andolo <stevani@hotmail.com.au>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import {
  23. audioButtonName,
  24. videoButtonName,
  25. screenButtonName,
  26. videoContextMenuName,
  27. } from './common';
  28. import {
  29. addMenubarItem,
  30. } from 'editor_tiny/utils';
  31. const configureMenu = (menu) => {
  32. const items = menu.insert.items.split(' ');
  33. const inserted = items.some((item, index) => {
  34. // Append after the media or video button.
  35. if (item.match(/(media|video)\b/)) {
  36. items.splice(index + 1, 0, audioButtonName, videoButtonName, screenButtonName);
  37. return true;
  38. }
  39. return false;
  40. });
  41. if (inserted) {
  42. menu.insert.items = items.join(' ');
  43. } else {
  44. addMenubarItem(menu, 'insert', `${audioButtonName} ${videoButtonName} ${screenButtonName}`);
  45. }
  46. return menu;
  47. };
  48. const configureToolbar = (toolbar) => {
  49. // The toolbar contains an array of named sections.
  50. // The Moodle integration ensures that there is a section called 'content'.
  51. return toolbar.map((section) => {
  52. if (section.name === 'content') {
  53. const inserted = section.items.some((item, index) => {
  54. // Append after the media or video button.
  55. if (item.match(/(media|video)\b/)) {
  56. section.items.splice(index + 1, 0, audioButtonName, videoContextMenuName);
  57. return true;
  58. }
  59. return false;
  60. });
  61. if (!inserted) {
  62. section.items.unshift(audioButtonName, videoContextMenuName);
  63. }
  64. }
  65. return section;
  66. });
  67. };
  68. export const configure = (instanceConfig) => {
  69. // Update the instance configuration to add the Media menu option to the menus and toolbars and upload_handler.
  70. return {
  71. toolbar: configureToolbar(instanceConfig.toolbar),
  72. menu: configureMenu(instanceConfig.menu),
  73. };
  74. };