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); },