odoo.define('website.snippets.animation', function (require) { 'use strict'; var ajax = require('web.ajax'); var core = require('web.core'); var base = require('web_editor.base'); var animation = require('web_editor.snippets.animation'); var qweb = core.qweb; function load_called_template () { var ids_or_xml_ids = _.uniq($("[data-oe-call]").map(function () {return $(this).data('oe-call');}).get()); if (ids_or_xml_ids.length) { ajax.jsonRpc('/website/multi_render', 'call', { 'ids_or_xml_ids': ids_or_xml_ids }).then(function (data) { for (var k in data) { var $data = $(data[k]).addClass('o_block_'+k); $("[data-oe-call='"+k+"']").each(function () { $(this).replaceWith($data.clone()); }); } }); } } base.ready().then(function () { load_called_template(); if ($(".o_gallery:not(.oe_slideshow)").size()) { // load gallery modal template ajax.loadXML('/website/static/src/xml/website.gallery.xml', qweb); } }); animation.registry.slider = animation.Class.extend({ selector: ".carousel", start: function () { this.$target.carousel(); }, stop: function () { this.$target.carousel('pause'); this.$target.removeData("bs.carousel"); }, }); animation.registry.parallax = animation.Class.extend({ selector: ".parallax", start: function () { _.defer((function () { this.set_values(); }).bind(this)); $(window).on("scroll.animation_parallax", _.throttle(this.on_scroll.bind(this), 10)) .on("resize.animation_parallax", _.debounce(this.set_values.bind(this), 500)); return this._super.apply(this, arguments); }, stop: function () { $(window).off(".animation_parallax"); }, set_values: function () { var self = this; this.speed = parseFloat(self.$target.attr("data-scroll-background-ratio") || 0); this.offset = 0; if (this.speed === 1 || this.$target.css("background-image") === "none") { this.$target.css("background-attachment", "fixed").css("background-position", "0px 0px"); return; } this.$target.css("background-attachment", "scroll"); var img = new Image(); img.onload = function () { var offset = 0; var padding = parseInt($(document.body).css("padding-top")); if (self.speed > 1) { var inner_offset = - self.$target.outerHeight() + this.height / this.width * document.body.clientWidth; var outer_offset = self.$target.offset().top - (document.body.clientHeight - self.$target.outerHeight()) - padding; offset = - outer_offset * self.speed + inner_offset; } else { offset = - self.$target.offset().top * self.speed; } self.offset = offset > 0 ? 0 : offset; self.on_scroll(); }; img.src = this.$target.css("background-image").replace(/url\(['"]*|['"]*\)/g, ""); }, on_scroll: function () { if (this.speed === 1) return; var top = this.offset + window.scrollY * this.speed; this.$target.css("background-position", "0px " + top + "px"); }, }); animation.registry.share = animation.Class.extend({ selector: ".oe_share", start: function () { var url_regex = /(\?(?:|.*&)(?:u|url|body)=)(.*?)(&|#|$)/; var title_regex = /(\?(?:|.*&)(?:title|text|subject)=)(.*?)(&|#|$)/; var url = encodeURIComponent(window.location.href); var title = encodeURIComponent($("title").text()); this.$("a").each(function () { var $a = $(this); $a.attr("href", function(i, href) { return href.replace(url_regex, function (match, a, b, c) { return a + url + c; }).replace(title_regex, function (match, a, b, c) { return a + title + c; }); }); if ($a.attr("target") && $a.attr("target").match(/_blank/i) && !$a.closest('.o_editable').length) { $a.on('click', function () { window.open(this.href,'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=550,width=600'); return false; }); } }); } }); animation.registry.media_video = animation.Class.extend({ selector: ".media_iframe_video", start: function () { // TODO: this code should be refactored to make more sense and be better // integrated with Odoo (this refactoring should be done in master). var def = this._super.apply(this, arguments); if (this.$target.children('iframe').length) { // There already is an