From ac170e8a8238a9b0aa468f83b11aabc4cd9493de Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Fri, 19 Jul 2019 14:50:15 +0000 Subject: [FIX] web_editor, website: stop snippet animations before cloning Before this commit, when a snippet was cloned, its animation was not destroyed first. The flow was: 1. Clone the snippet (DOM) - web_editor trigger `snippet_cloned` 2. Start cloned snippet animation - website listen `snippet_cloned` This was causing bugs, eg facebook snippet for which the animation is to create an iframe containing the facebook widget. When cloning this snippet, its iframe would be cloned to, then its animation would be started, creating another iframe. To fix such flows, the snippet cloning flow should be: 1. Strop the snippet animation 2. Clone the snippet (DOM) - web_editor trigger `snippet_cloned` 3. Start cloned snippet animation - website listen `snippet_cloned` 4. Restart the original snippet animation task-1951466 closes odoo/odoo#35029 Signed-off-by: Quentin Smetz (qsm) --- .../website/static/src/js/content/website_root.js | 1 + addons/website/static/src/js/menu/edit.js | 23 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'addons/website/static/src/js') diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index ab1de2ea357..dee89b8be1b 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -43,6 +43,7 @@ var WebsiteRoot = BodyManager.extend({ }), custom_events: _.extend({}, BodyManager.prototype.custom_events || {}, { animation_start_demand: '_onAnimationStartDemand', + animation_stop_demand: '_onAnimationStopDemand', ready_to_clean_for_save: '_onAnimationStopDemand', }), diff --git a/addons/website/static/src/js/menu/edit.js b/addons/website/static/src/js/menu/edit.js index c42e2196887..3b7803e8d56 100644 --- a/addons/website/static/src/js/menu/edit.js +++ b/addons/website/static/src/js/menu/edit.js @@ -17,6 +17,7 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ custom_events: _.extend({}, websiteNavbarData.WebsiteNavbarActionWidget.custom_events || {}, { content_will_be_destroyed: '_onContentWillBeDestroyed', content_was_recreated: '_onContentWasRecreated', + snippet_will_be_cloned: '_onSnippetWillBeCloned', snippet_cloned: '_onSnippetCloned', snippet_dropped: '_onSnippetDropped', }), @@ -111,9 +112,22 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ $target: ev.data.$target, }); }, + /** + * Called when a snippet is about to be cloned in the page. Notifies the + * WebsiteRoot that is should destroy the animations for this snippet. + * + * @private + * @param {OdooEvent} ev + */ + _onSnippetWillBeCloned: function (ev) { + this.trigger_up('animation_stop_demand', { + $target: ev.data.$target, + }); + }, /** * Called when a snippet is cloned in the page. Notifies the WebsiteRoot - * that is should start the animations for this snippet. + * that is should start the animations for this snippet and the snippet it + * was cloned from. * * @private * @param {OdooEvent} ev @@ -123,6 +137,13 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ editableMode: true, $target: ev.data.$target, }); + // TODO: remove in saas-12.5, undefined $origin will restart #wrapwrap + if (ev.data.$origin) { + this.trigger_up('animation_start_demand', { + editableMode: true, + $target: ev.data.$origin, + }); + } }, /** * Called when a snippet is dropped in the page. Notifies the WebsiteRoot -- cgit v1.2.3