Commit 5d8f91cf authored by hertzhaft's avatar hertzhaft

simplify some convenience variables

parent 6ec71a8f
...@@ -364,6 +364,7 @@ ...@@ -364,6 +364,7 @@
var p = $.map(coords, function(coord) { var p = $.map(coords, function(coord) {
return trafo.transform(geom.position(coord)); return trafo.transform(geom.position(coord));
}); });
// convenience varables
var p1 = p[0]; var p1 = p[0];
var p2 = p[1]; var p2 = p[1];
var $elem; var $elem;
...@@ -480,17 +481,17 @@ ...@@ -480,17 +481,17 @@
*/ */
var getVertexDragHandler = function (data, shape, vtx, onComplete) { var getVertexDragHandler = function (data, shape, vtx, onComplete) {
var $document = $(document); var $document = $(document);
var hs = data.settings.editHandleSize;
var $shape = shape.$elem; var $shape = shape.$elem;
var $handle = (shape.$vertexElems != null) ? shape.$vertexElems[vtx] : $(); var $handle = (shape.$vertexElems != null) ? shape.$vertexElems[vtx] : $();
var shapeType = shape.geometry.type; var shapeType = shape.geometry.type;
var imgRect = data.imgRect; var imgRect = data.imgRect;
var pt, pt0, pt1, pt2, rect; var hs = data.settings.editHandleSize;
var pStart, pt1, pt2; // convenience variables
var dragStart = function (evt) { var dragStart = function (evt) { // start dragging
// cancel if not left-click // cancel if not left-click
if (evt.which != 1) return; if (evt.which != 1) return;
pt0 = geom.position(evt); pStart = geom.position(evt);
if ($.inArray(shapeType, ['Rectangle', 'Circle', 'Ellipse']) > -1) { if ($.inArray(shapeType, ['Rectangle', 'Circle', 'Ellipse']) > -1) {
// save screen points of coordinates // save screen points of coordinates
pt1 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[0])); pt1 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[0]));
...@@ -502,8 +503,8 @@ ...@@ -502,8 +503,8 @@
return false; return false;
}; };
var dragMove = function (evt) { var dragMove = function (evt) { // dragging
pt = geom.position(evt); var pt = geom.position(evt);
pt.clipTo(imgRect); pt.clipTo(imgRect);
// move handle // move handle
$handle.attr({'x': pt.x-hs/2, 'y': pt.y-hs/2}); $handle.attr({'x': pt.x-hs/2, 'y': pt.y-hs/2});
...@@ -515,6 +516,7 @@ ...@@ -515,6 +516,7 @@
$shape.attr({'x2': pt.x, 'y2': pt.y}); $shape.attr({'x2': pt.x, 'y2': pt.y});
} }
} else if (shapeType === 'Rectangle') { } else if (shapeType === 'Rectangle') {
var rect;
if (vtx == 0) { if (vtx == 0) {
rect = geom.rectangle(pt, pt2); rect = geom.rectangle(pt, pt2);
} else if (vtx == 1) { } else if (vtx == 1) {
...@@ -552,9 +554,9 @@ ...@@ -552,9 +554,9 @@
return false; return false;
}; };
var dragEnd = function (evt) { var dragEnd = function (evt) { // end dragging
pt = geom.position(evt); var pt = geom.position(evt);
if ((pt.distance(pt0) < 5) && evt.type === 'mouseup') { if ((pt.distance(pStart) < 5) && evt.type === 'mouseup') {
// not drag but click to start // not drag but click to start
return false; return false;
} }
...@@ -615,7 +617,7 @@ ...@@ -615,7 +617,7 @@
var $overlayDiv = $('<div class="'+data.settings.cssPrefix+'shapeOverlay" style="position:absolute; z-index:100;"/>'); var $overlayDiv = $('<div class="'+data.settings.cssPrefix+'shapeOverlay" style="position:absolute; z-index:100;"/>');
$elem.append($overlayDiv); $elem.append($overlayDiv);
bodyRect.adjustDiv($overlayDiv); bodyRect.adjustDiv($overlayDiv);
var shapeStart = function (evt) { var shapeStart = function (evt) {
var pt = geom.position(evt); var pt = geom.position(evt);
// setup shape // setup shape
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment