Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 4e3180c

Browse files
committed
feat: django CMS 5-compatible inline editing
1 parent 3ca0643 commit 4e3180c

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

djangocms_text_ckeditor/static/djangocms_text_ckeditor/js/cms.ckeditor.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
editors: {},
5959

6060

61-
init: function (element, mode, options, settings, callback) {
61+
init: function (element, mode, options, settings, callback) { // eslint-disable-line max-params
6262
var container = $(element);
6363

6464
container.data('ckeditor-initialized', true);
@@ -86,6 +86,7 @@
8686
'/ckeditor_plugins/cmsplugins/icons/cmsplugins.svg');
8787

8888
var editor;
89+
8990
if (mode === 'admin') {
9091
// render ckeditor
9192
editor = CKEDITOR.replace(container[0], this.options);
@@ -110,21 +111,25 @@
110111
return;
111112
}
112113

113-
CMS.CKEditor.observer = CMS.CKEditor.observer || new IntersectionObserver(function (entries, opts) {
114+
CMS.CKEditor.observer = CMS.CKEditor.observer || new IntersectionObserver(function (entries) {
114115
entries.forEach(function (entry) {
115116
if (entry.isIntersecting) {
116117
var target = $(entry.target);
117118
var plugin_id = target.data('cms_plugin_id');
118119
var url = target.data('cms_edit_url');
119120

120121
CMS.CKEditor.startInlineEditor(plugin_id, url);
122+
CMS.CKEditor.observer.unobserve(entry.target); // initialized; no more events needed
121123
}
122124
});
123125
}, {
124126
root: null,
125127
threshold: 0.05
126128
});
127129

130+
// disconnect first -- each visible element needs to trigger an event
131+
CMS.CKEditor.observer.disconnect();
132+
128133
CMS._plugins.forEach(function (plugin) {
129134
if (plugin[1].plugin_type === 'TextPlugin') {
130135
var url = plugin[1].urls.edit_plugin;
@@ -142,7 +147,8 @@
142147
elements
143148
.removeClass('cms-plugin')
144149
.removeClass('cms-plugin-' + id);
145-
wrapper.addClass('cms-plugin').addClass('cms-plugin-' + id);
150+
wrapper.addClass('cms-plugin').addClass('cms-plugin-' + id)
151+
.addClass('cms-plugin-start').addClass('cms-plugin-end');
146152
}
147153
wrapper.data('cms_edit_url', url);
148154
wrapper.data('cms_plugin_id', id);
@@ -176,10 +182,6 @@
176182
var settings = JSON.parse(document.getElementById('ck-cfg-' + plugin_id).textContent);
177183
var wrapper = $('.cms-plugin.cms-plugin-' + plugin_id);
178184

179-
if (wrapper.data('ckeditor-initialized')) {
180-
return;
181-
}
182-
183185
settings.plugin_id = plugin_id;
184186
settings.url = url;
185187
options = settings.options;
@@ -465,18 +467,18 @@
465467
});
466468
setTimeout(function () {
467469
CMS.Plugin._highlightPluginStructure(draggable.find('.cms-dragitem:first'),
468-
{successTimeout: 200, delay: 2000, seeThrough: true});
470+
{ successTimeout: 200, delay: 2000, seeThrough: true });
469471
}, HIGHLIGHT_TIMEOUT);
470472
}
471473
},
472474

473475
_initAll: function () {
474476
CMS.CKEditor.touchdevice = 'ontouchstart' in window || navigator.msMaxTouchPoints; // on touch device?
475-
if (!CMS.CKEditor.touchdevice) { // no inline editing on touch devices to not interfere with scrolling
477+
if (CMS.CKEditor.touchdevice) { // no inline editing on touch devices to not interfere with scrolling
478+
$('div.cms a.cms-btn.cms-edit-toggle').hide();
479+
} else {
476480
CMS.CKEditor.initInlineEditors();
477481
$('div.cms a.cms-btn.cms-edit-toggle').show();
478-
} else {
479-
$('div.cms a.cms-btn.cms-edit-toggle').hide();
480482
}
481483
CMS.CKEditor.initAdminEditors();
482484
},

0 commit comments

Comments
 (0)