Skip to content

Commit

Permalink
Fix: Catch double click and tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Sep 25, 2024
1 parent 65c2c21 commit e8cb9c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
1 change: 0 additions & 1 deletion private/js/cms.dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ class CmsForm {
}

close(event) {
console.log(event);
if (!event || !this.dialog.contains(event.target)) {

if (this.cancel) {
Expand Down
27 changes: 14 additions & 13 deletions private/js/cms.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class CMSEditor {
wrapper = this._initInlineRichText(document.getElementsByClassName(plugin[0]), url, id);
if (wrapper) {
wrapper.dataset.cmsCsrfToken = this.CMS.config.csrf;
wrapper.dataset.onClose = plugin[1].onClose;
wrapper.dataset.cmsField = edit_fields;
wrapper.dataset.cmsType = (
generic_inline_fields[search_key] === 'HTMLFormField' ?
Expand All @@ -188,22 +187,21 @@ class CMSEditor {
// Catch CMS double click event if present, since double click is needed by Editor
this.observer.observe(wrapper);
if (this.CMS) {
this.CMS.$(wrapper).on('dblclick.cms-editor', function (event) {
// Remove django CMS core's double click event handler which opens an edit dialog
this.CMS.$(wrapper).off('dblclick.cms.plugin')
.on('dblclick.cms-editor', function (event) {
event.stopPropagation();
});
wrapper.addEventListener('focusin.cms-editor', () => {
this._highlightTextplugin(id);
}, true);
// Prevent tooltip on hover
this.CMS.$(wrapper).off('pointerover.cms.plugin pointerout.cms.plugin')
.on('pointerover.cms-editor', function (event) {
this.CMS.API.Tooltip.displayToggle(false, event.target, '', id);
event.stopPropagation();
});
}

// Prevent tooltip on hover
document.addEventListener('pointerover.cms-editor', (event) => {
// use time out to let other event handlers (CMS' !) run first.
setTimeout(function () {
// do not show tooltip on inline editing text fields.
this.CMS.API.Tooltip.displayToggle(false, event.target, '', id);
}, 0);
});
}
}
}, this);
Expand Down Expand Up @@ -397,6 +395,11 @@ class CMSEditor {
}
return; // No databridge to evaluate
}
if (this.CMS) {
// Success:
// Remove an error message from a previous save attempt
this.CMS.API.Messages.close();
}
const script = dom.querySelector('script#data-bridge');
el.dataset.changed = 'false';
if (script && script.textContent.length > 2) {
Expand Down Expand Up @@ -428,9 +431,7 @@ class CMSEditor {
}
window.console.error(error.message);
});
return el.dataset.changed === 'false';
}
return true;
}

// CMS Editor: addPluginForm
Expand Down
23 changes: 13 additions & 10 deletions private/js/cms.texteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class CmsTextEditor {
this.plugin_id = parseInt(id_split[id_split.length-1]);
this.options = options;
this.events = {};
this.save = (el) => {
return save_callback(el);
};
this.save = save_callback;
this.init();
}

Expand Down Expand Up @@ -62,13 +60,18 @@ class CmsTextEditor {
}

_blur (e) {
const success = this.save(e.target);
console.log(success);
if (!success) {
e.target.innerText = this.options.undo;
e.target.dataset.changed = 'false';
e.target.focus();
}
this.save(e.target, (el, response) => {
console.log("timer set");
console.log(response);
setTimeout(() => {
console.log(e.target);
if (e.target.dataset.changed === 'true') {
e.target.innerText = this.options.undo;
e.target.dataset.changed = 'false';
e.target.focus();
}
}, 100);
});
}

_paste (e) {
Expand Down

0 comments on commit e8cb9c8

Please sign in to comment.