Skip to content

Commit

Permalink
fix: Better django CMS 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Oct 7, 2024
1 parent b1e0cc4 commit 3007027
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

0.3.2 (07-10-2024)
==================

* fix: Improve inline editing experience for django CMS v3


0.3.1 (02-10-2024)
==================

Expand Down
2 changes: 1 addition & 1 deletion djangocms_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
9. Publish the release when ready
10. Github actions will publish the new package to pypi
"""
__version__ = "0.3.1"
__version__ = "0.3.2"
33 changes: 16 additions & 17 deletions private/js/cms.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class CMSEditor {

if (this.CMS) {
// Only needs to happen on the main window.
console.log("Refresh established");
this.CMS.$(window).on('cms-content-refresh', () => {
if (document.querySelector('template.cms-plugin')) {
// django CMS core does not wrap newly inserted inline editable fields
Expand Down Expand Up @@ -153,8 +152,6 @@ class CMSEditor {
// no plugins -> no inline editors
return;
}
console.log("Init inline editors");
const plugins = this.CMS._plugins;

this.observer = this.observer || new IntersectionObserver( (entries) => {
entries.forEach((entry) => {
Expand All @@ -172,7 +169,7 @@ class CMSEditor {
generic_inline_fields = JSON.parse(generic_inline_fields.textContent || '{}');
}

plugins.forEach(function (plugin) {
this.CMS._plugins.forEach(function (plugin) {
if (plugin[1].type === 'plugin' || plugin[1].type === 'generic') {
// Either plugin or frontend editable element
const url = plugin[1].urls.edit_plugin;
Expand Down Expand Up @@ -256,10 +253,6 @@ class CMSEditor {
wrapper = document.createElement('div');
wrapper.classList.add('cms-editor-inline-wrapper', 'wrapped');
wrapper = this._wrapAll(elements, wrapper);
wrapper.classList.add('cms-plugin', 'cms-plugin-' + id);
for (let child of wrapper.children) {
child.classList.remove('cms-plugin', 'cms-plugin-' + id);
}
}
wrapper.dataset.cmsEditUrl = url;
return wrapper;
Expand Down Expand Up @@ -450,10 +443,17 @@ class CMSEditor {
return;
}
}
this.CMS.API.StructureBoard.handleEditPlugin(this.CMS.API.Helpers.dataBridge);
if (this.CMS.settings.version < "4") {
/* Reflect dirty flag in django CMS < 4 */
try {
/* For some reason, in v3 this fails if the structure board is not open */
this.CMS.API.StructureBoard.handleEditPlugin(this.CMS.API.Helpers.dataBridge);
} catch (e) {
console.error(e);
}
this._loadToolbar();
} else {
this.CMS.API.StructureBoard.handleEditPlugin(this.CMS.API.Helpers.dataBridge);
}
})
.catch(error => {
Expand All @@ -467,6 +467,7 @@ class CMSEditor {
});
}
window.console.error(error.message);
window.console.log(error.stack);
});
}
}
Expand Down Expand Up @@ -584,14 +585,12 @@ class CMSEditor {
// CMS Editor: loadToolbar
// Load the toolbar after saving for update
_loadToolbar () {
if (this.CMS) {
const $ = this.CMS.$;
this.CMS.API.StructureBoard._loadToolbar()
.done((newToolbar) => {
this.CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar'));
})
.fail(() => this.CMS.API.Helpers.reloadBrowser());
}
const $ = this.CMS.$;
this.CMS.API.StructureBoard._loadToolbar()
.done((newToolbar) => {
this.CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar'));
})
.fail(() => this.CMS.API.Helpers.reloadBrowser());
}

_highlightTextplugin (pluginId) {
Expand Down

0 comments on commit 3007027

Please sign in to comment.