diff --git a/addons/website/static/src/css/snippets.css b/addons/website/static/src/css/snippets.css index 628689b78cf..35d78303aae 100644 --- a/addons/website/static/src/css/snippets.css +++ b/addons/website/static/src/css/snippets.css @@ -1,3 +1,13 @@ +/* add CSS for bootstrap dropdown multi level */ +.dropdown-submenu{position:relative;} +.dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;} +.dropdown-submenu:hover>.dropdown-menu{display:block;} +.dropdown-submenu>a:after{display:block;content:" ";float:right;width:0;height:0;border-color:transparent;border-style:solid;border-width:5px 0 5px 5px;border-left-color:#cccccc;margin-top:5px;margin-right:-10px;} +.dropdown-submenu:hover>a:after{border-left-color:#ffffff;} +.dropdown-submenu.pull-left{float:none;} +.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px;} + + /* .oe_snippet_demo .oe_page{ margin-top: 50px; @@ -208,14 +218,3 @@ min-width: 10px; } - -/* Custom CSS for snippets */ -.carousel.oe_small .carousel-inner { - height: 200px; -} -.carousel.oe_medium .carousel-inner { - height: 300px; -} -.carousel.oe_big .carousel-inner { - height: 450px; -} diff --git a/addons/website/static/src/css/website.css b/addons/website/static/src/css/website.css index c48d4fa9b2a..20a0968347a 100644 --- a/addons/website/static/src/css/website.css +++ b/addons/website/static/src/css/website.css @@ -246,6 +246,15 @@ footer { height: 100%; } +.carousel.oe_small .carousel-inner { + height: 200px; +} +.carousel.oe_medium .carousel-inner { + height: 300px; +} +.carousel.oe_big .carousel-inner { + height: 450px; +} .carousel .carousel-caption h1, .carousel .carousel-caption h2, .carousel .carousel-caption h3 { margin-top: 10px; margin-bottom: 10px; @@ -271,7 +280,7 @@ footer { background: rgba(0, 0, 0, 0.4); } .carousel .item.text_only .carousel-image { - display: none; + display: none !important; } .carousel .item.text_only .carousel-caption { left: 10%; @@ -291,6 +300,20 @@ footer { right: 50%; left: 10%; } +.carousel .carousel-control { + cursor: pointer; +} +.carousel .carousel-control span { + top: 50%; + position: absolute; + margin-top: -8px; +} +.carousel .carousel-control.left span { + left: 10px; +} +.carousel .carousel-control.right span { + right: 10px; +} /* ---- HOMEPAGE THEME CUSTOMIZATION ---- */ .dark { diff --git a/addons/website/static/src/css/website.sass b/addons/website/static/src/css/website.sass index 9f7efa2c416..2511cb55d9e 100644 --- a/addons/website/static/src/css/website.sass +++ b/addons/website/static/src/css/website.sass @@ -177,7 +177,14 @@ footer .carousel-inner .item height: 100% + .carousel + &.oe_small .carousel-inner + height: 200px + &.oe_medium .carousel-inner + height: 300px + &.oe_big .carousel-inner + height: 450px .carousel-caption h1, h2, h3 margin-top: 10px @@ -202,7 +209,7 @@ footer background: rgba(0, 0, 0, 0.4) .item.text_only .carousel-image - display: none + display: none !important .carousel-caption left: 10% right: 10% @@ -219,6 +226,16 @@ footer .carousel-image right: 50% left: 10% + .carousel-control + cursor: pointer + span + top: 50% + position: absolute + margin-top: -8px + &.left span + left: 10px + &.right span + right: 10px /* ---- HOMEPAGE THEME CUSTOMIZATION ---- */ diff --git a/addons/website/static/src/js/website.snippets.js b/addons/website/static/src/js/website.snippets.js index 3457fbb66e2..44e30d612e3 100644 --- a/addons/website/static/src/js/website.snippets.js +++ b/addons/website/static/src/js/website.snippets.js @@ -28,6 +28,7 @@ return this._super.apply(this, arguments); }, save: function () { + this.snippets.make_active(false); remove_added_snippet_id(); this._super(); }, @@ -106,9 +107,11 @@ var $ul = this.parent.$("#website-top-edit ul"); - var $button = $(openerp.qweb.render('website.snippets_button')) - .click(function () {self.$el.toggleClass("hidden");}) - .prependTo($ul); + var $button = $(openerp.qweb.render('website.snippets_button')).prependTo($ul); + $button.find('button').click(function () { + self.make_active(false); + self.$el.toggleClass("hidden"); + }); this.fetch_snippet_templates(); @@ -568,14 +571,6 @@ * Called after onBlur of snippet editor */ onBlurEdit : function () {}, - - /* getOptions - * Read data saved for your snippet animation. - */ - getOptions: function () { - var options = this.$el.data("snippet-options"); - return options ? JSON.parse(options) : undefined; - }, }); @@ -626,8 +621,7 @@ // activate drag and drop for the snippets in the snippet toolbar _drag_and_drop: function(){ var self = this; - var dropped = false; - var $move = this.$overlay.find(".oe_snippet_move"); + this.dropped = false; this.$overlay.draggable({ greedy: true, appendTo: 'body', @@ -639,49 +633,67 @@ }, helper: function() { var $clone = $(this).clone().css({width: "24px", height: "24px", border: 0}); - $clone.find(".oe_overlay_options >:not(.oe_snippet_move), .oe_handle").remove(); + $clone.find(".oe_overlay_options >:not(:contains(.oe_snippet_move)), .oe_handle").remove(); $clone.find(":not(.glyphicon)").css({position: 'absolute', top: 0, left: 0}); - return $clone.appendTo("body").removeClass("hidden"); + $clone.appendTo("body").removeClass("hidden"); + return $clone; }, - start: function(){ - self.parent.hide(); - self.parent.editor_busy = true; - self.$target.after("
"); + start: _.bind(self._drag_and_drop_start, self), + stop: _.bind(self._drag_and_drop_stop, self) + }); + }, + _drag_and_drop_after_insert_dropzone: function (){}, + _drag_and_drop_active_drop_zone: function ($zones){ + var self = this; + $zones.droppable({ + over: function(){ + $(".oe_drop_zone.hide").removeClass("hide"); + $(this).addClass("hide").first().after(self.$target); + self.dropped = true; + }, + out: function(){ + $(this).removeClass("hide"); self.$target.detach(); - self.$overlay.addClass("hidden"); - self.parent.activate_insertion_zones({ - siblings: self.$el ? self.$el.data('selector-siblings') : false, - children: self.$el ? self.$el.data('selector-children') : false, - vertical_children: self.$el ? self.$el.data('selector-vertical-children') : false, - }); - $("body").addClass('move-important'); - $('.oe_drop_zone').droppable({ - over: function(){ - $(".oe_drop_zone.hide").removeClass("hide"); - $(this).addClass("hide").first().after(self.$target); - dropped = true; - }, - out: function(){ - $(this).removeClass("hide"); - self.$target.detach(); - dropped = false; - }, - }); - }, - stop: function(){ - if (!dropped) { - $(".oe_drop_clone").after(self.$target); - } - self.$overlay.removeClass("hidden"); - $("body").removeClass('move-important'); - $('.oe_drop_zone').droppable('destroy').remove(); - $(".oe_drop_clone").remove(); - self.parent.editor_busy = false; - self.get_parent_block(); - setTimeout(function () {self.parent.create_overlay(self.$target);},0); + self.dropped = false; }, }); }, + _drag_and_drop_start: function (){ + var self = this; + self.parent.hide(); + self.parent.editor_busy = true; + self.size = { + width: self.$target.width(), + height: self.$target.height() + }; + self.$target.after(""); + self.$target.detach(); + self.$overlay.addClass("hidden"); + + self.parent.activate_insertion_zones({ + siblings: self.$el ? self.$el.data('selector-siblings') : false, + children: self.$el ? self.$el.data('selector-children') : false, + vertical_children: self.$el ? self.$el.data('selector-vertical-children') : false, + }); + + $("body").addClass('move-important'); + + self._drag_and_drop_after_insert_dropzone(); + self._drag_and_drop_active_drop_zone($('.oe_drop_zone')); + }, + _drag_and_drop_stop: function (){ + var self = this; + if (!self.dropped) { + $(".oe_drop_clone").after(self.$target); + } + self.$overlay.removeClass("hidden"); + $("body").removeClass('move-important'); + $('.oe_drop_zone').droppable('destroy').remove(); + $(".oe_drop_clone, .oe_drop_to_remove").remove(); + self.parent.editor_busy = false; + self.get_parent_block(); + setTimeout(function () {self.parent.create_overlay(self.$target);},0); + }, _clone: function () { var self = this; @@ -785,21 +797,6 @@ onBlur : function () { this.$overlay.removeClass('oe_active'); }, - - /* setOptions - * Use this method when you want to save some data for your snippet animation. - */ - setOptions: function (options) { - $target.attr("data-snippet-options", JSON.stringify(options)); - }, - - /* getOptions - * Read data saved for your snippet animation. - */ - getOptions: function () { - var options = this.$target.data("snippet-options"); - return options ? JSON.parse(options) : undefined; - }, }); @@ -931,6 +928,36 @@ return this.grid; }, + + _drag_and_drop_after_insert_dropzone: function(){ + var self = this; + var $zones = $(".row:has(> .oe_drop_zone)").each(function () { + var $row = $(this); + var width = $row.innerWidth(); + var pos = 0; + while (width > pos + self.size.width) { + var $last = $row.find("> .oe_drop_zone:last"); + $last.each(function () { + pos = $(this).position().left; + }); + if (width > pos + self.size.width) { + $row.append(""); + var $add_drop = $last.clone(); + $row.append($add_drop); + self._drag_and_drop_active_drop_zone($add_drop); + } + } + }); + }, + _drag_and_drop_start: function () { + this._super(); + this.$target.attr("class",this.$target.attr("class").replace(/\s*(col-lg-offset-|col-md-offset-)([0-9-]+)/g, '')); + }, + _drag_and_drop_stop: function () { + this.$target.addClass("col-md-offset-" + this.$target.prevAll(".oe_drop_to_remove").length); + this._super(); + }, + on_resize: function (compass, beginClass, current) { if (compass !== 'w') return; @@ -958,88 +985,150 @@ website.snippet.editorRegistry.carousel = website.snippet.editorRegistry.resize.extend({ build_snippet: function($target) { - var id = "myCarousel" + $("body .carousel").size(); + var id = "myCarousel" + $("body .carousel").length; $target.attr("id", id); $target.find(".carousel-control").attr("href", "#"+id); }, start : function () { this._super(); - this.$editor.find(".js_add").on('click', this, this.on_add); - this.$editor.find(".js_remove").on('click', this, this.on_remove); + this.$editor.find(".js_add").on('click', _.bind(this.on_add, this)); + this.$editor.find(".js_remove").on('click', _.bind(this.on_remove, this)); this.change_background(); this.change_style(); this.change_size(); + + // remove cke image seletor + this.$target.on('mousedown mouseup', '.carousel-inner .item > img', function (event) { + event.preventDefault(); + return false; + }); }, on_add: function (e) { e.preventDefault(); - var $inner = e.data.$target.find('.carousel-inner'); - var cycle = $inner.find('.item').size(); + this.$target.find('.carousel-control').removeClass("hidden"); + var $inner = this.$target.find('.carousel-inner'); + var cycle = $inner.find('.item').length; $inner.find('.item.active').clone().removeClass('active').appendTo($inner); - e.data.$target.carousel(cycle); + this.$target.carousel(cycle); + this.set_options_background(); + this.set_options_style(); }, on_remove: function (e) { e.preventDefault(); - var $inner = e.data.$target.find('.carousel-inner'); - if ($inner.find('.item').size() > 1) { + var $inner = this.$target.find('.carousel-inner'); + var nb = $inner.find('.item').length; + if (nb > 1) { $inner .find('.item.active').remove().end() .find('.item:first').addClass('active'); - e.data.$target.carousel(0); + this.$target.carousel(0); + this.set_options_background(); + this.set_options_style(); } + console.log(nb); + if (nb <= 1) { + this.$target.find('.carousel-control').addClass("hidden"); + } + }, + onFocus: function () { + this.set_options_background(); + this.set_options_style(); + this._super(); + }, + set_options_background: function () { + var $image = this.$target.find('.carousel-inner .item.active > img'); + var bg = $image.attr('src'); + var $ul = this.$editor.find('ul[name="carousel-background"]'); + $ul.find("li").removeClass("active"); + var selected = $ul.find('[data-value="' + bg + '"], [data-value="' + bg.replace(/.*:\/\/[^\/]+/, '') + '"]') + .addClass('active').length; + this.$editor.find('.oe_custom_bg b').val(selected ? "" : bg); }, change_background: function () { var self = this; - var bg = this.$target.find('.carousel-inner .item.active').css('background-image').replace(/url\((.*)\)/g, '$1'); - var selected = this.$editor.find('select[name="carousel-background"] option[value="'+bg+'"], select[name="carousel-background"] option[value="'+bg.replace(window.location.protocol+'//'+window.location.host, '')+'"]') - .prop('selected', true).length; - if (!selected) { - this.$editor.find('.carousel-background input').val(bg); - } + var $ul = this.$editor.find('ul[name="carousel-background"]'); + var $li = $ul.find("li"); - this.$editor.find('select[name="carousel-background"], input') - .on('click', function (event) {event.preventDefault(); return false;}) - .on('change', function () { - self.$target.find('.carousel-inner .item.active').css('background-image', 'url(' + $(this).val() + ')'); - $(this).next().val(""); + $li.on('click', function (event) { + $li.removeClass("active"); + $(this).addClass("active"); + self.$editor.find('input').val(""); + }) + .on('mouseover', function (event) { + if ($(this).data("value")) { + self.$target.find('.carousel-inner .item.active > img') + .attr('src', $(this).data("value")); + } + }) + .on('mouseout', function (event) { + self.$target.find('.carousel-inner .item.active > img') + .attr('src', $ul.find('li.active').data("value")); }); }, + set_options_style: function () { + var style = false; + var $el = this.$target.find('.carousel-inner .item.active'); + var $ul = this.$editor.find('ul[name="carousel-style"]'); + var $li = $ul.find("li"); + + if ($el.hasClass('text_only')) + style = 'text_only'; + if ($el.hasClass('image_text')) + style = 'image_text'; + if ($el.hasClass('text_image')) + style = 'text_image'; + + $ul.find('[data-value="' + style + '"]').addClass('active'); + }, change_style: function () { var self = this; - var style = false; - var el = this.$target.find('.carousel-inner .item.active'); - if (el.hasClass('text_only')) - style = 'text_only'; - if (el.hasClass('image_text')) - style = 'image_text'; - if (el.hasClass('text_image')) - style = 'text_image'; + var $ul = this.$editor.find('ul[name="carousel-style"]'); + var $li = $ul.find("li"); - this.$editor.find('select[name="carousel-style"] option[value="'+style+'"]').prop('selected', true); - - this.$editor.find('select[name="carousel-style"]').on('change', function(e) { - var $container = self.$target.find('.carousel-inner .item.active'); - $container.removeClass('image_text text_image text_only'); - $container.addClass($(e.currentTarget).val()); - }); + $li.on('click', function (event) { + $li.removeClass("active"); + $(this).addClass("active"); + }) + .on('mouseover', function (event) { + var $el = self.$target.find('.carousel-inner .item.active'); + $el.removeClass('image_text text_image text_only'); + $el.addClass($(event.currentTarget).data("value")); + }) + .on('mouseout', function (event) { + var $el = self.$target.find('.carousel-inner .item.active'); + $el.removeClass('image_text text_image text_only'); + $el.addClass($ul.find('li.active').data("value")); + }); }, change_size: function () { var self = this; + var $el = this.$target; - var size = 'big'; + var size = 'oe_big'; if (this.$target.hasClass('oe_small')) - size = 'small'; + size = 'oe_small'; else if (this.$target.hasClass('oe_medium')) - size = 'medium'; + size = 'oe_medium'; - this.$editor.find('select[name="carousel-size"] option[value="'+size+'"]').prop('selected', true); + var $ul = this.$editor.find('ul[name="carousel-size"]'); + var $li = $ul.find("li"); - this.$editor.find('select[name="carousel-size"]').on('change', function(e) { - self.$target - .removeClass('oe_big oe_small oe_medium') - .addClass("oe_" + $(e.currentTarget).val()); - }); + $ul.find('[data-value="' + size + '"]').addClass('active'); + + $li.on('click', function (event) { + $li.removeClass("active"); + $(this).addClass("active"); + }) + .on('mouseover', function (event) { + $el.removeClass('oe_big oe_small oe_medium'); + $el.addClass($(event.currentTarget).data("value")); + }) + .on('mouseout', function (event) { + $el.removeClass('oe_big oe_small oe_medium'); + $el.addClass($ul.find('li.active').data("value")); + }); } }); diff --git a/addons/website/static/src/xml/website.snippets.xml b/addons/website/static/src/xml/website.snippets.xml index 752aa66fc34..af562606bbe 100644 --- a/addons/website/static/src/xml/website.snippets.xml +++ b/addons/website/static/src/xml/website.snippets.xml @@ -111,55 +111,50 @@