[FIX] web_editor,website: top menu edition

Ensure all the `#top_menu` links are unremovable.
This prevent the editor to merge two `<a>` elements together
during delete commands.

task-2967314

closes odoo/odoo#99966

Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Sébastien Geelen (sge)
2022-09-13 10:30:20 +02:00
parent 04a352ea76
commit 992acd25e2
3 changed files with 9 additions and 0 deletions
@@ -220,6 +220,7 @@ export class OdooEditor extends EventTarget {
showEmptyElementHint: true,
defaultLinkAttributes: {},
plugins: [],
getUnremovableElements: () => [],
getReadOnlyAreas: () => [],
getContentEditableAreas: () => [],
getPowerboxElement: () => {
@@ -1947,6 +1948,9 @@ export class OdooEditor extends EventTarget {
for (const node of this.options.getReadOnlyAreas()) {
node.setAttribute('contenteditable', false);
}
for (const element of this.options.getUnremovableElements()) {
element.classList.add("oe_unremovable");
}
this.observerActive('_activateContenteditable');
}
_stopContenteditable() {
@@ -169,6 +169,7 @@ const Wysiwyg = Widget.extend({
controlHistoryFromDocument: this.options.controlHistoryFromDocument,
getContentEditableAreas: this.options.getContentEditableAreas,
getReadOnlyAreas: this.options.getReadOnlyAreas,
getUnremovableElements: this.options.getUnremovableElements,
defaultLinkAttributes: this.options.userGeneratedContent ? {rel: 'ugc' } : {},
allowCommandVideo: this.options.allowCommandVideo,
getYoutubeVideoElement: getYoutubeVideoElement,
@@ -278,6 +278,7 @@ export class WysiwygAdapterComponent extends ComponentAdapter {
bindLinkTool: true,
showEmptyElementHint: false,
getReadOnlyAreas: this._getReadOnlyAreas.bind(this),
getUnremovableElements: this._getUnremovableElements.bind(this),
...this.props.wysiwygOptions,
};
}
@@ -358,6 +359,9 @@ export class WysiwygAdapterComponent extends ComponentAdapter {
_getReadOnlyAreas() {
return [];
}
_getUnremovableElements () {
return this.$editable[0].querySelectorAll("#top_menu a:not(.oe_unremovable)");
}
/**
* This method provides support for the legacy event system.
* The supported events are defined in the prototype.