From 69a27360c98aee3d97eb42e9a27a751311791e15 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Thu, 21 Sep 2023 15:57:42 +0200 Subject: [PATCH] [IMP] web_editor: omit protocol in URL input field Before this commit, when an existing link was edited with the LinkTools or LinkDialog, the URL input field omitted the "mailto:" part of the URL for email links, but displayed the protocol/scheme for http(s) links and phone numbers (tel: or tel://). This commit standardizes the behaviour of the referred input field such that the protocol/scheme for http(s), mailto and tel URLs are omitted, in order to have a cleaner UI. task-3516854 Part-of: odoo/odoo#136487 --- addons/web_editor/static/src/js/wysiwyg/widgets/link.js | 4 ++-- addons/website/static/tests/tours/link_tools.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js index 32a9d850d12..2d2d196d876 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -196,8 +196,8 @@ export class Link extends Component { */ _setUrl({ shouldFocus } = {}) { if (this.state.url) { - var match = /mailto:(.+)/.exec(this.state.url); - this.$el.find('input[name="url"]').val(match ? match[1] : this.state.url); + const protocolLessUrl = this.state.url.replace(/^(https?|mailto|tel):(\/\/)?/i, ''); + this.$el.find('input[name="url"]').val(protocolLessUrl); this._onURLInput(); this._savedURLInputOnDestroy = false; } diff --git a/addons/website/static/tests/tours/link_tools.js b/addons/website/static/tests/tours/link_tools.js index 8083f2f163a..151563f03ae 100644 --- a/addons/website/static/tests/tours/link_tools.js +++ b/addons/website/static/tests/tours/link_tools.js @@ -285,7 +285,7 @@ wTourUtils.registerWebsitePreviewTour('link_tools', { content: "Check Link tools URL input content is up-to-date", trigger: "#o_link_dialog_url_input", run() { - if (this.$anchor[0].value !== 'http://callmemaybe.com/shop') { + if (this.$anchor[0].value !== 'callmemaybe.com/shop') { throw new Error("Tour step failed"); } }