odoo.define("theme_common.s_showcase_slider_frontend", function (require) { "use strict"; const dom = require('web.dom'); var publicWidget = require('web.public.widget'); publicWidget.registry.s_showcase_slider = publicWidget.Widget.extend({ selector: ".s_showcase_slider", start: function () { _.defer(this.bindEvents.bind(this)); // FIXME delayed to counter a web_editor bug which off all click event this.createPagination(); return this._super.apply(this, arguments); }, destroy: function () { this._super.apply(this, arguments); _.defer(this.unbindEvents.bind(this)); // FIXME delayed to counter a web_editor bug which off all click event this.destroyPagination(); this.$target.removeClass("active"); }, bindEvents: function () { // Enlarge image on click if not already enlarged this.$target.on("click.s_showcase_slider", ".s_ss_slider", (function (e) { if (this.$target.hasClass("active")) return; this.$target .addClass("active") .one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", (function () { dom.scrollTo(this.$target[0], { duration: 200, extraOffset: 70, }); this.$target.trigger("transitionIsFinished"); }).bind(this)); }).bind(this)); // Close the enlarged image on close icon click this.$target.on("click.s_showcase_slider", ".s_ss_close", (function (e) { this.$target.removeClass("active"); }).bind(this)); // Handle click navigation this.$target.on("click.s_showcase_slider", ".s_ss_prev", this.prevSlide.bind(this)); this.$target.on("click.s_showcase_slider", ".s_ss_next", this.nextSlide.bind(this)); this.$target.on("click.s_showcase_slider", ".s_ss_slider_pagination > li > a", (function (e) { e.preventDefault(); var $selectedDot = $(e.currentTarget).parent(); if ($selectedDot.hasClass("selected")) return; this.changeSlide($selectedDot.index()); }).bind(this)); // Keyboard slider navigation $(document).on("keyup.s_showcase_slider", (function (e) { if (!this.$target.hasClass("active")) return; switch (e.which) { case $.ui.keyCode.LEFT: this.prevSlide(); break; case $.ui.keyCode.RIGHT: this.nextSlide(); break; case $.ui.keyCode.ESCAPE: this.$target.removeClass("active"); break; } }).bind(this)); }, unbindEvents: function () { this.$target.off(".s_showcase_slider"); $(document).off(".s_showcase_slider"); }, createPagination: function () { // FIXME pagination should be saved with editor but keep this for compatibility this.$target.find(".s_ss_slider_pagination").remove(); // Remove saved-with-editor pagination this.$pagination = $("