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 8b5f988bbc9..8e99f888bbe 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -17,7 +17,7 @@ const Link = Widget.extend({ events: { 'input': '_onAnyChange', 'change': '_onAnyChange', - 'input input[name="url"]': '_onURLInput', + 'input input[name="url"]': '__onURLInput', 'change input[name="url"]': '_onURLInputChange', }, @@ -485,6 +485,23 @@ const Link = Widget.extend({ this._adaptPreview(); } }, + /** + * @todo Adapt in master: in stable _onURLInput was both used as an event + * handler responding to url input events + a private method called at the + * widget lifecycle start. Originally both points were to update the link + * tools/dialog UI. It was later wanted to actually update the DOM... but + * should only be done in event handler part. + * + * This allows to differentiate the event handler part. In master, we should + * take the opportunity to also update the `_updatePreview` concept which + * updates the "preview" of the original link dialog but actually updates + * the real DOM for the "new" link tools. + * + * @private + */ + __onURLInput: function () { + this._onURLInput(...arguments); + }, /** * @private */ @@ -495,10 +512,10 @@ const Link = Widget.extend({ let isLink = value.indexOf('@') < 0; this.$('input[name="is_new_window"]').closest('.row').toggleClass('d-none', !isLink); this.$('.o_strip_domain').toggleClass('d-none', value.indexOf(window.location.origin) !== 0); - this.options.wysiwyg && this.options.wysiwyg.odooEditor.historyPauseSteps('_onURLInput'); - this._adaptPreview(); - this.options.wysiwyg && this.options.wysiwyg.odooEditor.historyUnpauseSteps('_onURLInput'); }, + /** + * @private + */ _onURLInputChange: function () { this._adaptPreview(); this._savedURLInputOnDestroy = false; diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js index 3acf848e136..e09e4fa3c42 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_dialog.js @@ -160,6 +160,7 @@ const _DialogLinkWidget = Link.extend({ _onURLInput: function () { this._super(...arguments); this.$('#o_link_dialog_url_input').closest('.o_url_input').removeClass('o_has_error').find('.form-control, .form-select').removeClass('is-invalid'); + this._adaptPreview(); }, }); diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js index 927900c8f25..f126d3a6b10 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js @@ -425,6 +425,15 @@ const LinkTools = Link.extend({ this.options.wysiwyg.odooEditor.historyStep(); } }, + /** + * @override + */ + __onURLInput() { + this._super(...arguments); + this.options.wysiwyg.odooEditor.historyPauseSteps('_onURLInput'); + this._adaptPreview(); + this.options.wysiwyg.odooEditor.historyUnpauseSteps('_onURLInput'); + }, }); return LinkTools; diff --git a/addons/website/static/src/js/editor/widget_link.js b/addons/website/static/src/js/editor/widget_link.js index b1f887b89f5..9de80f11e25 100644 --- a/addons/website/static/src/js/editor/widget_link.js +++ b/addons/website/static/src/js/editor/widget_link.js @@ -5,9 +5,6 @@ var weWidgets = require('wysiwyg.widgets'); var wUtils = require('website.utils'); weWidgets.LinkTools.include({ - events: _.extend({}, weWidgets.LinkTools.prototype.events || {}, { - 'input input[name="url"]': '_onURLInput', - }), custom_events: _.extend({}, weWidgets.LinkTools.prototype.custom_events || {}, { website_url_chosen: '_onAutocompleteClose', }),