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