From 3b4eeee5ca42fcabf21a19ae6f0c035d5ae5d0bb Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 15 Oct 2018 13:20:29 +0000 Subject: [PATCH] [FIX] website: restore carousel item behavior The animation that made all the carousel items have the same height automatically was broken. This commit fixes it and improves its behavior during edition. closes odoo/odoo#27801 --- .../src/js/content/snippets.animation.js | 57 +++++++++++++------ .../static/src/js/editor/snippets.options.js | 4 ++ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js index 99678b34e93..2833e5b5318 100644 --- a/addons/website/static/src/js/content/snippets.animation.js +++ b/addons/website/static/src/js/content/snippets.animation.js @@ -426,27 +426,16 @@ var registry = {}; registry.slider = Animation.extend({ selector: '.carousel', + edit_events: { + 'slid.bs.carousel': '_onEditionSlide', + }, /** * @override */ start: function () { if (!this.editableMode) { - var maxHeight = 0; - var $items = this.$('.item'); - _.each($items, function (el) { - var $item = $(el); - var isActive = $item.hasClass('active'); - $item.addClass('active'); - var height = $item.outerHeight(); - if (height > maxHeight) { - maxHeight = height; - } - $item.toggleClass('active', isActive); - }); - _.each($items, function (el) { - $(el).css('min-height', maxHeight); - }); + this._computeHeights(); } this.$target.carousel(); return this._super.apply(this, arguments); @@ -458,10 +447,46 @@ registry.slider = Animation.extend({ this._super.apply(this, arguments); this.$target.carousel('pause'); this.$target.removeData('bs.carousel'); - _.each(this.$('.item'), function (el) { + _.each(this.$('.carousel-item'), function (el) { $(el).css('min-height', ''); }); }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + */ + _computeHeights: function () { + var maxHeight = 0; + var $items = this.$('.carousel-item'); + _.each($items, function (el) { + var $item = $(el); + var isActive = $item.hasClass('active'); + $item.addClass('active'); + var height = $item.outerHeight(); + if (height > maxHeight) { + maxHeight = height; + } + $item.toggleClass('active', isActive); + }); + _.each($items, function (el) { + $(el).css('min-height', maxHeight); + }); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + _onEditionSlide: function () { + this._computeHeights(); + }, }); registry.parallax = Animation.extend({ diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 55142cea2ca..13532104449 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -247,6 +247,10 @@ options.registry.carousel = options.Class.extend({ } }); _.defer(function () { + self.trigger_up('animation_start_demand', { + editableMode: true, + $target: self.$target, + }); self.$target.carousel(index > 0 ? --index : cycle); }); }