lib/editor/tiny/plugins/media/amd/src/imagehelpers.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 media plugin image helpers.
  17. *
  18. * @module tiny_media/imagehelpers
  19. * @copyright 2024 Meirza <meirza.arson@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import * as Helpers from 'tiny_media/helpers';
  23. import {Selectors} from './selectors';
  24. /**
  25. * Maximum length allowed for the alt attribute.
  26. */
  27. export const MAX_LENGTH_ALT = 750;
  28. /**
  29. * Renders and inserts the body template for inserting an image into the modal.
  30. *
  31. * @param {object} templateContext - The context for rendering the template.
  32. * @param {HTMLElement} root - The root element where the template will be inserted.
  33. * @returns {Promise<void>}
  34. * @deprecated Since Moodle 5.0 See {@link module:core_editor/tiny/plugins/media/helpers.body}
  35. */
  36. export const bodyImageInsert = async(templateContext, root) => {
  37. window.console.warn('This function is deprecated. Please use core_editor/tiny/plugins/media/helpers.body instead.');
  38. templateContext.bodyTemplate = 'tiny_media/insert_image_modal_insert';
  39. templateContext.selector = Selectors.IMAGE.type;
  40. return Helpers.body(templateContext, root);
  41. };
  42. /**
  43. * Renders and inserts the footer template for inserting an image into the modal.
  44. *
  45. * @param {object} templateContext - The context for rendering the template.
  46. * @param {HTMLElement} root - The root element where the template will be inserted.
  47. * @returns {Promise<void>}
  48. * @deprecated Since Moodle 5.0 See {@link module:core_editor/tiny/plugins/media/helpers.footer}
  49. */
  50. export const footerImageInsert = async(templateContext, root) => {
  51. window.console.warn(`This function is deprecated.
  52. Please use core_editor/tiny/plugins/media/helpers.footer instead.`);
  53. templateContext.footerTemplate = 'tiny_media/insert_image_modal_insert_footer';
  54. templateContext.selector = Selectors.IMAGE.type;
  55. return Helpers.footer(templateContext, root);
  56. };
  57. /**
  58. * Renders and inserts the body template for displaying image details in the modal.
  59. *
  60. * @param {object} templateContext - The context for rendering the template.
  61. * @param {HTMLElement} root - The root element where the template will be inserted.
  62. * @returns {Promise<void>}
  63. * @deprecated Since Moodle 5.0 See {@link module:core_editor/tiny/plugins/media/helpers.body}
  64. */
  65. export const bodyImageDetails = async(templateContext, root) => {
  66. window.console.warn(`This function is deprecated.
  67. Please use core_editor/tiny/plugins/media/helpers.body instead.`);
  68. templateContext.bodyTemplate = 'tiny_media/insert_image_modal_details';
  69. templateContext.selector = Selectors.IMAGE.type;
  70. return Helpers.body(templateContext, root);
  71. };
  72. /**
  73. * Renders and inserts the footer template for displaying image details in the modal.
  74. * @param {object} templateContext - The context for rendering the template.
  75. * @param {HTMLElement} root - The root element where the template will be inserted.
  76. * @returns {Promise<void>}
  77. * @deprecated Since Moodle 5.0 See {@link module:core_editor/tiny/plugins/media/helpers.footer}
  78. */
  79. export const footerImageDetails = async(templateContext, root) => {
  80. window.console.warn(`This function is deprecated.
  81. Please use core_editor/tiny/plugins/media/helpers.footer instead.`);
  82. templateContext.footerTemplate = 'tiny_media/insert_image_modal_details_footer';
  83. templateContext.selector = Selectors.IMAGE.type;
  84. return Helpers.footer(templateContext, root);
  85. };
  86. /**
  87. * Show the element(s).
  88. *
  89. * @param {string|string[]} elements - The CSS selector for the elements to toggle.
  90. * @param {object} root - The CSS selector for the elements to toggle.
  91. * @deprecated Since Moodle 5.0 See {@link module:core_editor/tiny/plugins/media/helpers.showElements}
  92. */
  93. export const showElements = (elements, root) => {
  94. window.console.warn(`This function is deprecated.
  95. Please use core_editor/tiny/plugins/media/helpers.showElements instead.`);
  96. Helpers.showElements(elements, root);
  97. };
  98. /**
  99. * Hide the element(s).
  100. *
  101. * @param {string|string[]} elements - The CSS selector for the elements to toggle.
  102. * @param {object} root - The CSS selector for the elements to toggle.
  103. * @deprecated Since Moodle 5.0 See {@link module:core_editor/tiny/plugins/media/helpers.hideElements}
  104. */
  105. export const hideElements = (elements, root) => {
  106. window.console.warn(`This function is deprecated.
  107. Please use core_editor/tiny/plugins/media/helpers.hideElements instead.`);
  108. Helpers.hideElements(elements, root);
  109. };
  110. /**
  111. * Checks if the given value is a percentage value.
  112. *
  113. * @param {string} value - The value to check.
  114. * @returns {boolean} True if the value is a percentage value, false otherwise.
  115. * @deprecated Since Moodle 5.0 See {@link module:core_editor/tiny/plugins/media/helpers.isPercentageValue}
  116. */
  117. export const isPercentageValue = (value) => {
  118. window.console.warn(`This function is deprecated.
  119. Please use core_editor/tiny/plugins/media/helpers.isPercentageValue instead.`);
  120. return Helpers.isPercentageValue(value);
  121. };