integration/js/cutout.js
changeset 94 1e837b3a4b00
parent 8 c64d503ebba7
child 96 de07c00bfa7e
--- a/integration/js/cutout.js	Mon Feb 25 18:32:06 2013 +0100
+++ b/integration/js/cutout.js	Tue Mar 19 13:11:39 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;