[FIX] website: prevent console error when email in link tools
This commit prevents the editor to search for anchors when the link URL is an email. This way we prevent an error in the console. Related to runbot-18747 closes odoo/odoo#143791 X-original-commit: e767c7d4b0ccdeb016cf224b80e269afce4b3028 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Signed-off-by: Guillaume Dieleman (gdi) <gdi@odoo.com>
This commit is contained in:
@@ -53,32 +53,34 @@ patch(LinkTools.prototype, {
|
||||
_adaptPageAnchor() {
|
||||
const urlInputValue = this.$el.find('input[name="url"]').val();
|
||||
const $pageAnchor = this.$el.find('.o_link_dialog_page_anchor');
|
||||
const isFromWebsite = urlInputValue[0] === '/';
|
||||
const showAnchorSelector = urlInputValue[0] === '/';
|
||||
const $selectMenu = this.$el.find('we-selection-items[name="link_anchor"]');
|
||||
|
||||
if ($selectMenu.data("anchor-for") !== urlInputValue) { // avoid useless query
|
||||
$pageAnchor.toggleClass('d-none', !isFromWebsite);
|
||||
$pageAnchor.toggleClass('d-none', !showAnchorSelector);
|
||||
$selectMenu.empty();
|
||||
const always = () => {
|
||||
const anchor = `#${urlInputValue.split('#')[1]}`;
|
||||
let weTogglerText = '\u00A0';
|
||||
if (anchor) {
|
||||
const weButtonEls = $selectMenu[0].querySelectorAll('we-button');
|
||||
if (Array.from(weButtonEls).some(el => el.textContent === anchor)) {
|
||||
weTogglerText = anchor;
|
||||
if (showAnchorSelector) {
|
||||
const always = () => {
|
||||
const anchor = `#${urlInputValue.split('#')[1]}`;
|
||||
let weTogglerText = '\u00A0';
|
||||
if (anchor) {
|
||||
const weButtonEls = $selectMenu[0].querySelectorAll('we-button');
|
||||
if (Array.from(weButtonEls).some(el => el.textContent === anchor)) {
|
||||
weTogglerText = anchor;
|
||||
}
|
||||
}
|
||||
}
|
||||
$pageAnchor[0].querySelector('we-toggler').textContent = weTogglerText;
|
||||
};
|
||||
const urlWithoutHash = urlInputValue.split("#")[0];
|
||||
wUtils.loadAnchors(urlWithoutHash, this.$editable[0].ownerDocument.body).then(anchors => {
|
||||
for (const anchor of anchors) {
|
||||
const $option = $('<we-button class="dropdown-item">');
|
||||
$option.text(anchor);
|
||||
$option.data('value', anchor);
|
||||
$selectMenu.append($option);
|
||||
}
|
||||
}).finally(always);
|
||||
$pageAnchor[0].querySelector('we-toggler').textContent = weTogglerText;
|
||||
};
|
||||
const urlWithoutHash = urlInputValue.split("#")[0];
|
||||
wUtils.loadAnchors(urlWithoutHash, this.$editable[0].ownerDocument.body).then(anchors => {
|
||||
for (const anchor of anchors) {
|
||||
const $option = $('<we-button class="dropdown-item">');
|
||||
$option.text(anchor);
|
||||
$option.data('value', anchor);
|
||||
$selectMenu.append($option);
|
||||
}
|
||||
}).finally(always);
|
||||
}
|
||||
}
|
||||
$selectMenu.data("anchor-for", urlInputValue);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user