Skip to content

Commit 398703a

Browse files
committed
Leanver event management
1 parent c0b205a commit 398703a

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

private/js/cms.editor.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CMSEditor {
3939

4040
if (this.mainWindow) {
4141
// Only needs to happen on the main window.
42-
this.mainWindow.addEventListener('load', () => {
42+
this.CMS.$(window).on('cms-content-refresh', () => {
4343
this._resetInlineEditors();
4444
});
4545
}
@@ -49,7 +49,7 @@ class CMSEditor {
4949
this._admin_selector = this._inline_admin_selector + ':not(.empty-form) ' + this._admin_selector;
5050
}
5151
this.initAll();
52-
});
52+
}, { once: true });
5353
}
5454

5555
// CMS Editor: init_all
@@ -92,10 +92,6 @@ class CMSEditor {
9292
if (!el.id) {
9393
el.id = "cms-edit-" + Math.random().toString(36).slice(2, 9);
9494
}
95-
if (el.id in this._editor_settings) {
96-
// Already initialized - happens when an inline editor is scrolled back into the viewport
97-
return;
98-
}
9995
// Create editor
10096
if (!el.dataset.cmsType || el.dataset.cmsType === 'TextPlugin' || el.dataset.cmsType === 'HTMLField') {
10197
this._createRTE(el);
@@ -122,14 +118,15 @@ class CMSEditor {
122118
this.observer = this.observer || new IntersectionObserver( (entries) => {
123119
entries.forEach((entry) => {
124120
if (entry.isIntersecting) {
125-
this.init(entry.target);
126121
this.observer.unobserve(entry.target); // Only init once
122+
this.init(entry.target);
127123
}
128124
}, this);
129125
}, {
130126
root: null,
131127
threshold: 0.05
132128
});
129+
this.observer.disconnect();
133130

134131
let generic_inline_fields = document.getElementById('cms-generic-inline-fields') || {};
135132
if (generic_inline_fields) {
@@ -495,7 +492,7 @@ class CMSEditor {
495492
}
496493
}
497494
// Additional content for the page disrupts inline editing and needs to be removed
498-
delete this.CMS.API.Helpers.dataBridge.structure.content;
495+
delete this.CMS.API.Helpers.dataBridge.structure?.content;
499496

500497
if (this.CMS.settings.version.startsWith('3.')) {
501498
/* Reflect dirty flag in django CMS < 4 */
@@ -632,7 +629,7 @@ class CMSEditor {
632629

633630
// CMS Editor: resetInlineEditors
634631
_resetInlineEditors () {
635-
this.initAll();
632+
this.initInlineEditors();
636633
}
637634

638635
// CMS Editor: loadToolbar

private/js/tiptap_plugins/cms.tiptap.toolbar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ const TiptapToolbar = {
216216
// If the user is currently editing a link, update the whole link
217217
editor.commands.extendMarkRange('link');
218218
}
219-
setTimeout(() => editor.chain().focus().openCmsForm('Link'), 0);
219+
setTimeout(() => editor.commands.openCmsForm('Link'), 0);
220220
},
221221
formAction: (editor, data) => {
222222
if (data) {
@@ -228,7 +228,7 @@ const TiptapToolbar = {
228228
editor.chain().focus().setLink(link).run();
229229
}
230230
},
231-
enabled: (editor) => editor.can().setLink({href: '#'}).run(),
231+
enabled: (editor) => editor.can().setLink({href: '#'}),
232232
active: (editor) => editor.isActive('link'),
233233
attributes: (editor) => {
234234
let attrs = editor.getAttributes('link');

0 commit comments

Comments
 (0)