@@ -88,7 +88,6 @@ class CMSEditor {
88
88
// CMS Editor: init
89
89
// Initialize a single editor
90
90
init ( el ) {
91
-
92
91
if ( ! el . id ) {
93
92
el . id = "cms-edit-" + Math . random ( ) . toString ( 36 ) . slice ( 2 , 9 ) ;
94
93
}
@@ -158,7 +157,7 @@ class CMSEditor {
158
157
const search_key = `${ generic_class [ 2 ] } -${ generic_class [ 3 ] } -${ edit_fields } ` ;
159
158
if ( generic_inline_fields [ search_key ] ) {
160
159
// Inline editable?
161
- wrapper = this . _initInlineRichText ( document . getElementsByClassName ( plugin [ 0 ] ) , url , plugin [ 0 ] ) ;
160
+ wrapper = this . _initInlineRichText ( document . querySelectorAll ( `. ${ plugin [ 0 ] } ` ) , url , plugin [ 0 ] ) ;
162
161
if ( wrapper ) {
163
162
wrapper . dataset . cmsCsrfToken = this . CMS . config . csrf ;
164
163
wrapper . dataset . cmsField = edit_fields ;
@@ -208,31 +207,6 @@ class CMSEditor {
208
207
} ) ;
209
208
}
210
209
211
- _initInlineRichText ( elements , url , cls ) {
212
- let wrapper ;
213
-
214
- if ( elements . length > 0 ) {
215
- if ( elements . length === 1 && (
216
- elements [ 0 ] . tagName === 'DIV' || // Single wrapping div
217
- elements [ 0 ] . tagName === 'CMS-PLUGIN' || // Single wrapping cms-plugin tag
218
- elements [ 0 ] . classList . contains ( 'cms-editor-inline-wrapper' ) // already wrapped
219
- ) ) {
220
- // already wrapped?
221
- wrapper = elements [ 0 ] ;
222
- wrapper . classList . add ( 'cms-editor-inline-wrapper' ) ;
223
- } else { // no, wrap now!
224
- wrapper = document . createElement ( 'div' ) ;
225
- wrapper . classList . add ( 'cms-editor-inline-wrapper' , 'wrapped' ) ;
226
- wrapper . classList . add ( 'cms-plugin' , cls , 'cms-plugin-start' , 'cms-plugin-end' ) ;
227
- wrapper = this . _wrapAll ( elements , wrapper ) ;
228
- }
229
- wrapper . dataset . cmsEditUrl = url ;
230
- return wrapper ;
231
- }
232
- // No elements found
233
- return undefined ;
234
- }
235
-
236
210
_createRTE ( el ) {
237
211
const settings = this . getSettings ( el ) ;
238
212
// Element options overwrite
@@ -673,20 +647,44 @@ class CMSEditor {
673
647
}
674
648
}
675
649
650
+ _initInlineRichText ( elements , url , cls ) {
651
+ let wrapper ;
652
+
653
+ if ( elements . length > 0 ) {
654
+ if ( elements . length === 1 && (
655
+ elements [ 0 ] . tagName === 'DIV' || // Single wrapping div
656
+ elements [ 0 ] . tagName === 'CMS-PLUGIN' || // Single wrapping cms-plugin tag
657
+ elements [ 0 ] . classList . contains ( 'cms-editor-inline-wrapper' ) // already wrapped
658
+ ) ) {
659
+ // already wrapped?
660
+ wrapper = elements [ 0 ] ;
661
+ wrapper . classList . add ( 'cms-editor-inline-wrapper' ) ;
662
+ } else { // no, wrap now!
663
+ wrapper = document . createElement ( 'div' ) ;
664
+ wrapper . classList . add ( 'cms-editor-inline-wrapper' , 'wrapped' ) ;
665
+ wrapper . classList . add ( 'cms-plugin' , cls , 'cms-plugin-start' , 'cms-plugin-end' ) ;
666
+ wrapper = this . _wrapAll ( elements , wrapper , cls ) ;
667
+ }
668
+ wrapper . dataset . cmsEditUrl = url ;
669
+ return wrapper ;
670
+ }
671
+ // No elements found
672
+ return undefined ;
673
+ }
674
+
676
675
// Wrap wrapper around nodes
677
676
// Just pass a collection of nodes, and a wrapper element
678
- _wrapAll ( nodes , wrapper ) {
677
+ _wrapAll ( nodes , wrapper , cls ) {
679
678
// Cache the current parent and previous sibling of the first node.
680
679
const parent = nodes [ 0 ] . parentNode ;
681
680
const previousSibling = nodes [ 0 ] . previousSibling ;
682
681
683
682
// Place each node in wrapper.
684
- // - If nodes is an array, we must increment the index we grab from
685
- // after each loop.
686
- // - If nodes is a NodeList, each node is automatically removed from
687
- // the NodeList when it is removed from its parent with appendChild.
688
- for ( let i = 0 ; nodes . length - i ; wrapper . firstChild === nodes [ 0 ] && i ++ ) {
689
- wrapper . appendChild ( nodes [ i ] ) ;
683
+ for ( const node of nodes ) {
684
+ // Remove class markers
685
+ node . classList . remove ( 'cms-plugin' , cls , 'cms-plugin-start' , 'cms-plugin-end' ) ;
686
+ // ... and add to wrapper
687
+ wrapper . appendChild ( node ) ;
690
688
}
691
689
692
690
// Place the wrapper just after the cached previousSibling,
0 commit comments