From b9f8eb73e8175a3a956d0d5c1b79761bf2e2cd10 Mon Sep 17 00:00:00 2001 From: Guillaume-gdi Date: Thu, 23 Nov 2023 12:47:26 +0000 Subject: [PATCH] [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) Signed-off-by: Guillaume Dieleman (gdi) --- .../static/src/js/editor/widget_link.js | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/addons/website/static/src/js/editor/widget_link.js b/addons/website/static/src/js/editor/widget_link.js index af8f8a6d7cc..49effbbb248 100644 --- a/addons/website/static/src/js/editor/widget_link.js +++ b/addons/website/static/src/js/editor/widget_link.js @@ -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 = $(''); - $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 = $(''); + $option.text(anchor); + $option.data('value', anchor); + $selectMenu.append($option); + } + }).finally(always); + } } $selectMenu.data("anchor-for", urlInputValue); },