From 60414062b38e7518af893ed0378af9992ca0673b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 28 Jan 2014 14:08:51 +0100 Subject: [PATCH] [IMP] website snippet animation: replace binding method by data-selector instead of data-snippet-id bzr revid: chm@openerp.com-20140128130851-atd6d3dkcjoufo6b --- .../src/js/website.snippets.animation.js | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/addons/website/static/src/js/website.snippets.animation.js b/addons/website/static/src/js/website.snippets.animation.js index 7d3b84f2254..60c5aea49e2 100644 --- a/addons/website/static/src/js/website.snippets.animation.js +++ b/addons/website/static/src/js/website.snippets.animation.js @@ -3,21 +3,28 @@ var website = openerp.website; website.snippet = {}; + website.snippet.readyAnimation = []; website.snippet.start_animation = function () { - $("[data-snippet-id]").each(function() { - var $snipped_id = $(this); - if ( !$snipped_id.parents("#oe_snippets").length && - !$snipped_id.parent("body").length && - !$snipped_id.data("snippet-view") && - website.snippet.animationRegistry[$snipped_id.data("snippet-id")]) { - var snippet = new website.snippet.animationRegistry[$snipped_id.data("snippet-id")]($snipped_id); - $snipped_id.data("snippet-view", snippet); + for (var k in website.snippet.animationRegistry) { + var Animation = website.snippet.animationRegistry[k]; + var selector = "[data-snippet-id='"+k+"']"; + if (Animation.prototype.selector) { + selector += ", " + Animation.prototype.selector; } - }); + $(selector).each(function() { + var $snipped_id = $(this); + if ( !$snipped_id.parents("#oe_snippets").length && + !$snipped_id.parent("body").length && + !$snipped_id.data("snippet-view")) { + website.snippet.readyAnimation.push($snipped_id); + $snipped_id.data("snippet-view", new Animation($snipped_id)); + } + }); + } }; website.snippet.stop_animation = function () { - $("[data-snippet-id]").each(function() { + $(website.snippet.readyAnimation).each(function() { var $snipped_id = $(this); if ($snipped_id.data("snippet-view")) { $snipped_id.data("snippet-view").stop(); @@ -30,6 +37,7 @@ website.snippet.animationRegistry = {}; website.snippet.Animation = openerp.Class.extend({ + selector: false, $: function () { return this.$el.find.apply(this.$el, arguments); }, @@ -51,14 +59,15 @@ }, }); - website.snippet.animationRegistry.carousel = website.snippet.animationRegistry.slider = website.snippet.Animation.extend({ + selector: ".carousel", start: function () { this.$target.carousel({interval: 10000}); }, }); website.snippet.animationRegistry.parallax = website.snippet.Animation.extend({ + parallax: ".parallax", start: function () { var self = this; setTimeout(function () {self.set_values();});