odoo.define('website.snippets.editor.gallery', function (require) { 'use strict'; var ajax = require('web.ajax'); var core = require('web.core'); var base = require('web_editor.base'); var widget = require('web_editor.widget'); var animation = require('web_editor.snippets.animation'); var options = require('web_editor.snippets.options'); var snippet_editor = require('web_editor.snippet.editor'); var _t = core._t; var qweb = core.qweb; /*-------------------------------------------------------------------------- Template files to load --------------------------------------------------------------------------*/ ajax.loadXML('/website/static/src/xml/website.gallery.xml', qweb); /*-------------------------------------------------------------------------- Gallery Snippet This is the snippet responsible for configuring the image galleries. Look at /website/views/snippets.xml for the available options ------------------------------------------------------------------------*/ options.registry.gallery = options.Class.extend({ start : function () { this._super(); this.bind_change(); var index = Math.max(_.map(this.$target.find("img").get(), function (img) { return img.dataset.index | 0; })); this.$target.find("img:not([data-index])").each(function () { index++; $(this).attr('data-index', index).data('index', index); }); this.$target.attr("contentEditable", false); this._temp_mode = this.$el.find("data-mode").data("mode"); this._temp_col = this.$el.find("data-columns").data("columns"); }, drop_and_build_snippet: function () { var uuid = new Date().getTime(); this.$target.find('.carousel').attr('id', 'slideshow_' + uuid); this.$target.find('[data-target]').attr('data-target', '#slideshow_' + uuid); }, styling : function (type, value) { var classes = this.$el.find('li[data-styling]').map(function () { return $(this).data('styling'); }).get().join(' '); this.$target.find("img").removeClass(classes).addClass(value); }, interval : function (type, value) { this.$target.find('.carousel:first').attr("data-interval", value); }, reapply : function () { var self = this, modes = [ 'o_nomode', 'o_grid', 'o_masonry', 'o_slideshow' ], classes = this.$target.attr("class").split(/\s+/); this.cancel_masonry(); modes.forEach(function (mode) { if (classes.indexOf(mode) != -1) { self.mode("reapply", mode.slice(2, Infinity)); return; } }); this.$target.attr("contentEditable", false); }, bind_change: function () { var self = this; return this.$target.find("img").off('saved').on('saved', function (event, img) { var $parent = $(img).parent(); $parent.addClass("saved_active"); var index = self.$target.find(".item.saved_active").index(); $parent.removeClass("saved_active"); self.$target.find(".carousel:first li[data-target]:eq("+index+")").css("background-image", "url("+$(img).attr("src")+")"); }); }, get_imgs: function () { var imgs = this.$target.find("img").addClass("img img-thumbnail img-responsive mb8 mt8").detach().get(); imgs.sort(function (a,b) { return $(a).data('index')-$(b).data('index'); }); return imgs; }, mode: function (type, value, $li) { if (type !== "reapply" && type !== "click" && this._temp_mode === value) { return; } this._temp_mode = value; this.cancel_masonry(); if (!value) value = 'nomode'; this[value](type); this.$target.removeClass('o_nomode o_masonry o_grid o_slideshow').addClass("o_"+value); this.bind_change(); }, replace: function ($content) { var $container = this.$target.find(".container:first"); $container.empty().append($content); return $container; }, nomode : function (type) { if (type !== "reapply" && !this.$target.attr('class').match(/o_grid|o_masonry|o_slideshow/)) return; var self = this, $row = $('
'), $imgs = $(this.get_imgs()); this.replace($row); $imgs.each(function () { var $wrap = $(this).wrap('