JSLint svgcanvas.js (30% scanned)
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2679 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
6a9cf9551a
commit
00092d4a03
|
@ -1483,12 +1483,11 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
mouse_target.style.vectorEffect = 'non-scaling-stroke';
|
mouse_target.style.vectorEffect = 'non-scaling-stroke';
|
||||||
if (isWebkit) {delayedStroke(mouse_target);}
|
if (isWebkit) {delayedStroke(mouse_target);}
|
||||||
|
|
||||||
var i,
|
var all = mouse_target.getElementsByTagName('*'),
|
||||||
all = mouse_target.getElementsByTagName('*'),
|
|
||||||
len = all.length;
|
len = all.length;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
all[i].style.vectorEffect = 'non-scaling-stroke';
|
all[i].style.vectorEffect = 'non-scaling-stroke';
|
||||||
if (isWebkit) delayedStroke(all[i]);
|
if (isWebkit) {delayedStroke(all[i]);}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1668,12 +1667,12 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
|
|
||||||
// in this function we do not record any state changes yet (but we do update
|
// in this function we do not record any state changes yet (but we do update
|
||||||
// any elements that are still being created, moved or resized on the canvas)
|
// any elements that are still being created, moved or resized on the canvas)
|
||||||
var mouseMove = function(evt)
|
var mouseMove = function(evt) {
|
||||||
{
|
|
||||||
if (!started) {return;}
|
if (!started) {return;}
|
||||||
if (evt.button === 1 || canvas.spaceKey) {return;}
|
if (evt.button === 1 || canvas.spaceKey) {return;}
|
||||||
|
|
||||||
var selected = selectedElements[0],
|
var i, xya, c, cx, cy, dx, dy, len,
|
||||||
|
selected = selectedElements[0],
|
||||||
pt = svgedit.math.transformPoint( evt.pageX, evt.pageY, root_sctm ),
|
pt = svgedit.math.transformPoint( evt.pageX, evt.pageY, root_sctm ),
|
||||||
mouse_x = pt.x * current_zoom,
|
mouse_x = pt.x * current_zoom,
|
||||||
mouse_y = pt.y * current_zoom,
|
mouse_y = pt.y * current_zoom,
|
||||||
|
@ -1697,8 +1696,8 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
// this transform is removed upon mousing up and the element is
|
// this transform is removed upon mousing up and the element is
|
||||||
// relocated to the new location
|
// relocated to the new location
|
||||||
if (selectedElements[0] !== null) {
|
if (selectedElements[0] !== null) {
|
||||||
var dx = x - start_x;
|
dx = x - start_x;
|
||||||
var dy = y - start_y;
|
dy = y - start_y;
|
||||||
|
|
||||||
if (curConfig.gridSnapping){
|
if (curConfig.gridSnapping){
|
||||||
dx = svgedit.utilities.snapToGrid(dx);
|
dx = svgedit.utilities.snapToGrid(dx);
|
||||||
|
@ -1706,14 +1705,13 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.shiftKey) {
|
if (evt.shiftKey) {
|
||||||
var xya = svgedit.math.snapToAngle(start_x, start_y, x, y);
|
xya = svgedit.math.snapToAngle(start_x, start_y, x, y);
|
||||||
x = xya.x;
|
x = xya.x;
|
||||||
y = xya.y;
|
y = xya.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dx != 0 || dy != 0) {
|
if (dx != 0 || dy != 0) {
|
||||||
var i,
|
len = selectedElements.length;
|
||||||
len = selectedElements.length;
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
var selected = selectedElements[i];
|
var selected = selectedElements[i];
|
||||||
if (selected == null) {break;}
|
if (selected == null) {break;}
|
||||||
|
@ -1760,10 +1758,9 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
// - if newList contains selected, do nothing
|
// - if newList contains selected, do nothing
|
||||||
// - if newList doesn't contain selected, remove it from selected
|
// - if newList doesn't contain selected, remove it from selected
|
||||||
// - for any newList that was not in selectedElements, add it to selected
|
// - for any newList that was not in selectedElements, add it to selected
|
||||||
var i,
|
var elemsToRemove = [], elemsToAdd = [],
|
||||||
elemsToRemove = [], elemsToAdd = [],
|
newList = getIntersectionList();
|
||||||
newList = getIntersectionList(),
|
len = selectedElements.length;
|
||||||
len = selectedElements.length;
|
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
var ind = newList.indexOf(selectedElements[i]);
|
var ind = newList.indexOf(selectedElements[i]);
|
||||||
|
@ -1796,7 +1793,9 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
hasMatrix = svgedit.math.hasMatrixTransform(tlist),
|
hasMatrix = svgedit.math.hasMatrixTransform(tlist),
|
||||||
box = hasMatrix ? init_bbox : svgedit.utilities.getBBox(selected),
|
box = hasMatrix ? init_bbox : svgedit.utilities.getBBox(selected),
|
||||||
left = box.x, top = box.y, width = box.width,
|
left = box.x, top = box.y, width = box.width,
|
||||||
height = box.height, dx = (x-start_x), dy = (y-start_y);
|
height = box.height;
|
||||||
|
dx = (x-start_x);
|
||||||
|
dy = (y-start_y);
|
||||||
|
|
||||||
if (curConfig.gridSnapping) {
|
if (curConfig.gridSnapping) {
|
||||||
dx = svgedit.utilities.snapToGrid(dx);
|
dx = svgedit.utilities.snapToGrid(dx);
|
||||||
|
@ -1853,8 +1852,8 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
|
|
||||||
translateOrigin.setTranslate(-(left+tx), -(top+ty));
|
translateOrigin.setTranslate(-(left+tx), -(top+ty));
|
||||||
if (evt.shiftKey) {
|
if (evt.shiftKey) {
|
||||||
if (sx == 1) sx = sy;
|
if (sx == 1) {sx = sy;}
|
||||||
else sy = sx;
|
else {sy = sx;}
|
||||||
}
|
}
|
||||||
scale.setScale(sx, sy);
|
scale.setScale(sx, sy);
|
||||||
|
|
||||||
|
@ -1863,7 +1862,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
var diff = angle?1:0;
|
var diff = angle?1:0;
|
||||||
tlist.replaceItem(translateOrigin, 2+diff);
|
tlist.replaceItem(translateOrigin, 2+diff);
|
||||||
tlist.replaceItem(scale, 1+diff);
|
tlist.replaceItem(scale, 1+diff);
|
||||||
tlist.replaceItem(translateBack, 0+diff);
|
tlist.replaceItem(translateBack, Number(diff));
|
||||||
} else {
|
} else {
|
||||||
var N = tlist.numberOfItems;
|
var N = tlist.numberOfItems;
|
||||||
tlist.replaceItem(translateBack, N-3);
|
tlist.replaceItem(translateBack, N-3);
|
||||||
|
@ -1895,7 +1894,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
case "line":
|
case "line":
|
||||||
// Opera has a problem with suspendRedraw() apparently
|
// Opera has a problem with suspendRedraw() apparently
|
||||||
var handle = null;
|
var handle = null;
|
||||||
if (!window.opera) svgroot.suspendRedraw(1000);
|
if (!window.opera) {svgroot.suspendRedraw(1000);}
|
||||||
|
|
||||||
if (curConfig.gridSnapping){
|
if (curConfig.gridSnapping){
|
||||||
x = svgedit.utilities.snapToGrid(x);
|
x = svgedit.utilities.snapToGrid(x);
|
||||||
|
@ -1906,14 +1905,14 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
var y2 = y;
|
var y2 = y;
|
||||||
|
|
||||||
if (evt.shiftKey) {
|
if (evt.shiftKey) {
|
||||||
var xya = svgedit.math.snapToAngle(start_x, start_y, x2, y2);
|
xya = svgedit.math.snapToAngle(start_x, start_y, x2, y2);
|
||||||
x2 = xya.x;
|
x2 = xya.x;
|
||||||
y2 = xya.y;
|
y2 = xya.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
shape.setAttributeNS(null, "x2", x2);
|
shape.setAttributeNS(null, "x2", x2);
|
||||||
shape.setAttributeNS(null, "y2", y2);
|
shape.setAttributeNS(null, "y2", y2);
|
||||||
if (!window.opera) svgroot.unsuspendRedraw(handle);
|
if (!window.opera) {svgroot.unsuspendRedraw(handle);}
|
||||||
break;
|
break;
|
||||||
case "foreignObject":
|
case "foreignObject":
|
||||||
// fall through
|
// fall through
|
||||||
|
@ -1951,20 +1950,22 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "circle":
|
case "circle":
|
||||||
var c = $(shape).attr(["cx", "cy"]);
|
c = $(shape).attr(["cx", "cy"]);
|
||||||
var cx = c.cx, cy = c.cy,
|
cx = c.cx;
|
||||||
rad = Math.sqrt( (x-cx)*(x-cx) + (y-cy)*(y-cy) );
|
cy = c.cy;
|
||||||
|
var rad = Math.sqrt( (x-cx)*(x-cx) + (y-cy)*(y-cy) );
|
||||||
if (curConfig.gridSnapping){
|
if (curConfig.gridSnapping){
|
||||||
rad = svgedit.utilities.snapToGrid(rad);
|
rad = svgedit.utilities.snapToGrid(rad);
|
||||||
}
|
}
|
||||||
shape.setAttributeNS(null, "r", rad);
|
shape.setAttributeNS(null, "r", rad);
|
||||||
break;
|
break;
|
||||||
case "ellipse":
|
case "ellipse":
|
||||||
var c = $(shape).attr(["cx", "cy"]);
|
c = $(shape).attr(["cx", "cy"]);
|
||||||
var cx = c.cx, cy = c.cy;
|
cx = c.cx;
|
||||||
|
cy = c.cy;
|
||||||
// Opera has a problem with suspendRedraw() apparently
|
// Opera has a problem with suspendRedraw() apparently
|
||||||
handle = null;
|
handle = null;
|
||||||
if (!window.opera) svgroot.suspendRedraw(1000);
|
if (!window.opera) {svgroot.suspendRedraw(1000);}
|
||||||
if (curConfig.gridSnapping){
|
if (curConfig.gridSnapping){
|
||||||
x = svgedit.utilities.snapToGrid(x);
|
x = svgedit.utilities.snapToGrid(x);
|
||||||
cx = svgedit.utilities.snapToGrid(cx);
|
cx = svgedit.utilities.snapToGrid(cx);
|
||||||
|
@ -1974,7 +1975,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
shape.setAttributeNS(null, "rx", Math.abs(x - cx) );
|
shape.setAttributeNS(null, "rx", Math.abs(x - cx) );
|
||||||
var ry = Math.abs(evt.shiftKey?(x - cx):(y - cy));
|
var ry = Math.abs(evt.shiftKey?(x - cx):(y - cy));
|
||||||
shape.setAttributeNS(null, "ry", ry );
|
shape.setAttributeNS(null, "ry", ry );
|
||||||
if (!window.opera) svgroot.unsuspendRedraw(handle);
|
if (!window.opera) {svgroot.unsuspendRedraw(handle);}
|
||||||
break;
|
break;
|
||||||
case "fhellipse":
|
case "fhellipse":
|
||||||
case "fhrect":
|
case "fhrect":
|
||||||
|
@ -1987,8 +1988,8 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
// d_attr += + real_x + "," + real_y + " ";
|
// d_attr += + real_x + "," + real_y + " ";
|
||||||
// shape.setAttributeNS(null, "points", d_attr);
|
// shape.setAttributeNS(null, "points", d_attr);
|
||||||
end.x = real_x; end.y = real_y;
|
end.x = real_x; end.y = real_y;
|
||||||
if (controllPoint2.x && controllPoint2.y){
|
if (controllPoint2.x && controllPoint2.y) {
|
||||||
for (var i = 0; i < STEP_COUNT - 1; i++) {
|
for (i = 0; i < STEP_COUNT - 1; i++) {
|
||||||
parameter = i / STEP_COUNT;
|
parameter = i / STEP_COUNT;
|
||||||
nextParameter = (i + 1) / STEP_COUNT;
|
nextParameter = (i + 1) / STEP_COUNT;
|
||||||
bSpline = getBsplinePoint(nextParameter);
|
bSpline = getBsplinePoint(nextParameter);
|
||||||
|
@ -2021,14 +2022,15 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
}
|
}
|
||||||
if (evt.shiftKey) {
|
if (evt.shiftKey) {
|
||||||
var path = svgedit.path.path;
|
var path = svgedit.path.path;
|
||||||
|
var x1, y1;
|
||||||
if (path) {
|
if (path) {
|
||||||
var x1 = path.dragging?path.dragging[0]:start_x;
|
x1 = path.dragging?path.dragging[0]:start_x;
|
||||||
var y1 = path.dragging?path.dragging[1]:start_y;
|
y1 = path.dragging?path.dragging[1]:start_y;
|
||||||
} else {
|
} else {
|
||||||
var x1 = start_x;
|
x1 = start_x;
|
||||||
var y1 = start_y;
|
y1 = start_y;
|
||||||
}
|
}
|
||||||
var xya = svgedit.math.snapToAngle(x1, y1, x, y);
|
xya = svgedit.math.snapToAngle(x1, y1, x, y);
|
||||||
x = xya.x;
|
x = xya.x;
|
||||||
y = xya.y;
|
y = xya.y;
|
||||||
}
|
}
|
||||||
|
@ -2062,10 +2064,10 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "rotate":
|
case "rotate":
|
||||||
var box = svgedit.utilities.getBBox(selected),
|
var box = svgedit.utilities.getBBox(selected);
|
||||||
cx = box.x + box.width/2,
|
cx = box.x + box.width/2;
|
||||||
cy = box.y + box.height/2,
|
cy = box.y + box.height/2;
|
||||||
m = svgedit.math.getMatrix(selected),
|
var m = svgedit.math.getMatrix(selected),
|
||||||
center = svgedit.math.transformPoint(cx, cy, m);
|
center = svgedit.math.transformPoint(cx, cy, m);
|
||||||
cx = center.x;
|
cx = center.x;
|
||||||
cy = center.y;
|
cy = center.y;
|
||||||
|
@ -2100,10 +2102,10 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
// identified, a ChangeElementCommand is created and stored on the stack for those attrs
|
// identified, a ChangeElementCommand is created and stored on the stack for those attrs
|
||||||
// this is done in when we recalculate the selected dimensions()
|
// this is done in when we recalculate the selected dimensions()
|
||||||
var mouseUp = function(evt) {
|
var mouseUp = function(evt) {
|
||||||
if (evt.button === 2) return;
|
if (evt.button === 2) {return;}
|
||||||
var tempJustSelected = justSelected;
|
var tempJustSelected = justSelected;
|
||||||
justSelected = null;
|
justSelected = null;
|
||||||
if (!started) return;
|
if (!started) {return;}
|
||||||
var pt = svgedit.math.transformPoint( evt.pageX, evt.pageY, root_sctm ),
|
var pt = svgedit.math.transformPoint( evt.pageX, evt.pageY, root_sctm ),
|
||||||
mouse_x = pt.x * current_zoom,
|
mouse_x = pt.x * current_zoom,
|
||||||
mouse_y = pt.y * current_zoom,
|
mouse_y = pt.y * current_zoom,
|
||||||
|
@ -2118,8 +2120,8 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
// TODO: Make true when in multi-unit mode
|
// TODO: Make true when in multi-unit mode
|
||||||
var useUnit = false; // (curConfig.baseUnit !== 'px');
|
var useUnit = false; // (curConfig.baseUnit !== 'px');
|
||||||
started = false;
|
started = false;
|
||||||
switch (current_mode)
|
var attrs;
|
||||||
{
|
switch (current_mode) {
|
||||||
// intentionally fall-through to select here
|
// intentionally fall-through to select here
|
||||||
case "resize":
|
case "resize":
|
||||||
case "multiselect":
|
case "multiselect":
|
||||||
|
@ -2164,9 +2166,9 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
recalculateAllSelectedDimensions();
|
recalculateAllSelectedDimensions();
|
||||||
// if it was being dragged/resized
|
// if it was being dragged/resized
|
||||||
if (real_x != r_start_x || real_y != r_start_y) {
|
if (real_x != r_start_x || real_y != r_start_y) {
|
||||||
var len = selectedElements.length;
|
var i, len = selectedElements.length;
|
||||||
for (var i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
if (selectedElements[i] == null) break;
|
if (selectedElements[i] == null) {break;}
|
||||||
if (!selectedElements[i].firstChild) {
|
if (!selectedElements[i].firstChild) {
|
||||||
// Not needed for groups (incorrectly resizes elems), possibly not needed at all?
|
// Not needed for groups (incorrectly resizes elems), possibly not needed at all?
|
||||||
selectorManager.requestSelector(selectedElements[i]).resize();
|
selectorManager.requestSelector(selectedElements[i]).resize();
|
||||||
|
@ -2205,7 +2207,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
if (rubberBox != null) {
|
if (rubberBox != null) {
|
||||||
rubberBox.setAttribute("display", "none");
|
rubberBox.setAttribute("display", "none");
|
||||||
}
|
}
|
||||||
var factor = evt.shiftKey?.5:2;
|
var factor = evt.shiftKey ? 0.5 : 2;
|
||||||
call("zoomed", {
|
call("zoomed", {
|
||||||
'x': Math.min(r_start_x, real_x),
|
'x': Math.min(r_start_x, real_x),
|
||||||
'y': Math.min(r_start_y, real_y),
|
'y': Math.min(r_start_y, real_y),
|
||||||
|
@ -2236,14 +2238,14 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "line":
|
case "line":
|
||||||
var attrs = $(element).attr(["x1", "x2", "y1", "y2"]);
|
attrs = $(element).attr(["x1", "x2", "y1", "y2"]);
|
||||||
keep = (attrs.x1 != attrs.x2 || attrs.y1 != attrs.y2);
|
keep = (attrs.x1 != attrs.x2 || attrs.y1 != attrs.y2);
|
||||||
break;
|
break;
|
||||||
case "foreignObject":
|
case "foreignObject":
|
||||||
case "square":
|
case "square":
|
||||||
case "rect":
|
case "rect":
|
||||||
case "image":
|
case "image":
|
||||||
var attrs = $(element).attr(["width", "height"]);
|
attrs = $(element).attr(["width", "height"]);
|
||||||
// Image should be kept regardless of size (use inherit dimensions later)
|
// Image should be kept regardless of size (use inherit dimensions later)
|
||||||
keep = (attrs.width != 0 || attrs.height != 0) || current_mode === "image";
|
keep = (attrs.width != 0 || attrs.height != 0) || current_mode === "image";
|
||||||
break;
|
break;
|
||||||
|
@ -2251,7 +2253,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
||||||
keep = (element.getAttribute('r') != 0);
|
keep = (element.getAttribute('r') != 0);
|
||||||
break;
|
break;
|
||||||
case "ellipse":
|
case "ellipse":
|
||||||
var attrs = $(element).attr(["rx", "ry"]);
|
attrs = $(element).attr(["rx", "ry"]);
|
||||||
keep = (attrs.rx != null || attrs.ry != null);
|
keep = (attrs.rx != null || attrs.ry != null);
|
||||||
break;
|
break;
|
||||||
case "fhellipse":
|
case "fhellipse":
|
||||||
|
|
Loading…
Reference in New Issue