diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-12-28 14:41:25 +0100 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2018-08-13 18:42:52 +0200 |
| commit | b56e647f2c540d34860cdee8a6adf0785ce3b8ef (patch) | |
| tree | 1991522bc27e7c2ee2b80236bd967590f75c16f8 /addons/website/static/src/js/content | |
| parent | 4dce6cc98b2b95a00249ac29245305e08f288e6c (diff) | |
[REF] web_editor, website: improve animations' restart
- Before this commit, when we asked to (re)start animations on an
element, we checked the animations to be started on the element
and started them after destroying the animations with the same
name which were already running on that element. This is in fact
not correct. Indeed, if an animation was running on element but
that the conditions that made the animation start are now gone,
asking to restart the animations on that element should destroy
the deprecated ones. (e.g. an animation "A" is to be started on
all elements which have a class "a", if we remove the class "a"
on an element then restart animations, the animation "A" should
be destroy). The implementation is in fact even simpler: when
asking a restart, a full stop is performed then a simple start.
Note: this does not need to be a fix as multiple animations on
a same element was recently introduced and the described case
never occurs with current features.
- When stopping the animations on an element, stops the animations
of all its descendants too.
- Add an helper method in the `SnippetOption` class to restart the
animations running on the `$target` element.
Diffstat (limited to 'addons/website/static/src/js/content')
| -rw-r--r-- | addons/website/static/src/js/content/website_root.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index 336ea822902..29163838f7a 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -137,27 +137,22 @@ var WebsiteRoot = BodyManager.extend({ */ _startAnimations: function (editableMode, $from) { var self = this; + editableMode = editableMode || false; if ($from === undefined) { $from = this.$('#wrapwrap'); } + + this._stopAnimations($from); + var defs = _.map(sAnimation.registry, function (Animation, animationName) { var selector = Animation.prototype.selector || ''; var $target = $from.find(selector).addBack(selector); var defs = _.map($target, function (el) { - var $snippet = $(el); - var animationIndex = _.findIndex(self.animations, function (animation) { - return animation.__name === animationName && $snippet[0] === animation.el; - }); - if (animationIndex >= 0) { - self.animations[animationIndex].destroy(); - self.animations.splice(animationIndex, 1); - } var animation = new Animation(self, editableMode); - animation.__name = animationName; self.animations.push(animation); - return animation.attachTo($snippet); + return animation.attachTo($(el)); }); return $.when.apply($, defs); }); @@ -168,12 +163,15 @@ var WebsiteRoot = BodyManager.extend({ * in edition mode for example. * * @private - * @param {jQuery} [$stopTarget] - * only stop the animations linked to the given element(s) + * @param {jQuery} [$from] + * only stop the animations linked to the given element(s) or one of + * its descendants */ - _stopAnimations: function ($stopTarget) { + _stopAnimations: function ($from) { var removedAnimations = _.map(this.animations, function (animation) { - if (!$stopTarget || $stopTarget.filter(animation.el).length) { + if (!$from + || $from.filter(animation.el).length + || $from.find(animation.el).length) { animation.destroy(); return animation; } |
