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. } from './common';
  26. import {
  27. addMenubarItem,
  28. } from 'editor_tiny/utils';
  29. const configureMenu = (menu) => {
  30. const items = menu.insert.items.split(' ');
  31. const inserted = items.some((item, index) => {
  32. // Append after the media or video button.
  33. if (item.match(/(media|video)\b/)) {
  34. items.splice(index + 1, 0, audioButtonName, videoButtonName);
  35. return true;
  36. }
  37. return false;
  38. });
  39. if (inserted) {
  40. menu.insert.items = items.join(' ');
  41. } else {
  42. addMenubarItem(menu, 'insert', `${audioButtonName} ${videoButtonName}`);
  43. }
  44. return menu;
  45. };
  46. const configureToolbar = (toolbar) => {
  47. // The toolbar contains an array of named sections.
  48. // The Moodle integration ensures that there is a section called 'content'.
  49. return toolbar.map((section) => {
  50. if (section.name === 'content') {
  51. const inserted = section.items.some((item, index) => {
  52. // Append after the media or video button.
  53. if (item.match(/(media|video)\b/)) {
  54. section.items.splice(index + 1, 0, audioButtonName, videoButtonName);
  55. return true;
  56. }
  57. return false;
  58. });
  59. if (!inserted) {
  60. section.items.unshift(audioButtonName, videoButtonName);
  61. }
  62. }
  63. return section;
  64. });
  65. };
  66. export const configure = (instanceConfig) => {
  67. // Update the instance configuration to add the Media menu option to the menus and toolbars and upload_handler.
  68. return {
  69. toolbar: configureToolbar(instanceConfig.toolbar),
  70. menu: configureMenu(instanceConfig.menu),
  71. };
  72. };