theme.js 5.7 KB

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