Drupal investigation

theme.js 3.0KB

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