From cc87d6d4c834dadfeeef85b22ffffe5fb0d2afd8 Mon Sep 17 00:00:00 2001 From: fja-odoo Date: Mon, 24 Jun 2019 16:29:14 +0000 Subject: [PATCH] [FIX] website, *: fix wishlist animation * = website_sale, website_sale_wishlist The wishlist animation was not handling the affixed navbar and always referring to the main one. Now the animation will target the right navbar if we scroll down. When the navbar is duplicated, the ids of the tags were kept which is wrong and was producing bugs such as the wishlist button not showing up on the floating navbar on the first product added to the wishlist and the first issue. Now the id is removed from the clone and never used in JS code. Its only purpose is for the xpath of the wishlist button. When a product was added to the cart from the wishlist and the affixed navbar was displayed, the product was hidden before the animation was completed. This changed the height of the page and the animation went to the middle of the page instead of the button. This is now fixed too. task-2002122 closes odoo/odoo#34358 Signed-off-by: Quentin Smetz (qsm) --- addons/website/static/src/js/content/menu.js | 2 +- addons/website_sale/views/templates.xml | 2 +- .../static/src/js/website_sale_wishlist.js | 33 +++++++++++++++---- .../views/website_sale_wishlist_template.xml | 4 +-- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/addons/website/static/src/js/content/menu.js b/addons/website/static/src/js/content/menu.js index 1a16b828d09..9d3d5621f65 100644 --- a/addons/website/static/src/js/content/menu.js +++ b/addons/website/static/src/js/content/menu.js @@ -15,7 +15,7 @@ publicWidget.registry.affixMenu = publicWidget.Widget.extend({ var def = this._super.apply(this, arguments); var self = this; - this.$headerClone = this.$target.clone().addClass('o_header_affix affix').removeClass('o_affix_enabled'); + this.$headerClone = this.$target.clone().addClass('o_header_affix affix').removeClass('o_affix_enabled').removeAttr('id'); this.$headerClone.insertAfter(this.$target); this.$headers = this.$target.add(this.$headerClone); this.$dropdowns = this.$headers.find('.dropdown'); diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 457758900a4..66aa33feb91 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -72,7 +72,7 @@
  • +
  • My Cart diff --git a/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js b/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js index 5a899feb7ed..dce756d5bbb 100644 --- a/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js +++ b/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js @@ -11,7 +11,7 @@ var VariantMixin = require('sale.VariantMixin'); publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, { selector: '.oe_website_sale', events: { - 'click #my_wish': '_onClickMyWish', + 'click .o_wsale_my_wish': '_onClickMyWish', 'click .o_add_wishlist, .o_add_wishlist_dyn': '_onClickAddWish', 'change input.product_id': '_onChangeVariant', 'change input.js_product_change': '_onChangeProduct', @@ -68,6 +68,23 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, // Private //-------------------------------------------------------------------------- + /** + * Gets the element in the navbar currently displayed. + * Depending on the scroll position, it could either be the one in the main + * top bar or the one in the affixed navbar. + * + * @private + * @param {string} selector + * @returns {jQuery} + */ + _getNavBarButton: function (selector) { + var $affixedHeaderButton = $('header.affixed ' + selector); + if ($affixedHeaderButton.length) { + return $affixedHeaderButton; + } else { + return $('header ' + selector).first(); + } + }, /** * @private */ @@ -105,9 +122,10 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, product_id: productId, }, }).then(function () { + var $navButton = self._getNavBarButton('.o_wsale_my_wish'); self.wishlistProductIDs.push(productId); self._updateWishlistView(); - wSaleUtils.animateClone($('#my_wish'), $el.closest('form'), 25, 40); + wSaleUtils.animateClone($navButton, $el.closest('form'), 25, 40); }).guardedCatch(function () { $el.prop("disabled", false).removeClass('disabled'); }); @@ -121,16 +139,16 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, */ _updateWishlistView: function () { if (this.wishlistProductIDs.length > 0) { - $('#my_wish').show(); + $('.o_wsale_my_wish').show(); $('.my_wish_quantity').text(this.wishlistProductIDs.length); } else { - $('#my_wish').hide(); + $('.o_wsale_my_wish').hide(); } }, /** * @private */ - _removeWish: function (e, deferred_redirect){ + _removeWish: function (e, deferred_redirect) { var tr = $(e.currentTarget).parents('tr'); var wish = tr.data('wish-id'); var product = tr.data('product-id'); @@ -156,10 +174,11 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin, * @private */ _addOrMoveWish: function (e) { + var $navButton = this._getNavBarButton('.o_wsale_my_cart'); var tr = $(e.currentTarget).parents('tr'); var product = tr.data('product-id'); - $('#my_cart').removeClass('d-none'); - wSaleUtils.animateClone($('#my_cart'), tr, 25, 40); + $('.o_wsale_my_cart').removeClass('d-none'); + wSaleUtils.animateClone($navButton, tr, 25, 40); if ($('#b2b_wish').is(':checked')) { return this._addToCart(product, tr.find('add_qty').val() || 1); diff --git a/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml b/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml index d8f43248403..77ac50e7823 100644 --- a/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml +++ b/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml @@ -33,10 +33,10 @@