theme.es6.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**
  2. * @file
  3. * Provides theme functions for all of Quick Edit's client-side HTML.
  4. */
  5. (function ($, Drupal) {
  6. /**
  7. * Theme function for a "backstage" for the Quick Edit module.
  8. *
  9. * @param {object} settings
  10. * Settings object used to construct the markup.
  11. * @param {string} settings.id
  12. * The id to apply to the backstage.
  13. *
  14. * @return {string}
  15. * The corresponding HTML.
  16. */
  17. Drupal.theme.quickeditBackstage = function (settings) {
  18. let html = '';
  19. html += `<div id="${settings.id}" />`;
  20. return html;
  21. };
  22. /**
  23. * Theme function for a toolbar container of the Quick Edit module.
  24. *
  25. * @param {object} settings
  26. * Settings object used to construct the markup.
  27. * @param {string} settings.id
  28. * the id to apply to the backstage.
  29. *
  30. * @return {string}
  31. * The corresponding HTML.
  32. */
  33. Drupal.theme.quickeditEntityToolbar = function (settings) {
  34. let html = '';
  35. html += `<div id="${settings.id}" class="quickedit quickedit-toolbar-container clearfix">`;
  36. html += '<i class="quickedit-toolbar-pointer"></i>';
  37. html += '<div class="quickedit-toolbar-content">';
  38. html += '<div class="quickedit-toolbar quickedit-toolbar-entity clearfix icon icon-pencil">';
  39. html += '<div class="quickedit-toolbar-label" />';
  40. html += '</div>';
  41. html += '<div class="quickedit-toolbar quickedit-toolbar-field clearfix" />';
  42. html += '</div><div class="quickedit-toolbar-lining"></div></div>';
  43. return html;
  44. };
  45. /**
  46. * Theme function for a toolbar container of the Quick Edit module.
  47. *
  48. * @param {object} settings
  49. * Settings object used to construct the markup.
  50. * @param {string} settings.entityLabel
  51. * The title of the active entity.
  52. * @param {string} settings.fieldLabel
  53. * The label of the highlighted or active field.
  54. *
  55. * @return {string}
  56. * The corresponding HTML.
  57. */
  58. Drupal.theme.quickeditEntityToolbarLabel = function (settings) {
  59. // @todo Add XSS regression test coverage in https://www.drupal.org/node/2547437
  60. return `<span class="field">${Drupal.checkPlain(settings.fieldLabel)}</span>${Drupal.checkPlain(settings.entityLabel)}`;
  61. };
  62. /**
  63. * Element defining a containing box for the placement of the entity toolbar.
  64. *
  65. * @return {string}
  66. * The corresponding HTML.
  67. */
  68. Drupal.theme.quickeditEntityToolbarFence = function () {
  69. return '<div id="quickedit-toolbar-fence" />';
  70. };
  71. /**
  72. * Theme function for a toolbar container of the Quick Edit module.
  73. *
  74. * @param {object} settings
  75. * Settings object used to construct the markup.
  76. * @param {string} settings.id
  77. * The id to apply to the toolbar container.
  78. *
  79. * @return {string}
  80. * The corresponding HTML.
  81. */
  82. Drupal.theme.quickeditFieldToolbar = function (settings) {
  83. return `<div id="${settings.id}" />`;
  84. };
  85. /**
  86. * Theme function for a toolbar toolgroup of the Quick Edit module.
  87. *
  88. * @param {object} settings
  89. * Settings object used to construct the markup.
  90. * @param {string} [settings.id]
  91. * The id of the toolgroup.
  92. * @param {string} settings.classes
  93. * The class of the toolgroup.
  94. * @param {Array} settings.buttons
  95. * See {@link Drupal.theme.quickeditButtons}.
  96. *
  97. * @return {string}
  98. * The corresponding HTML.
  99. */
  100. Drupal.theme.quickeditToolgroup = function (settings) {
  101. // Classes.
  102. const classes = (settings.classes || []);
  103. classes.unshift('quickedit-toolgroup');
  104. let html = '';
  105. html += `<div class="${classes.join(' ')}"`;
  106. if (settings.id) {
  107. html += ` id="${settings.id}"`;
  108. }
  109. html += '>';
  110. html += Drupal.theme('quickeditButtons', { buttons: settings.buttons });
  111. html += '</div>';
  112. return html;
  113. };
  114. /**
  115. * Theme function for buttons of the Quick Edit module.
  116. *
  117. * Can be used for the buttons both in the toolbar toolgroups and in the
  118. * modal.
  119. *
  120. * @param {object} settings
  121. * Settings object used to construct the markup.
  122. * @param {Array} settings.buttons
  123. * - String type: the type of the button (defaults to 'button')
  124. * - Array classes: the classes of the button.
  125. * - String label: the label of the button.
  126. *
  127. * @return {string}
  128. * The corresponding HTML.
  129. */
  130. Drupal.theme.quickeditButtons = function (settings) {
  131. let html = '';
  132. for (let i = 0; i < settings.buttons.length; i++) {
  133. const button = settings.buttons[i];
  134. if (!button.hasOwnProperty('type')) {
  135. button.type = 'button';
  136. }
  137. // Attributes.
  138. const attributes = [];
  139. const attrMap = settings.buttons[i].attributes || {};
  140. for (const attr in attrMap) {
  141. if (attrMap.hasOwnProperty(attr)) {
  142. attributes.push(attr + ((attrMap[attr]) ? `="${attrMap[attr]}"` : ''));
  143. }
  144. }
  145. html += `<button type="${button.type}" class="${button.classes}"` + ` ${attributes.join(' ')}>`;
  146. html += button.label;
  147. html += '</button>';
  148. }
  149. return html;
  150. };
  151. /**
  152. * Theme function for a form container of the Quick Edit module.
  153. *
  154. * @param {object} settings
  155. * Settings object used to construct the markup.
  156. * @param {string} settings.id
  157. * The id to apply to the toolbar container.
  158. * @param {string} settings.loadingMsg
  159. * The message to show while loading.
  160. *
  161. * @return {string}
  162. * The corresponding HTML.
  163. */
  164. Drupal.theme.quickeditFormContainer = function (settings) {
  165. let html = '';
  166. html += `<div id="${settings.id}" class="quickedit-form-container">`;
  167. html += ' <div class="quickedit-form">';
  168. html += ' <div class="placeholder">';
  169. html += settings.loadingMsg;
  170. html += ' </div>';
  171. html += ' </div>';
  172. html += '</div>';
  173. return html;
  174. };
  175. }(jQuery, Drupal));