From 911e2a5df9355b79c15b5dfbc3ab6e5cd5899176 Mon Sep 17 00:00:00 2001 From: "Pulinckx Pierre (PIPU)" Date: Thu, 8 Jun 2023 14:37:40 +0000 Subject: [PATCH] [FIX] website,* : fix map on jquery arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jquery find return an object instead of an array of element. When you map on this object, the first callback element is so the index and not the element. This commit fix wrong usages of .map() used with Jquery. closes odoo/odoo#124359 X-original-commit: b87dac213dcc8a197dc7c00245a392d1e4d86925 Signed-off-by: Géry Debongnie --- addons/web_unsplash/static/src/js/unsplash_beacon.js | 2 +- addons/website/static/src/js/utils.js | 2 +- addons/website/static/src/snippets/s_image_gallery/options.js | 2 +- addons/website_forum/static/src/js/website_forum.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/web_unsplash/static/src/js/unsplash_beacon.js b/addons/web_unsplash/static/src/js/unsplash_beacon.js index 53600aacb48..79de88ea9d1 100644 --- a/addons/web_unsplash/static/src/js/unsplash_beacon.js +++ b/addons/web_unsplash/static/src/js/unsplash_beacon.js @@ -10,7 +10,7 @@ publicWidget.registry.UnsplashBeacon = publicWidget.Widget.extend({ * @override */ start: function () { - var unsplashImages = this.$('img[src*="/unsplash/"]').map((img) => { + var unsplashImages = Array.from(this.$('img[src*="/unsplash/"]')).map((img) => { // get image id from URL (`http://www.domain.com:1234/unsplash/xYdf5feoI/lion.jpg` -> `xYdf5feoI`) return img.src.split('/unsplash/')[1].split('/')[0]; }); diff --git a/addons/website/static/src/js/utils.js b/addons/website/static/src/js/utils.js index 778c38d83c3..6b4dfd84f62 100644 --- a/addons/website/static/src/js/utils.js +++ b/addons/website/static/src/js/utils.js @@ -123,7 +123,7 @@ function autocompleteWithPages(self, $input, options) { * @param {jQuery} [$excluded] */ function onceAllImagesLoaded($element, $excluded) { - var defs = $element.find('img').addBack('img').map(img => { + var defs = Array.from($element.find("img").addBack("img")).map((img) => { if (img.complete || $excluded && ($excluded.is(img) || $excluded.has(img).length)) { return; // Already loaded } diff --git a/addons/website/static/src/snippets/s_image_gallery/options.js b/addons/website/static/src/snippets/s_image_gallery/options.js index 71243d3a0ea..db5cd4bca50 100644 --- a/addons/website/static/src/snippets/s_image_gallery/options.js +++ b/addons/website/static/src/snippets/s_image_gallery/options.js @@ -278,7 +278,7 @@ options.registry.gallery = options.Class.extend({ */ slideshow: function () { const imageEls = this._getImages(); - const images = imageEls.map((img) => ({ + const images = Array.from(imageEls).map((img) => ({ // Use getAttribute to get the attribute value otherwise .src // returns the absolute url. src: img.getAttribute('src'), diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 25922139e89..afbe847d123 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -614,7 +614,7 @@ publicWidget.registry.websiteForumSpam = publicWidget.Widget.extend({ _onMarkSpamClick: function (ev) { var key = this.$('.modal .tab-pane.active').data('key'); var $inputs = this.$('.modal .tab-pane.active input.form-check-input:checked'); - var values = $inputs.map((o) => parseInt(o.value)); + var values = Array.from($inputs).map((o) => parseInt(o.value)); return this._rpc({model: 'forum.post', method: 'mark_as_offensive_batch', args: [this.spamIDs, key, values],