theme.es6.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @file
  3. * Provides theme functions for image Quick Edit's client-side HTML.
  4. */
  5. (function (Drupal) {
  6. /**
  7. * Theme function for validation errors of the Image in-place editor.
  8. *
  9. * @param {object} settings
  10. * Settings object used to construct the markup.
  11. * @param {string} settings.errors
  12. * Already escaped HTML representing error messages.
  13. *
  14. * @return {string}
  15. * The corresponding HTML.
  16. */
  17. Drupal.theme.quickeditImageErrors = function (settings) {
  18. return `<div class="quickedit-image-errors">${settings.errors}</div>`;
  19. };
  20. /**
  21. * Theme function for the dropzone element of the Image module's in-place
  22. * editor.
  23. *
  24. * @param {object} settings
  25. * Settings object used to construct the markup.
  26. * @param {string} settings.state
  27. * State of the upload.
  28. * @param {string} settings.text
  29. * Text to display inline with the dropzone element.
  30. *
  31. * @return {string}
  32. * The corresponding HTML.
  33. */
  34. Drupal.theme.quickeditImageDropzone = function (settings) {
  35. return `<div class="quickedit-image-dropzone ${settings.state}">` +
  36. ' <i class="quickedit-image-icon"></i>' +
  37. ` <span class="quickedit-image-text">${settings.text}</span>` +
  38. '</div>';
  39. };
  40. /**
  41. * Theme function for the toolbar of the Image module's in-place editor.
  42. *
  43. * @param {object} settings
  44. * Settings object used to construct the markup.
  45. * @param {bool} settings.alt_field
  46. * Whether or not the "Alt" field is enabled for this field.
  47. * @param {bool} settings.alt_field_required
  48. * Whether or not the "Alt" field is required for this field.
  49. * @param {string} settings.alt
  50. * The current value for the "Alt" field.
  51. * @param {bool} settings.title_field
  52. * Whether or not the "Title" field is enabled for this field.
  53. * @param {bool} settings.title_field_required
  54. * Whether or not the "Title" field is required for this field.
  55. * @param {string} settings.title
  56. * The current value for the "Title" field.
  57. *
  58. * @return {string}
  59. * The corresponding HTML.
  60. */
  61. Drupal.theme.quickeditImageToolbar = function (settings) {
  62. let html = '<form class="quickedit-image-field-info">';
  63. if (settings.alt_field) {
  64. html += `${' <div>' +
  65. ' <label for="alt" class="'}${settings.alt_field_required ? 'required' : ''}">${Drupal.t('Alternative text')}</label>` +
  66. ` <input type="text" placeholder="${settings.alt}" value="${settings.alt}" name="alt" ${settings.alt_field_required ? 'required' : ''}/>` +
  67. ' </div>';
  68. }
  69. if (settings.title_field) {
  70. html += `${' <div>' +
  71. ' <label for="title" class="'}${settings.title_field_required ? 'form-required' : ''}">${Drupal.t('Title')}</label>` +
  72. ` <input type="text" placeholder="${settings.title}" value="${settings.title}" name="title" ${settings.title_field_required ? 'required' : ''}/>` +
  73. ' </div>';
  74. }
  75. html += '</form>';
  76. return html;
  77. };
  78. }(Drupal));