@@ -449,24 +449,13 @@ class CMSEditor {
449
449
}
450
450
451
451
}
452
- const script = dom . querySelector ( 'script#data-bridge' ) ;
453
452
el . dataset . changed = 'false' ;
454
- if ( script && script . textContent . length > 2 ) {
455
- this . CMS . API . Helpers . dataBridge = JSON . parse ( script . textContent ) ;
456
- } else {
457
- const regex1 = / ^ \s * W i n d o w \. C M S \. A P I \. H e l p e r s \. d a t a B r i d g e \s = \s ( .* ?) ; $ / gmu. exec ( body ) ;
458
- const regex2 = / ^ \s * W i n d o w \. C M S \. A P I \. H e l p e r s \. d a t a B r i d g e \. s t r u c t u r e \s = \s ( .* ?) ; $ / gmu. exec ( body ) ;
459
- if ( regex1 && regex2 && this . CMS ) {
460
- this . CMS . API . Helpers . dataBridge = JSON . parse ( regex1 [ 1 ] ) ;
461
- this . CMS . API . Helpers . dataBridge . structure = JSON . parse ( regex2 [ 1 ] ) ;
462
- } else {
463
- // No databridge found: reload
464
- this . CMS . API . Helpers . reloadBrowser ( 'REFRESH_PAGE' ) ;
465
- return ;
466
- }
453
+ this . processDataBridge ( dom ) ;
454
+ if ( ! this . CMS . API . Helpers . dataBridge ) {
455
+ // No databridge found
456
+ this . CMS . API . Helpers . reloadBrowser ( 'REFRESH_PAGE' ) ;
457
+ return ;
467
458
}
468
- // Additional content for the page disrupts inline editing and needs to be removed
469
- delete this . CMS . API . Helpers . dataBridge . structure ?. content ;
470
459
471
460
if ( this . CMS . settings . version . startsWith ( '3.' ) ) {
472
461
/* Reflect dirty flag in django CMS < 4 */
@@ -497,6 +486,29 @@ class CMSEditor {
497
486
}
498
487
}
499
488
489
+ processDataBridge ( dom ) {
490
+ const script = dom . querySelector ( 'script#data-bridge' ) ;
491
+
492
+ if ( script && script . textContent . length > 2 ) {
493
+ this . CMS . API . Helpers . dataBridge = JSON . parse ( script . textContent ) ;
494
+ console . log ( "CMS.API.Helpers.dataBridge" , this . CMS . API . Helpers . dataBridge ) ;
495
+ } else {
496
+ const regex1 = / ^ \s * W i n d o w \. C M S \. A P I \. H e l p e r s \. d a t a B r i d g e \s = \s ( .* ?) ; $ / gmu. exec ( body ) ;
497
+ const regex2 = / ^ \s * W i n d o w \. C M S \. A P I \. H e l p e r s \. d a t a B r i d g e \. s t r u c t u r e \s = \s ( .* ?) ; $ / gmu. exec ( body ) ;
498
+
499
+ if ( regex1 && regex2 && this . CMS ) {
500
+ this . CMS . API . Helpers . dataBridge = JSON . parse ( regex1 [ 1 ] ) ;
501
+ this . CMS . API . Helpers . dataBridge . structure = JSON . parse ( regex2 [ 1 ] ) ;
502
+ console . log ( "CMS.API.Helpers.dataBridge by REGEX" , this . CMS . API . Helpers . dataBridge ) ;
503
+ } else {
504
+ // No databridge found
505
+ this . CMS . API . Helpers . dataBridge = { } ;
506
+ }
507
+ }
508
+ // Additional content for the page disrupts inline editing and needs to be removed
509
+ delete this . CMS . API . Helpers . dataBridge . structure ?. content ;
510
+ }
511
+
500
512
// CMS Editor: addPluginForm
501
513
// Get form for a new child plugin
502
514
addPluginForm ( plugin_type , iframe , el , onLoad , onSave ) {
@@ -554,19 +566,13 @@ class CMSEditor {
554
566
el . dataset . changed = 'true' ;
555
567
// Hook into the django CMS dataBridge to get the details of the newly created or saved
556
568
// plugin. For new plugins we need their id to get the content.
569
+
557
570
if ( ! this . CMS . API . Helpers . dataBridge ) {
558
- // The dataBridge sets a timer, so typically it will not yet be present
559
- setTimeout ( ( ) => {
560
- // Needed to update StructureBoard
561
- if ( onSave ) {
562
- onSave ( el , form , this . CMS . API . Helpers . dataBridge ) ;
563
- }
564
- } , 100 ) ;
565
- } else {
566
- // Needed to update StructureBoard
567
- if ( onSave ) {
568
- onSave ( el , form , this . CMS . API . Helpers . dataBridge ) ;
569
- }
571
+ this . processDataBridge ( form ) ;
572
+ }
573
+ // Needed to update StructureBoard
574
+ if ( onSave && this . CMS . API . Helpers . dataBridge ) {
575
+ onSave ( el , form , this . CMS . API . Helpers . dataBridge ) ;
570
576
}
571
577
// Do callback
572
578
} else if ( onLoad ) {
0 commit comments