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 () { var self = this; setTimeout(function () {self.set_values();}); this.on_scroll = function () { var speed = parseFloat(self.$target.attr("data-scroll-background-ratio") || 0); if (speed == 1) return; var offset = parseFloat(self.$target.attr("data-scroll-background-offset") || 0); var top = offset + window.scrollY * speed; self.$target.css("background-position", "0px " + top + "px"); }; this.on_resize = function () { self.set_values(); }; $(window).on("scroll", this.on_scroll); $(window).on("resize", this.on_resize); }, stop: function () { $(window).off("scroll", this.on_scroll) .off("resize", this.on_resize); }, set_values: function () { var self = this; var speed = parseFloat(self.$target.attr("data-scroll-background-ratio") || 0); if (speed === 1 || this.$target.css("background-image") === "none") { this.$target.css("background-attachment", "fixed").css("background-position", "0px 0px"); return; } else { this.$target.css("background-attachment", "scroll"); } this.$target.attr("data-scroll-background-offset", 0); var img = new Image(); img.onload = function () { var offset = 0; var padding = parseInt($(document.body).css("padding-top")); if (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 * speed + inner_offset; } else { offset = - self.$target.offset().top * speed; } self.$target.attr("data-scroll-background-offset", offset > 0 ? 0 : offset); $(window).scroll(); }; img.src = this.$target.css("background-image").replace(/url\(['"]*|['"]*\)/g, ""); $(window).scroll(); } }); animation.registry.share = animation.Class.extend({ selector: ".oe_share", start: function () { var url = encodeURIComponent(window.location.href); var title = encodeURIComponent($("title").text()); this.$("a").each(function () { var $a = $(this); var url_regex = /\{url\}|%7Burl%7D/, title_regex = /\{title\}|%7Btitle%7D/; $a.attr("href", $(this).attr("href").replace(url_regex, url).replace(title_regex, title)); 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 () { if (!this.$target.has('.media_iframe_video_size')) { var editor = '