[IMP] website: snippets: add resize bar on snippet overlay; resising % 8px; remove...
authorChristophe Matthieu <chm@openerp.com>
Wed, 8 Jan 2014 12:21:13 +0000 (13:21 +0100)
committerChristophe Matthieu <chm@openerp.com>
Wed, 8 Jan 2014 12:21:13 +0000 (13:21 +0100)
bzr revid: chm@openerp.com-20140108122113-d2zcyaobkahixlpa

addons/website/static/src/css/editor.css
addons/website/static/src/css/editor.sass
addons/website/static/src/css/website.css
addons/website/static/src/css/website.sass
addons/website/static/src/js/website.snippets.editor.js
addons/website/static/src/xml/website.snippets.xml
addons/website/views/snippets.xml

index f552465..79fcdb6 100644 (file)
@@ -432,6 +432,9 @@ ul.oe_menu_editor .disclose {
 }
 
 /* ---- SNIPPET MANIPULATOR ---- {{{ */
+.resize_editor_busy {
+  background-color: rgba(0,0,0,0.1);
+}
 .oe_overlay {
   display: none;
   position: absolute;
@@ -514,16 +517,28 @@ ul.oe_menu_editor .disclose {
 .oe_overlay .oe_handle.e:before {
   content: "\F061";
 }
-.oe_overlay .oe_handle.s {
+.oe_overlay .oe_handle.s, .oe_overlay .oe_handle.size {
   top: auto;
   left: 2px;
   width: 100%;
   bottom: -4px;
   cursor: n-resize;
 }
-.oe_overlay .oe_handle.s:before {
+.oe_overlay .oe_handle.s:before, .oe_overlay .oe_handle.size:before {
   content: "\F063";
 }
+.oe_overlay .oe_handle.size {
+  border-style: dashed;
+  border-width: 0 0 1px 0;
+  border-color: rgba(0, 0, 0, 0.5);
+}
+.oe_overlay .oe_handle.size:before {
+  content: "Resize";
+  width: 64px;
+  text-align: center;
+  margin-left: -32px;
+  margin-top: -4px;
+}
 .oe_overlay .oe_handle.w {
   top: 2px;
   height: 100%;
index 9def6bc..78af810 100644 (file)
@@ -349,6 +349,8 @@ ul.oe_menu_editor
 
 /* ---- SNIPPET MANIPULATOR ---- {{{ */
 
+.resize_editor_busy
+    background-color: rgba(0,0,0,0.3)
 .oe_overlay
     display: none
     position: absolute
@@ -403,7 +405,7 @@ ul.oe_menu_editor
         cursor: w-resize
         &:before
             content: "\F061"
-    .oe_handle.s
+    .oe_handle.s, .oe_handle.size
         top: auto
         left: 2px
         width: 100%
@@ -411,6 +413,16 @@ ul.oe_menu_editor
         cursor: n-resize
         &:before
             content: "\F063"
+    .oe_handle.size
+        border-style: dashed
+        border-width: 0 0 1px 0
+        border-color: rgba(0, 0, 0, 0.5)
+        &:before
+            content: "Resize"
+            width: 64px
+            text-align: center
+            margin-left: -32px
+            margin-top: -4px
     .oe_handle.w
         top: 2px
         height: 100%
index bf261cf..ca59f4c 100644 (file)
@@ -334,19 +334,16 @@ ul.nav-stacked > li > a {
 }
 
 /* ---- SNIPPETS --- */
-.carousel-inner .item {
-  height: 100%;
-  background-size: 100%;
+[data-snippet-id],.colmd,.hr,.blockquote {
+    overflow: hidden;
 }
 
-.carousel.oe_small .carousel-inner {
-  height: 200px;
-}
-.carousel.oe_medium .carousel-inner {
-  height: 300px;
+.carousel-inner {
+  height: 100%;
 }
-.carousel.oe_big .carousel-inner {
-  height: 450px;
+.carousel-inner .item {
+  height: 100%;
+  background-size: 100%;
 }
 .carousel .carousel-caption {
   left: auto;
index ccd11d3..ab13d79 100644 (file)
@@ -242,18 +242,15 @@ ul.nav-stacked > li > a
             color: white
 
 /* ---- SNIPPETS --- */
+[data-snippet-id],.colmd,.hr,.blockquote
+    overflow: hidden
 
-.carousel-inner .item
+.carousel-inner
     height: 100%
-    background-size: 100%
-
+    .item
+        height: 100%
+        background-size: 100%
 .carousel
-    &.oe_small .carousel-inner
-        height: 200px
-    &.oe_medium .carousel-inner
-        height: 300px
-    &.oe_big .carousel-inner
-        height: 450px
     .carousel-caption
         left: auto
         right: auto
index 50975a7..33f38ea 100644 (file)
                 'top': pos.top - mt,
                 'left': pos.left
             });
+            $el.find(".oe_handle.size").css("bottom", mb+'px');
         },
         show: function () {
             this.$el.removeClass("hidden");
     });
 
 
-    website.snippet.styleRegistry.size = website.snippet.StyleEditor.extend({
-        select: function(event, np) {
-            this._super(event, np);
-            this.parent.parent.cover_target(this.$overlay, this.$target);
-        },
-        preview: function (event, np) {
-            this._super(event, np);
-            this.parent.parent.cover_target(this.$overlay, this.$target);
-        }
-    });
-
     website.snippet.styleRegistry.background = website.snippet.StyleEditor.extend({
         _get_bg: function () {
             return this.$target.css("background-image").replace(/url\(['"]*|['"]*\)|^none$/g, "");
                 }
                 var Editor = website.snippet.styleRegistry[val['snippet-style-id']] || website.snippet.StyleEditor;
                 var editor = new Editor(self, self.$target, val['snippet-style-id']);
-                $ul.prepend(editor.$el);
+                $ul.prepend(editor.$el.addClass("snippet-style-" + val['snippet-style-id']));
             });
 
             if ($ul.find("li").length) {
             if (!resize_values.s) $box.find(".oe_handle.s").remove();
             if (!resize_values.e) $box.find(".oe_handle.e").remove();
             if (!resize_values.w) $box.find(".oe_handle.w").remove();
+            if (!resize_values.size) $box.find(".oe_handle.size").remove();
 
             this.$overlay.append($box.find(".oe_handles").html());
 
             this.$overlay.find(".oe_handle").on('mousedown', function (event){
-                    event.preventDefault();
+                event.preventDefault();
 
-                    var $handle = $(this);
+                var $handle = $(this);
 
-                    var resize_values = self.getSize();
-                    var compass = false;
-                    var XY = false;
-                    if ($handle.hasClass('n')) {
-                        compass = 'n';
-                        XY = 'Y';
-                    }
-                    else if ($handle.hasClass('s')) {
-                        compass = 's';
-                        XY = 'Y';
-                    }
-                    else if ($handle.hasClass('e')) {
-                        compass = 'e';
-                        XY = 'X';
-                    }
-                    else if ($handle.hasClass('w')) {
-                        compass = 'w';
-                        XY = 'X';
-                    }
+                var resize_values = self.getSize();
+                var compass = false;
+                var XY = false;
+                if ($handle.hasClass('n')) {
+                    compass = 'n';
+                    XY = 'Y';
+                }
+                else if ($handle.hasClass('s')) {
+                    compass = 's';
+                    XY = 'Y';
+                }
+                else if ($handle.hasClass('e')) {
+                    compass = 'e';
+                    XY = 'X';
+                }
+                else if ($handle.hasClass('w')) {
+                    compass = 'w';
+                    XY = 'X';
+                }
+                else if ($handle.hasClass('size')) {
+                    compass = 'size';
+                    XY = 'Y';
+                }
 
-                    var resize = resize_values[compass];
-                    if (!resize) return;
+                var resize = resize_values[compass];
+                if (!resize) return;
 
+
+                if (compass === 'size') {
+                    var grid = resize[0];
+                    var offset = self.$target.offset().top;
+                    if (self.$target.css("background").match(/rgba\(0, 0, 0, 0\)/)) {
+                        self.$target.addClass("resize_editor_busy");
+                    }
+                } else {
+                    var xy = event['page'+XY];
                     var current = resize[2] || 0;
                     _.each(resize[0], function (val, key) {
                         if (self.$target.hasClass(val)) {
                             current = key;
                         }
                     });
-
-                    self.parent.editor_busy = true;
-
-                    var xy = event['page'+XY];
                     var begin = current;
                     var beginClass = self.$target.attr("class");
                     var regClass = new RegExp("\\s*" + resize[0][begin].replace(/[-]*[0-9]+/, '[-]*[0-9]+'), 'g');
+                }
 
-                    var cursor = $handle.css("cursor")+'-important';
-                    var $body = $(document.body);
-                    $body.addClass(cursor);
-
-                    var body_mousemove = function (event){
-                        event.preventDefault();
-                        var dd = event['page'+XY] - xy + resize[1][begin];
-                        var next = current+1 === resize[1].length ? current : (current+1);
-                        var prev = current ? (current-1) : 0;
-
-                        var change = false;
-                        if (dd > (2*resize[1][next] + resize[1][current])/3) {
-                            self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, ''));
-                            self.$target.addClass(resize[0][next]);
-                            current = next;
-                            change = true;
-                        }
-                        if (prev != current && dd < (2*resize[1][prev] + resize[1][current])/3) {
-                            self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, ''));
-                            self.$target.addClass(resize[0][prev]);
-                            current = prev;
-                            change = true;
-                        }
+                self.parent.editor_busy = true;
 
-                        if (change) {
-                            self.on_resize(compass, beginClass, current);
-                            self.parent.cover_target(self.$overlay, self.$target);
-                        }
-                    };
-
-                    var body_mouseup = function(){
-                        $body.unbind('mousemove', body_mousemove);
-                        $body.unbind('mouseup', body_mouseup);
-                        $body.removeClass(cursor);
-                        self.parent.editor_busy = false;
-                    };
-                    $body.mousemove(body_mousemove);
-                    $body.mouseup(body_mouseup);
-                });
+                var cursor = $handle.css("cursor")+'-important';
+                var $body = $(document.body);
+                $body.addClass(cursor);
+
+                var body_mousemove = function (event){
+                    event.preventDefault();
+                    if (compass === 'size') {
+                        var dy = event.pageY-offset;
+                        dy = dy - dy%resize[0];
+                        if (dy <= 0) dy = resize[0];
+                        self.$target.css("height", dy+"px");
+                        self.on_resize(compass, beginClass, current);
+                        self.parent.cover_target(self.$overlay, self.$target);
+                        return;
+                    }
+                    var dd = event['page'+XY] - xy + resize[1][begin];
+                    var next = current+1 === resize[1].length ? current : (current+1);
+                    var prev = current ? (current-1) : 0;
+
+                    var change = false;
+                    if (dd > (2*resize[1][next] + resize[1][current])/3) {
+                        self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, ''));
+                        self.$target.addClass(resize[0][next]);
+                        current = next;
+                        change = true;
+                    }
+                    if (prev != current && dd < (2*resize[1][prev] + resize[1][current])/3) {
+                        self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, ''));
+                        self.$target.addClass(resize[0][prev]);
+                        current = prev;
+                        change = true;
+                    }
+
+                    if (change) {
+                        self.on_resize(compass, beginClass, current);
+                        self.parent.cover_target(self.$overlay, self.$target);
+                    }
+                };
+
+                var body_mouseup = function(){
+                    $body.unbind('mousemove', body_mousemove);
+                    $body.unbind('mouseup', body_mouseup);
+                    $body.removeClass(cursor);
+                    self.parent.editor_busy = false;
+                    self.$target.removeClass("resize_editor_busy");
+                };
+                $body.mousemove(body_mousemove);
+                $body.mouseup(body_mouseup);
+            });
         },
         getSize: function () {
             var grid = [0,4,8,16,32,48,64,92,128];
             this.grid = {
+                // list of class (Array), grid (Array), default value (INT)
                 n: [_.map(grid, function (v) {return 'mt'+v;}), grid],
-                s: [_.map(grid, function (v) {return 'mb'+v;}), grid]
+                s: [_.map(grid, function (v) {return 'mb'+v;}), grid],
+                size: [8]
             };
             return this.grid;
         },
             var grid = [-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11];
             this.grid.w = [_.map(grid, function (v) {return 'col-md-offset-'+v;}), _.map(grid, function (v) {return width/12*v;}), 12];
 
