Merge with 1e837b3a4b00c13c31c657986b810587ca5d907b
authorveltr
Tue, 19 Mar 2013 13:19:59 +0100
changeset 95 b4196fab7d01
parent 93 0a75599363e9 (current diff)
parent 94 1e837b3a4b00 (diff)
child 96 de07c00bfa7e
Merge with 1e837b3a4b00c13c31c657986b810587ca5d907b
src/egonomy/static/egonomy/js/cutout.js
--- a/integration/js/cutout.js	Thu Mar 14 16:11:21 2013 +0100
+++ b/integration/js/cutout.js	Tue Mar 19 13:19:59 2013 +0100
@@ -10,6 +10,7 @@
         offset = jqs.offset(),
         paper = new Raphael(jqs[0]),
         closed = false,
+        rectangleMode = false,
         closeTimeout,
         points = [];
     
@@ -36,6 +37,7 @@
                     }
                     redrawPath();
                     pathDragging = true;
+                    rectangleMode = true;
                 }
                 
                 var x = mx - offset.left,
@@ -55,6 +57,7 @@
         );
         
     function resetPoints() {
+    	rectangleMode = false;
         points.forEach(function(p) {
            p.handle.remove(); 
         });
@@ -69,6 +72,8 @@
                 y: Math.floor(y)
             }
         
+        var pointsWithSameX = [], pointsWithSameY = [];
+        
         var pointrect = paper.rect(0, 0, HANDLESIZE, HANDLESIZE)
             .attr({
                 stroke: PATHCOLOR,
@@ -81,11 +86,27 @@
                     pointDragging = true;
                     point.x = dx + dragdeltax;
                     point.y = dy + dragdeltay;
+                    if (rectangleMode) {
+                    	pointsWithSameX.forEach(function(p) {
+                    		p.x = point.x;
+                    	});
+                    	pointsWithSameY.forEach(function(p) {
+                    		p.y = point.y;
+                    	});
+                    }
                     redrawPath();
                 },
                 function() {
                     dragdeltax = point.x;
                     dragdeltay = point.y;
+                    if (rectangleMode) {
+                    	pointsWithSameX = points.filter(function(p) {
+                    		return p !== point && p.x === point.x;
+                    	});
+                    	pointsWithSameY = points.filter(function(p) {
+                    		return p !== point && p.y === point.y;
+                    	});
+                    }
                 },
                 function() {
                     setTimeout(function() {
@@ -117,6 +138,10 @@
             return;
         }
         
+        if (rectangleMode) {
+        	resetPoints();
+        }
+        
         clearTimeout(closeTimeout);
         closed = false;
         
--- a/src/egonomy/static/egonomy/js/cutout.js	Thu Mar 14 16:11:21 2013 +0100
+++ b/src/egonomy/static/egonomy/js/cutout.js	Tue Mar 19 13:19:59 2013 +0100
@@ -10,6 +10,7 @@
         offset = jqs.offset(),
         paper = new Raphael(jqs[0]),
         closed = false,
+        rectangleMode = false,
         closeTimeout,
         points = [];