From 704755515a7b2a23b7cbb2124aea32354524de1f Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Thu, 5 Apr 2018 12:19:26 +0200 Subject: [PATCH] [FIX] website_sale: fix zoom wich was not always computed In some case, (many JS like runbot with all modules), the onload event was binded after that the image was loaded. So the JS code that make the zoom conditionnal was not executed. Now we apply the function on all images already loaded, or that will is loading Courtesy of @ged-odoo for help and review --- addons/website_sale/static/src/js/website_sale.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 8aacaf136ed..3f325be94ec 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -482,16 +482,22 @@ odoo.define('website_sale.website_sale', function (require) { } }); + function onImageLoaded(img, callback) { + $(img).on('load', function() { callback(); }); + if (img.complete) { + $(img).off('load'); +     callback(); + } + } + // Do not activate image zoom for mobile devices, since it might prevent users from scrolling the page if (!config.device.isMobile) { - var autoZoom = $('.ecom-zoomable').data('ecom-zoom-auto') || false, factorZoom = parseFloat($('.ecom-zoomable').data('ecom-zoom-factor')) || 1.5, attach = '#o-carousel-product'; _.each($('.ecom-zoomable img[data-zoom]'), function (el) { - var $img = $(el); - $img.load(function(e) { - var el = e.currentTarget; + onImageLoaded(el, function() { + var $img = $(el); if (!_.str.endsWith(el.src, el.dataset.zoomImage) || // if zoom-img != img el.naturalWidth >= $(attach).width() * factorZoom || el.naturalHeight >= $(attach).height() * factorZoom) { $img.zoomOdoo({event: autoZoom ? 'mouseenter' : 'click', attach: attach}); @@ -502,4 +508,5 @@ odoo.define('website_sale.website_sale', function (require) { }); }); } + });