+            this.grid.s = null;
+
             return this.grid;
         },
         _drag_and_drop_after_insert_dropzone: function(){
             this.$target.css("background-image", "");
             this.$target.removeClass(this._class);
         },
+        getSize: function () {
+            this._super();
+            //this.grid.size = null;
+            return this.grid;
+        },
+        load_style_options : function () {
+            this._super();
+            $(".snippet-style-size li[data-class='']").remove();
+        },
         start : function () {
             var self = this;
             this._super();
index ecc3bb8..ca5cf01 100644 (file)
@@ -86,6 +86,7 @@
             <div class='oe_handle n'></div>
             <div class='oe_handle e'></div>
             <div class='oe_handle w'></div>
+            <div class='oe_handle size'></div>
             <div class='oe_handle s'></div>
         </div>
         <div class='oe_snippet_thumbnail'>Margin resize</div>
index 99bba70..a11d2b4 100644 (file)
@@ -25,7 +25,7 @@
             <img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_banner.png"/>
             <span class="oe_snippet_thumbnail_title">Banner</span>         
         </div>
-        <div id="myCarousel" class="oe_snippet_body carousel slide oe_medium mb32">
+        <div id="myCarousel" class="oe_snippet_body carousel slide mb32" style="height: 320px;">
             <!-- Indicators -->
             <ol class="carousel-indicators hidden">
                 <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
@@ -68,8 +68,8 @@
                             and give it to them.
                         </p>
                     </div>
-                    <div class="col-md-6 mt16 mb16">
-                        <img class="img img-responsive shadow" src="/website/static/src/img/text_image.png"/>
+                    <div class="col-md-6 mt16">
+                        <img class="img img-responsive shadow mb16" src="/website/static/src/img/text_image.png"/>
                     </div>
                 </div>
             </div>
@@ -85,8 +85,8 @@
         <section class="oe_snippet_body">
             <div class="container">
                 <div class="row">
-                    <div class="col-md-6 mt16 mb16">
-                        <img class="img img-responsive shadow" src="/website/static/src/img/image_text.jpg"/>
+                    <div class="col-md-6 mt16">
+                        <img class="img img-responsive shadow mb16" src="/website/static/src/img/image_text.jpg"/>
                     </div>
                     <div class="col-md-6 mt16">
                         <h3>A Section Subtitle</h3>
             <img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_quotes_slider.png"/>
             <span class="oe_snippet_thumbnail_title">Quotes Slider</span>         
         </div>
-        <div id="myQuoteCarousel" class="oe_snippet_body carousel slide oe_small mb0">
+        <div id="myQuoteCarousel" class="oe_snippet_body carousel slide mb0" style="height: 240px;">
             <!-- Indicators -->
             <ol class="carousel-indicators mb0">
                 <li data-target="#myQuoteCarousel" data-slide-to="0" class="active"></li>
                 <li data-value="1.7"><a>Very Fast</a></li>
             </ul>
         </li>
-        <section class="oe_snippet_body parallax oe_medium"
-                style="background-image: url('/website/static/src/img/banner/mountains.jpg')"
+        <section class="oe_snippet_body parallax"
+                style="height: 320px; background-image: url('/website/static/src/img/banner/mountains.jpg')"
                 data-scroll-background-ratio="0.3">
                 <div><div class="oe_structure"/></div>
         </section>
             <img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_quotes_slider.png"/>
             <span class="oe_snippet_thumbnail_title">Parallax Slider</span>        
         </div>
-        <section class="oe_snippet_body parallax oe_medium" data-snippet-id="parallax"
-                style="background-image: url('/website/static/src/img/parallax/quote.png')"
+        <section class="oe_snippet_body parallax" data-snippet-id="parallax"
+                 style="height: 320px; background-image: url('/website/static/src/img/parallax/quote.png')"
                 data-scroll-background-ratio="0.3">
             <div>
                 <div class="oe_structure">
-                    <div id="myQuoteCarousel" class="carousel slide oe_small mb0" data-snippet-id="slider">
+                    <div id="myQuoteCarousel" class="carousel slide mb0" style="height: 240px;" data-snippet-id="slider">
                         <!-- Indicators -->
                         <ol class="carousel-indicators mb0">
                             <li data-target="#myQuoteCarousel" data-slide-to="0" class="active"></li>
         </li>
     </div>
 
-    <div data-snippet-style-id='size' data-selector="section[data-snippet-id='parallax'], div[data-snippet-id='carousel'], div[data-snippet-id='slider']">
-        <li class="dropdown-submenu" data-required="true">
-            <a tabindex="-1" href="#">Size</a>
-            <ul class="dropdown-menu">
-                <li data-class='oe_small'><a>Small</a></li>
-                <li data-class='oe_medium'><a>Medium</a></li>
-                <li data-class='oe_big'><a>Big</a></li>
-                <li data-class=''><a>Auto</a></li>
-            </ul>
-        </li>
-    </div>
-
     <div data-snippet-style-id='background' data-selector="section, section[data-snippet-id='parallax'], div[data-snippet-id='carousel']">
         <li class="dropdown-submenu">
             <a tabindex="-1" href="#">Background</a>