|
117 | 117 | toolbar.className += ' medium-editor-stalker-toolbar';
|
118 | 118 | }
|
119 | 119 |
|
120 |
| - toolbar.appendChild(this.createToolbarButtons()); |
| 120 | + this.createToolbarButtons().forEach(function (row) { |
| 121 | + toolbar.appendChild(row); |
| 122 | + }); |
121 | 123 |
|
122 | 124 | // Add any forms that extensions may have
|
123 | 125 | this.forEachExtension(function (extension) {
|
|
132 | 134 | },
|
133 | 135 |
|
134 | 136 | createToolbarButtons: function () {
|
| 137 | + var rows = []; |
| 138 | + |
| 139 | + if (Array.isArray(this.buttons[0])) { |
| 140 | + this.buttons.forEach(function (row, index) { |
| 141 | + rows.push(this.createToolbarButtonsRow(row, index)); |
| 142 | + }, this); |
| 143 | + } else { |
| 144 | + rows.push(this.createToolbarButtonsRow(this.buttons, 0)); |
| 145 | + } |
| 146 | + |
| 147 | + return rows; |
| 148 | + }, |
| 149 | + |
| 150 | + createToolbarButtonsRow: function (buttons, index) { |
135 | 151 | var ul = this.document.createElement('ul'),
|
136 | 152 | li,
|
137 | 153 | btn,
|
138 |
| - buttons, |
| 154 | + buttonEls, |
139 | 155 | extension,
|
140 | 156 | buttonName,
|
141 | 157 | buttonOpts;
|
142 | 158 |
|
143 | 159 | ul.id = 'medium-editor-toolbar-actions' + this.getEditorId();
|
| 160 | + if (index > 0) { |
| 161 | + // Preserve backward compatibility and add index only for extra rows |
| 162 | + ul.id += '-' + index; |
| 163 | + } |
144 | 164 | ul.className = 'medium-editor-toolbar-actions';
|
145 | 165 | ul.style.display = 'block';
|
146 | 166 |
|
147 |
| - this.buttons.forEach(function (button) { |
| 167 | + buttons.forEach(function (button) { |
148 | 168 | if (typeof button === 'string') {
|
149 | 169 | buttonName = button;
|
150 | 170 | buttonOpts = null;
|
|
169 | 189 | }
|
170 | 190 | }, this);
|
171 | 191 |
|
172 |
| - buttons = ul.querySelectorAll('button'); |
| 192 | + buttonEls = ul.querySelectorAll('button'); |
173 | 193 | if (buttons.length > 0) {
|
174 |
| - buttons[0].classList.add(this.firstButtonClass); |
175 |
| - buttons[buttons.length - 1].classList.add(this.lastButtonClass); |
| 194 | + buttonEls[0].classList.add(this.firstButtonClass); |
| 195 | + buttonEls[buttonEls.length - 1].classList.add(this.lastButtonClass); |
176 | 196 | }
|
177 | 197 |
|
178 | 198 | return ul;
|
|
202 | 222 | },
|
203 | 223 |
|
204 | 224 | getToolbarActionsElement: function () {
|
205 |
| - return this.getToolbarElement().querySelector('.medium-editor-toolbar-actions'); |
| 225 | + // For backward compatibility |
| 226 | + return this.getToolbarActionsElements()[0]; |
| 227 | + }, |
| 228 | + |
| 229 | + getToolbarActionsElements: function () { |
| 230 | + var els = this.getToolbarElement().querySelectorAll('.medium-editor-toolbar-actions'); |
| 231 | + return Array.prototype.slice.call(els); |
206 | 232 | },
|
207 | 233 |
|
208 | 234 | // Toolbar event handlers
|
|
315 | 341 |
|
316 | 342 | hideToolbarDefaultActions: function () {
|
317 | 343 | if (this.isToolbarDefaultActionsDisplayed()) {
|
318 |
| - this.getToolbarActionsElement().style.display = 'none'; |
| 344 | + this.getToolbarActionsElements().forEach(function (el) { |
| 345 | + el.style.display = 'none'; |
| 346 | + }); |
319 | 347 | }
|
320 | 348 | },
|
321 | 349 |
|
322 | 350 | showToolbarDefaultActions: function () {
|
323 | 351 | this.hideExtensionForms();
|
324 | 352 |
|
325 | 353 | if (!this.isToolbarDefaultActionsDisplayed()) {
|
326 |
| - this.getToolbarActionsElement().style.display = 'block'; |
| 354 | + this.getToolbarActionsElements().forEach(function (el) { |
| 355 | + el.style.display = 'block'; |
| 356 | + }); |
327 | 357 | }
|
328 | 358 |
|
329 | 359 | // Using setTimeout + options.delay because:
|
|
0 commit comments