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