From a2e4c9b7e0ccf6a8299fcfd9d721450a0c58e3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 23 Aug 2013 10:27:12 +0200 Subject: [PATCH 1/7] [IMP] website: mutation snippets bzr revid: fva@openerp.com-20130823082712-sdcke0hy5yspszkb --- addons/website/static/src/css/editor.css | 10 ++ addons/website/static/src/css/editor.sass | 10 ++ addons/website/static/src/css/website.css | 7 +- addons/website/static/src/css/website.sass | 5 + addons/website/static/src/js/website.js | 122 ++++++++++++++++++--- addons/website/views/views.xml | 16 ++- 6 files changed, 148 insertions(+), 22 deletions(-) diff --git a/addons/website/static/src/css/editor.css b/addons/website/static/src/css/editor.css index d446d14f3bc..782136e0e5d 100644 --- a/addons/website/static/src/css/editor.css +++ b/addons/website/static/src/css/editor.css @@ -144,3 +144,13 @@ .oe_drop_zone.oe_hover:before { border-top: dashed 2px rgba(116, 255, 161, 0.72); } + +.oe_hover_zone { + position: absolute; + background: rgba(153, 0, 255, 0.17); + border-radius: 3px; +} +.oe_hover_zone.oe_hover { + background: rgba(0, 255, 133, 0.22); + z-index: 100000; +} diff --git a/addons/website/static/src/css/editor.sass b/addons/website/static/src/css/editor.sass index f7ce999257e..322f182e0b5 100644 --- a/addons/website/static/src/css/editor.sass +++ b/addons/website/static/src/css/editor.sass @@ -128,4 +128,14 @@ &.oe_hover:before border-top: dashed 2px rgba(116, 255, 161, 0.72) +.oe_hover_zone + position: absolute + background: rgba(153, 0, 255, 0.17) + border-radius: 3px + + &.oe_hover + background: rgba(0, 255, 133, 0.22) + z-index: 100000 + + diff --git a/addons/website/static/src/css/website.css b/addons/website/static/src/css/website.css index eea25bea19d..2ba763f402e 100644 --- a/addons/website/static/src/css/website.css +++ b/addons/website/static/src/css/website.css @@ -1,4 +1,3 @@ -@charset "utf-8"; /* THIS CSS FILE IS FOR WEBSITE THEMING CUSTOMIZATION ONLY * * css for editor buttons, openerp widget included in the website and other @@ -159,3 +158,9 @@ header.navbar-fixed-top { min-height: 300px; color: white; } + +.dark { + background: #eff8f8; + padding-top: 32px; + padding-bottom: 32px; +} diff --git a/addons/website/static/src/css/website.sass b/addons/website/static/src/css/website.sass index 13037deb2d7..0440a71624f 100644 --- a/addons/website/static/src/css/website.sass +++ b/addons/website/static/src/css/website.sass @@ -119,4 +119,9 @@ header.navbar-fixed-top min-height: 300px color: white +.dark + background: rgb(239, 248, 248) + padding-top: 32px + padding-bottom: 32px + diff --git a/addons/website/static/src/js/website.js b/addons/website/static/src/js/website.js index 620eab2a16b..725f6531b16 100644 --- a/addons/website/static/src/js/website.js +++ b/addons/website/static/src/js/website.js @@ -298,6 +298,34 @@ } }); + website.mutations = { + darken: function($el){ + if($el.parent().hasClass('dark')){ + $el.parent().replaceWith($el); + }else{ + $el.replaceWith($("
").append($el.clone())); + } + }, + vomify: function($el){ + var hue=0; + var beat = false; + var a = setInterval(function(){ + $el.css({'-webkit-filter':'hue-rotate('+hue+'deg)'}); hue += 5; + }, 10); + setTimeout(function(){ + clearInterval(a); + setInterval(function(){ + var filter = 'hue-rotate('+hue+'deg)'+ (beat ? ' invert()' : ''); + $('html').css({'-webkit-filter': filter}); hue += 5; + if(hue % 35 === 0){ + beat = !beat; + } + }, 10); + },5000); + $('').appendTo($el); + }, + }; + /* ----- SNIPPET SELECTOR ---- */ website.Snippets = openerp.Widget.extend({ template: 'website.snippets', @@ -318,11 +346,20 @@ }); }, + path_eval: function(path){ + var obj = window; + path = path.split('.'); + do{ + obj = obj[path.shift()]; + }while(path.length && obj); + return obj; + }, + // setup widget and drag and drop start_snippets: function(){ var self = this; - this.$('.oe_snippet').draggable({ + this.$('.oe_snippet[data-action="insert"]').draggable({ helper: 'clone', appendTo: 'body', start: function(){ @@ -354,6 +391,32 @@ self.deactivate_drop_zones(); }, }); + + this.$('.oe_snippet[data-action="mutate"]').draggable({ + helper: 'clone', + appendTo: 'body', + start: function(){ + var snippet = $(this); + + self.activate_hover_zones(snippet.data('selector')); + + $('.oe_hover_zone').droppable({ + over: function(){ + $(".oe_hover_zone.oe_hover").removeClass("oe_hover"); + $(this).addClass("oe_hover"); + }, + out: function(){ + $(this).removeClass("oe_hover"); + }, + drop: function(){ + self.path_eval(snippet.data('action-function'))( $(".oe_hover_zone.oe_hover").data('target') ); + }, + }); + }, + stop: function(){ + self.deactivate_hover_zones(); + }, + }); }, // A generic drop zone generator. two css selectors can be provided // selector.childs -> will insert drop zones as direct child of the selected elements @@ -404,7 +467,7 @@ $zones.remove(); }while(count > 0); - // Cleaning up zones placed between floating or inline elements + // Cleaning up zones placed between floating or inline elements. We do not like these kind of zones. var $zones = $('.oe_drop_zone'); for( var i = 0, len = $zones.length; i < len; i++ ){ var zone = $zones.eq(i); @@ -418,11 +481,10 @@ && (float_next === 'left' || float_next === 'right') ){ zone.remove(); continue; - }else if( !( disp_prev === null - || disp_next === null - || disp_prev === 'block' - || disp_next === 'block' - ) ){ + }else if( !( disp_prev === null + || disp_next === null + || disp_prev === 'block' + || disp_next === 'block' )){ zone.remove(); continue; } @@ -431,6 +493,42 @@ deactivate_drop_zones: function(){ $('.oe_drop_zone').remove(); }, + activate_hover_zones: function(selector){ + var $targets = $(selector); + + function is_visible($el){ + return $el.css('display') != 'none' + && $el.css('opacity') != '0' + && $el.css('visibility') != 'hidden'; + } + + // filter out invisible elements + $targets = $targets.filter(function(){ return is_visible($(this)); }); + + // filter out elements with invisible parents + $targets = $targets.filter(function(){ + var parents = $(this).parents().filter(function(){ return !is_visible($(this)); }); + return parents.length === 0; + }); + + var zone_template = "
"; + $('.oe_hover_zone').remove(); + + for(var i = 0, len = $targets.length; i < len; i++){ + var $target = $targets.eq(i); + var $zone = $(zone_template); + $zone.css({ + 'width': $target.outerWidth(), + 'height': $target.outerHeight(), + }); + $zone.css($target.offset()); + $zone.appendTo('body'); + $zone.data('target',$target); + } + }, + deactivate_hover_zones: function(selector){ + $('.oe_hover_zone').remove(); + }, toggle: function(){ if(this.$el.hasClass('oe_hidden')){ this.$el.removeClass('oe_hidden'); @@ -438,16 +536,6 @@ this.$el.addClass('oe_hidden'); } }, - snippet_start: function () { - var self = this; - $('.oe_snippet').draggable().click(function(ev) { - self.setup_droppable(); - $(".oe_snippet_drop").show(); - $('.oe_selected').removeClass('oe_selected'); - $(ev.currentTarget).addClass('oe_selected'); - }); - - }, }); function noop() {} diff --git a/addons/website/views/views.xml b/addons/website/views/views.xml index 42a6e2add3c..f592817a104 100644 --- a/addons/website/views/views.xml +++ b/addons/website/views/views.xml @@ -401,12 +401,20 @@