diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 5f721fd4805..1c208956624 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -622,6 +622,7 @@ var SnippetsMenu = Widget.extend({ * - Remove the 'contentEditable' attributes */ cleanForSave: function () { + this.trigger_up('ready_to_clean_for_save'); _.each(this.snippetEditors, function (snippetEditor) { snippetEditor.cleanForSave(); }); diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index aaa45e45c18..ab1de2ea357 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -43,8 +43,16 @@ var WebsiteRoot = BodyManager.extend({ }), custom_events: _.extend({}, BodyManager.prototype.custom_events || {}, { animation_start_demand: '_onAnimationStartDemand', + ready_to_clean_for_save: '_onAnimationStopDemand', }), + /** + * @constructor + */ + init: function () { + this._super.apply(this, arguments); + this.animations = []; + }, /** * @override */ @@ -108,6 +116,7 @@ var WebsiteRoot = BodyManager.extend({ * registry has been instantiated outside of the class and is simply * returned here. * + * @private * @override */ _getRegistry: function () { @@ -118,6 +127,7 @@ var WebsiteRoot = BodyManager.extend({ * `selector` key of one of the registered animations * (@see Animation.selector). * + * @private * @param {boolean} [editableMode=false] - true if the page is in edition mode * @param {jQuery} [$from] * only initialize the animations whose `selector` matches the @@ -138,9 +148,11 @@ var WebsiteRoot = BodyManager.extend({ var $snippet = $(el); var animation = $snippet.data('snippet-view'); if (animation) { + self.animations = _.without(self.animations, animation); animation.destroy(); } animation = new Animation(self, editableMode); + self.animations.push(animation); $snippet.data('snippet-view', animation); return animation.attachTo($snippet); }); @@ -148,6 +160,18 @@ var WebsiteRoot = BodyManager.extend({ }); return $.when.apply($, defs); }, + /** + * Destroys all animation instances. Especially needed before saving while + * in edition mode for example. + * + * @private + */ + _stopAnimations: function () { + _.each(this.animations, function (animation) { + animation.destroy(); + }); + this.animations = []; + }, //-------------------------------------------------------------------------- // Handlers @@ -165,6 +189,15 @@ var WebsiteRoot = BodyManager.extend({ .done(ev.data.onSuccess) .fail(ev.data.onFailure); }, + /** + * Called when the root is notified that the animations have to be + * stopped. + * + * @private + */ + _onAnimationStopDemand: function () { + this._stopAnimations(); + }, /** * @todo review * @private