diff --git a/addons/website/static/src/snippets/s_image_gallery/000.js b/addons/website/static/src/snippets/s_image_gallery/000.js index 7334d992f0e..45d9e624c64 100644 --- a/addons/website/static/src/snippets/s_image_gallery/000.js +++ b/addons/website/static/src/snippets/s_image_gallery/000.js @@ -67,9 +67,11 @@ const GalleryWidget = publicWidget.Widget.extend({ interval: milliseconds || 0, id: uniqueId("slideshow_"), })); + this.__onModalKeydown = this._onModalKeydown.bind(this); this.$modal.on('hidden.bs.modal', function () { $(this).hide(); $(this).siblings().filter('.modal-backdrop').remove(); // bootstrap leaves a modal-backdrop + this.removeEventListener("keydown", self.__onModalKeydown); $(this).remove(); self.$modal = undefined; }); @@ -78,11 +80,23 @@ const GalleryWidget = publicWidget.Widget.extend({ editableMode: false, $target: self.$modal.find('.modal-body.o_slideshow'), }); + this.addEventListener("keydown", self.__onModalKeydown); }); this.$modal.appendTo(document.body); const modalBS = new Modal(this.$modal[0], {keyboard: true, backdrop: true}); modalBS.show(); }, + _onModalKeydown(ev) { + if (ev.key === "ArrowLeft" || ev.key === "ArrowRight") { + const side = ev.key === "ArrowLeft" ? "prev" : "next"; + this.$modal[0].querySelector(`.carousel-control-${side}`).click(); + } + if (ev.key === "Escape") { + // If the user is connected as an editor, prevent the backend header + // from collapsing. + ev.stopPropagation(); + } + }, }); const GallerySliderWidget = publicWidget.Widget.extend({ diff --git a/addons/website/static/src/snippets/s_image_gallery/000.xml b/addons/website/static/src/snippets/s_image_gallery/000.xml index e78d7b1c5d3..12fd7657206 100644 --- a/addons/website/static/src/snippets/s_image_gallery/000.xml +++ b/addons/website/static/src/snippets/s_image_gallery/000.xml @@ -53,7 +53,7 @@ ======================================================================== --> -