Replaced heavy uses of getAttribute with .attr([])

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1363 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-02-09 14:23:34 +00:00
parent 8805307592
commit fd49cb2c89
1 changed files with 32 additions and 55 deletions

View File

@ -1785,37 +1785,27 @@ function BatchCommand(text) {
var batchCmd = new BatchCommand("Transform"); var batchCmd = new BatchCommand("Transform");
// store initial values that will be affected by reducing the transform list // store initial values that will be affected by reducing the transform list
var changes = {}, initial = null; var changes = {}, initial = null, attrs = [];
switch (selected.tagName) switch (selected.tagName)
{ {
case "line": case "line":
changes["x1"] = selected.getAttribute("x1"); attrs = ["x1", "y1", "x2", "y2"];
changes["y1"] = selected.getAttribute("y1");
changes["x2"] = selected.getAttribute("x2");
changes["y2"] = selected.getAttribute("y2");
break; break;
case "circle": case "circle":
changes["cx"] = selected.getAttribute("cx"); attrs = ["cx", "cy", "r"];
changes["cy"] = selected.getAttribute("cy");
changes["r"] = selected.getAttribute("r");
break; break;
case "ellipse": case "ellipse":
changes["cx"] = selected.getAttribute("cx"); attrs = ["cx", "cy", "rx", "ry"];
changes["cy"] = selected.getAttribute("cy");
changes["rx"] = selected.getAttribute("rx");
changes["ry"] = selected.getAttribute("ry");
break; break;
case "rect": case "rect":
case "image": case "image":
changes["width"] = selected.getAttribute("width"); attrs = ["width", "height", "x", "y"];
changes["height"] = selected.getAttribute("height"); break;
case "use": case "use":
changes["x"] = selected.getAttribute("x"); attrs = ["x", "y"];
changes["y"] = selected.getAttribute("y");
break; break;
case "text": case "text":
changes["x"] = selected.getAttribute("x"); attrs = ["x", "y"];
changes["y"] = selected.getAttribute("y");
break; break;
case "polygon": case "polygon":
case "polyline": case "polyline":
@ -1836,6 +1826,10 @@ function BatchCommand(text) {
break; break;
} // switch on element type to get initial values } // switch on element type to get initial values
if(attrs.length) {
changes = $(selected).attr(attrs);
}
// if we haven't created an initial array in polygon/polyline/path, then // if we haven't created an initial array in polygon/polyline/path, then
// make a copy of initial values and include the transform // make a copy of initial values and include the transform
if (initial == null) { if (initial == null) {
@ -2149,10 +2143,7 @@ function BatchCommand(text) {
m = transformListToTransform(tlist).matrix; m = transformListToTransform(tlist).matrix;
switch (selected.tagName) { switch (selected.tagName) {
case 'line': case 'line':
changes.x1 = selected.getAttribute("x1"); changes = $(selected).attr(["x1","y1","x2","y2"]);
changes.y1 = selected.getAttribute("y1");
changes.x2 = selected.getAttribute("x2");
changes.y2 = selected.getAttribute("y2");
case 'polyline': case 'polyline':
case 'polygon': case 'polygon':
changes.points = selected.getAttribute("points"); changes.points = selected.getAttribute("points");
@ -3127,14 +3118,14 @@ function BatchCommand(text) {
break; break;
case "circle": case "circle":
var cx = shape.getAttributeNS(null, "cx"), var c = $(shape).attr(["cx", "cy"]);
cy = shape.getAttributeNS(null, "cy"), var cx = c.cx, cy = c.cy,
rad = Math.sqrt( (x-cx)*(x-cx) + (y-cy)*(y-cy) ); rad = Math.sqrt( (x-cx)*(x-cx) + (y-cy)*(y-cy) );
shape.setAttributeNS(null, "r", rad); shape.setAttributeNS(null, "r", rad);
break; break;
case "ellipse": case "ellipse":
var cx = shape.getAttributeNS(null, "cx"), var c = $(shape).attr(["cx", "cy"]);
cy = shape.getAttributeNS(null, "cy"), var 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);
@ -3304,26 +3295,21 @@ function BatchCommand(text) {
} }
break; break;
case "line": case "line":
// keep = (element.x1.baseVal.value != element.x2.baseVal.value || var attrs = $(element).attr(["x1", "x2", "y1", "y2"]);
// element.y1.baseVal.value != element.y2.baseVal.value); keep = (attrs.x1 != attrs.x2 || attrs.y1 != attrs.y2);
keep = (element.getAttribute('x1') != element.getAttribute('x2') || element.getAttribute('y1') != element.getAttribute('y2'));
break; break;
case "square": case "square":
case "rect": case "rect":
// keep = (element.width.baseVal.value && element.height.baseVal.value);
keep = (element.getAttribute('width') != 0 || element.getAttribute('height') != 0);
break;
case "image": case "image":
// keep = (element.width.baseVal.value && element.height.baseVal.value); var attrs = $(element).attr(["width", "height"]);
keep = (element.getAttribute('width') != 0 || element.getAttribute('height') != 0); keep = (attrs.width != 0 || attrs.height != 0);
break; break;
case "circle": case "circle":
// keep = (element.r.baseVal.value);
keep = (element.getAttribute('r') != 0); keep = (element.getAttribute('r') != 0);
break; break;
case "ellipse": case "ellipse":
// keep = (element.rx.baseVal.value && element.ry.baseVal.value); var attrs = $(element).attr(["rx", "ry"]);
keep = (element.getAttribute('rx') != null || element.getAttribute('ry') != null); keep = (attrs.rx != null || attrs.ry != null);
break; break;
case "fhellipse": case "fhellipse":
if ((freehand.maxx - freehand.minx) > 0 && if ((freehand.maxx - freehand.minx) > 0 &&
@ -5190,14 +5176,12 @@ function BatchCommand(text) {
switch (elem.tagName) { switch (elem.tagName) {
case 'ellipse': case 'ellipse':
var rx = elem.getAttribute('rx')-0;
var ry = elem.getAttribute('ry')-0;
case 'circle': case 'circle':
var a = $(elem).attr(['rx', 'ry', 'cx', 'cy']);
var cx = a.cx, cy = a.cy, rx = a.rx, ry = a.ry;
if(elem.tagName == 'circle') { if(elem.tagName == 'circle') {
var rx = ry = elem.getAttribute('r')-0; rx = ry = $(elem).attr('r');
} }
var cx = elem.getAttribute('cx')-0;
var cy = elem.getAttribute('cy')-0;
joinSegs([ joinSegs([
['M',[(cx-rx),(cy)]], ['M',[(cx-rx),(cy)]],
@ -5212,20 +5196,16 @@ function BatchCommand(text) {
d = elem.getAttribute('d'); d = elem.getAttribute('d');
break; break;
case 'line': case 'line':
var x1 = elem.getAttribute('x1'); var a = $(elem).attr(["x1", "y1", "x2", "y2"]);
var x2 = elem.getAttribute('x2'); d = "M"+a.x1+","+a.y1+"L"+a.x2+","+a.y2;
var y1 = elem.getAttribute('y1');
var y2 = elem.getAttribute('y2');
d = "M"+x1+","+y1+"L"+x2+","+y2;
break; break;
case 'polyline': case 'polyline':
case 'polygon': case 'polygon':
var points = elem.getAttribute('points'); d = "M" + elem.getAttribute('points');
d = "M"+points;
break; break;
case 'rect': case 'rect':
var rx = elem.getAttribute('rx')-0; var r = $(elem).attr(['rx', 'ry']);
var ry = elem.getAttribute('ry')-0; var rx = r.rx, ry = r.ry;
var b = elem.getBBox(); var b = elem.getBBox();
var x = b.x, y = b.y, w = b.width, h = b.height; var x = b.x, y = b.y, w = b.width, h = b.height;
var num = 4-num; // Why? Because! var num = 4-num; // Why? Because!
@ -5993,10 +5973,7 @@ function BatchCommand(text) {
return true; return true;
}; };
this.getOffset = function() { this.getOffset = function() {
return { return $(svgcontent).attr(['x', 'y']);
x: svgcontent.getAttribute('x'),
y: svgcontent.getAttribute('y')
};
} }
this.setBBoxZoom = function(val, editor_w, editor_h) { this.setBBoxZoom = function(val, editor_w, editor_h) {