From 7c2d3a871f40c937bff43d692161fd62741a99cc Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 31 Jul 2013 17:05:11 +0200 Subject: [PATCH 1/3] [IMP] website: carousel edition bzr revid: chm@openerp.com-20130731150511-8wfza72kb6lynmor --- addons/website/static/src/css/snippets.css | 9 ++- addons/website/static/src/js/website.js | 71 ++++++---------------- addons/website/static/src/xml/website.xml | 14 ++--- addons/website/views/views.xml | 5 ++ 4 files changed, 33 insertions(+), 66 deletions(-) diff --git a/addons/website/static/src/css/snippets.css b/addons/website/static/src/css/snippets.css index e909c1ddb01..78e9162c332 100644 --- a/addons/website/static/src/css/snippets.css +++ b/addons/website/static/src/css/snippets.css @@ -177,5 +177,10 @@ } */ - - +.carousel > .css_carousel_options { + cursor: pointer; + position: absolute; + white-space: nowrap; + z-index: 1; + display: none; +} \ No newline at end of file diff --git a/addons/website/static/src/js/website.js b/addons/website/static/src/js/website.js index 21d8b426ec9..4b50728aeeb 100644 --- a/addons/website/static/src/js/website.js +++ b/addons/website/static/src/js/website.js @@ -1,5 +1,6 @@ openerp.website = function(instance) { var _lt = instance.web._lt; +var QWeb = instance.web.qweb; instance.website.EditorBar = instance.web.Widget.extend({ template: 'Website.EditorBar', events: { @@ -356,60 +357,24 @@ instance.website.RTE = instance.web.Widget.extend({ // TODO clean snippet_carousel: function () { var self = this; - $carousels = $("
"); - $carousels.css({'position': 'absolute', 'top': 0, 'white-space': 'nowrap'}); - $carousels.insertAfter(self.$el); + $('.carousel .js_carousel_options .label').on('click', function (e) { + e.preventDefault(); + var $button = $(e.currentTarget) + var $c = $button.parents(".carousel:first"); - $(".carousel").each(function() { - var $carousel = new instance.website.snippet.carousel(self, this); - $carousel.appendTo($carousels); + if($button.hasClass("js_add")) { + var cycle = $c.find(".carousel-inner .item").size(); + $c.find(".carousel-inner").append(QWeb.render("Website.Snipped.carousel")); + $c.carousel(cycle); + } + else { + var cycle = $c.find(".carousel-inner .item.active").remove(); + $c.find(".carousel-inner .item:first").addClass("active"); + $c.carousel(0); + self.trigger('change', self, null); + } }); - $(document).on("scroll", function () { - $carousels.css("top", (-self.$el.offset().top+2) + 'px'); - }); - } -}); - - -instance.website.snippet = {}; -instance.website.snippet.carousel = instance.web.Widget.extend({ - template: 'Website.Snipped.carousel', - events: { - 'click .add': 'add_page', - 'click .remove': 'remove_page', - }, - instances: [], - init: function (parent, carousel) { - this._super(parent); - this.parent = parent; - var index = instance.website.snippet.carousel.index || 0; - instance.website.snippet.carousel.index = index++; - this.index = index; - $(carousel).addClass("carousel-index-"+index); - this.offset = $(carousel).offset(); - }, - start: function () { - var self = this; - this.$el.css({position: 'absolute', top: this.offset.top+'px', left: this.offset.left+'px'}); - }, - destroy: function () { - return this._super(); - }, - get_carousel: function() { - return $(".carousel.carousel-index-"+this.index); - }, - add_page: function() { - var $c = this.get_carousel(); - var cycle = $c.find(".carousel-inner .item").size(); - $c.find(".carousel-inner").append(this.$(".item").clone()); - $c.carousel(cycle); - }, - remove_page: function() { - var $c = this.get_carousel(); - var cycle = $c.find(".carousel-inner .item.active").remove(); - $c.find(".carousel-inner .item:first").addClass("active"); - $c.carousel(0); - this.parent.trigger('change', this.parent, null); + $('.carousel .js_carousel_options').show(); } }); @@ -490,10 +455,8 @@ $(function(){ } event.preventDefault(); } - }); - instance.web.ActionRedirect = function(parent, action) { var url = $.deparam(window.location.href).url; if (url) { diff --git a/addons/website/static/src/xml/website.xml b/addons/website/static/src/xml/website.xml index 75d25616d87..941015fd0f5 100644 --- a/addons/website/static/src/xml/website.xml +++ b/addons/website/static/src/xml/website.xml @@ -19,16 +19,10 @@
-
- - -
-
-
-

Your New Banner Slide

-

With another convincing subtitle

-
-
+
+
+

Your New Banner Slide

+

With another convincing subtitle

diff --git a/addons/website/views/views.xml b/addons/website/views/views.xml index 2a4622f7226..94c2de11edb 100644 --- a/addons/website/views/views.xml +++ b/addons/website/views/views.xml @@ -204,6 +204,11 @@