From b339310d31c78b6282a797cd515cba29ee95db73 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Wed, 29 Jan 2020 09:53:49 +0000 Subject: [PATCH] [FIX] website: update links ids in duplicated carousel snippets (+ gallery snippet in carousel mode) Part of https://github.com/odoo/odoo/pull/44180 task-2162952 X-original-commit: 6237c59d607389cb0ed57694bb23b253f49805c8 --- .../static/src/js/editor/snippets.options.js | 9 ++++++- .../src/snippets/s_image_gallery/options.js | 25 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index eb67ca4f235..177f3dcc925 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -957,7 +957,14 @@ options.registry.Carousel = options.Class.extend({ const id = 'myCarousel' + Date.now(); this.$target.attr('id', id); this.$target.find('[data-target]').attr('data-target', '#' + id); - this.$target.find('[data-slide]').attr('href', '#' + id); + _.each(this.$target.find('[data-slide], [data-slide-to]'), function (el) { + var $el = $(el); + if ($el.attr('data-target')) { + $el.attr('data-target', '#' + id); + } else if ($el.attr('href')) { + $el.attr('href', '#' + id); + } + }); }, }); 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 cbbadb6ea50..e796b5a16d3 100644 --- a/addons/website/static/src/snippets/s_image_gallery/options.js +++ b/addons/website/static/src/snippets/s_image_gallery/options.js @@ -56,9 +56,13 @@ options.registry.gallery = options.Class.extend({ * @override */ onBuilt: function () { - var uuid = new Date().getTime(); - this.$target.find('.carousel').attr('id', 'slideshow_' + uuid); - this.$target.find('[data-target]').attr('data-target', '#slideshow_' + uuid); + this._adaptNavigationIDs(); + }, + /** + * @override + */ + onClone: function () { + this._adaptNavigationIDs(); }, /** * @override @@ -331,6 +335,21 @@ options.registry.gallery = options.Class.extend({ // Private //-------------------------------------------------------------------------- + /** + * @private + */ + _adaptNavigationIDs: function () { + var uuid = new Date().getTime(); + this.$target.find('.carousel').attr('id', 'slideshow_' + uuid); + _.each(this.$target.find('[data-slide], [data-slide-to]'), function (el) { + var $el = $(el); + if ($el.attr('data-target')) { + $el.attr('data-target', '#slideshow_' + uuid); + } else if ($el.attr('href')) { + $el.attr('href', '#slideshow_' + uuid); + } + }); + }, /** * @override */