Reduced repetitive styling code

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1497 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Alexis Deveria
2010-04-01 20:01:20 +00:00
parent e445baeadd
commit 753270d730

View File

@@ -1172,6 +1172,19 @@ function BatchCommand(text) {
current_layer.appendChild(shape); current_layer.appendChild(shape);
} }
} }
if(data.curStyles) {
assignAttributes(shape, {
"fill": cur_shape.fill,
"stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
"opacity": cur_shape.opacity / 2,
"style": "pointer-events:inherit"
}, 100);
}
assignAttributes(shape, data.attr, 100); assignAttributes(shape, data.attr, 100);
cleanupElement(shape); cleanupElement(shape);
return shape; return shape;
@@ -1213,7 +1226,7 @@ function BatchCommand(text) {
stroke_opacity: curConfig.initStroke.opacity, stroke_opacity: curConfig.initStroke.opacity,
stroke_width: curConfig.initStroke.width, stroke_width: curConfig.initStroke.width,
stroke_dasharray: 'none', stroke_dasharray: 'none',
stroke_linejoin: 'none', stroke_linejoin: 'miter',
opacity: curConfig.initOpacity opacity: curConfig.initOpacity
} }
}; };
@@ -3009,17 +3022,13 @@ function BatchCommand(text) {
var stroke_w = cur_shape.stroke_width == 0?1:cur_shape.stroke_width; var stroke_w = cur_shape.stroke_width == 0?1:cur_shape.stroke_width;
addSvgElementFromJson({ addSvgElementFromJson({
"element": "polyline", "element": "polyline",
"curStyles": true,
"attr": { "attr": {
"points": d_attr, "points": d_attr,
"id": getNextId(), "id": getNextId(),
"fill": "none", "fill": "none",
"stroke": cur_shape.stroke,
"stroke-width": stroke_w,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-opacity": cur_shape.stroke_opacity,
"stroke-linecap": "round",
"stroke-linejoin": cur_shape.stroke_linejoin,
"opacity": cur_shape.opacity / 2, "opacity": cur_shape.opacity / 2,
"stroke-linecap": "round",
"style": "pointer-events:none" "style": "pointer-events:none"
} }
}); });
@@ -3056,21 +3065,14 @@ function BatchCommand(text) {
start_y = y; start_y = y;
addSvgElementFromJson({ addSvgElementFromJson({
"element": "rect", "element": "rect",
"curStyles": true,
"attr": { "attr": {
"x": x, "x": x,
"y": y, "y": y,
"width": 0, "width": 0,
"height": 0, "height": 0,
"id": getNextId(), "id": getNextId(),
"fill": cur_shape.fill, "opacity": cur_shape.opacity / 2
"stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
"opacity": cur_shape.opacity / 2,
"style": "pointer-events:inherit"
} }
}); });
break; break;
@@ -3079,6 +3081,7 @@ function BatchCommand(text) {
var stroke_w = cur_shape.stroke_width == 0?1:cur_shape.stroke_width; var stroke_w = cur_shape.stroke_width == 0?1:cur_shape.stroke_width;
addSvgElementFromJson({ addSvgElementFromJson({
"element": "line", "element": "line",
"curStyles": true,
"attr": { "attr": {
"x1": x, "x1": x,
"y1": y, "y1": y,
@@ -3100,20 +3103,13 @@ function BatchCommand(text) {
started = true; started = true;
addSvgElementFromJson({ addSvgElementFromJson({
"element": "circle", "element": "circle",
"curStyles": true,
"attr": { "attr": {
"cx": x, "cx": x,
"cy": y, "cy": y,
"r": 0, "r": 0,
"id": getNextId(), "id": getNextId(),
"fill": cur_shape.fill, "opacity": cur_shape.opacity / 2
"stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
"opacity": cur_shape.opacity / 2,
"style": "pointer-events:inherit"
} }
}); });
break; break;
@@ -3121,21 +3117,14 @@ function BatchCommand(text) {
started = true; started = true;
addSvgElementFromJson({ addSvgElementFromJson({
"element": "ellipse", "element": "ellipse",
"curStyles": true,
"attr": { "attr": {
"cx": x, "cx": x,
"cy": y, "cy": y,
"rx": 0, "rx": 0,
"ry": 0, "ry": 0,
"id": getNextId(), "id": getNextId(),
"fill": cur_shape.fill, "opacity": cur_shape.opacity / 2
"stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
"opacity": cur_shape.opacity / 2,
"style": "pointer-events:inherit"
} }
}); });
break; break;
@@ -3143,23 +3132,16 @@ function BatchCommand(text) {
started = true; started = true;
var newText = addSvgElementFromJson({ var newText = addSvgElementFromJson({
"element": "text", "element": "text",
"curStyles": true,
"attr": { "attr": {
"x": x, "x": x,
"y": y, "y": y,
"id": getNextId(), "id": getNextId(),
"fill": cur_text.fill, "fill": cur_text.fill,
"stroke": cur_shape.stroke,
"stroke-width": cur_text.stroke_width, "stroke-width": cur_text.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
// fix for bug where text elements were always 50% opacity
"opacity": cur_shape.opacity,
"font-size": cur_text.font_size, "font-size": cur_text.font_size,
"font-family": cur_text.font_family, "font-family": cur_text.font_family,
"text-anchor": "middle", "text-anchor": "middle",
"style": "pointer-events:inherit",
"xml:space": "preserve" "xml:space": "preserve"
} }
}); });
@@ -3630,21 +3612,13 @@ function BatchCommand(text) {
(freehand.maxy - freehand.miny) > 0) { (freehand.maxy - freehand.miny) > 0) {
element = addSvgElementFromJson({ element = addSvgElementFromJson({
"element": "ellipse", "element": "ellipse",
"curStyles": true,
"attr": { "attr": {
"cx": (freehand.minx + freehand.maxx) / 2, "cx": (freehand.minx + freehand.maxx) / 2,
"cy": (freehand.miny + freehand.maxy) / 2, "cy": (freehand.miny + freehand.maxy) / 2,
"rx": (freehand.maxx - freehand.minx) / 2, "rx": (freehand.maxx - freehand.minx) / 2,
"ry": (freehand.maxy - freehand.miny) / 2, "ry": (freehand.maxy - freehand.miny) / 2,
"id": getId(), "id": getId()
"fill": cur_shape.fill,
"stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"opacity": cur_shape.opacity,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
"style": "pointer-events:inherit"
} }
}); });
call("changed",[element]); call("changed",[element]);
@@ -3656,21 +3630,13 @@ function BatchCommand(text) {
(freehand.maxy - freehand.miny) > 0) { (freehand.maxy - freehand.miny) > 0) {
element = addSvgElementFromJson({ element = addSvgElementFromJson({
"element": "rect", "element": "rect",
"curStyles": true,
"attr": { "attr": {
"x": freehand.minx, "x": freehand.minx,
"y": freehand.miny, "y": freehand.miny,
"width": (freehand.maxx - freehand.minx), "width": (freehand.maxx - freehand.minx),
"height": (freehand.maxy - freehand.miny), "height": (freehand.maxy - freehand.miny),
"id": getId(), "id": getId()
"fill": cur_shape.fill,
"stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"opacity": cur_shape.opacity,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
"style": "pointer-events:inherit"
} }
}); });
call("changed",[element]); call("changed",[element]);
@@ -4644,20 +4610,13 @@ function BatchCommand(text) {
// create new path element // create new path element
element = addSvgElementFromJson({ element = addSvgElementFromJson({
"element": "path", "element": "path",
"attr": { "curStyles": true,
"id": getId(), "attr": {
"d": d, "id": getId(),
"fill": "none", "d": d,
"stroke": cur_shape.stroke, "fill": "none"
"stroke-width": cur_shape.stroke_width, }
"stroke-dasharray": cur_shape.stroke_dasharray, });
"stroke-linejoin": cur_shape.stroke_linejoin,
"opacity": cur_shape.opacity,
"stroke-opacity": cur_shape.stroke_opacity,
"fill-opacity": cur_shape.fill_opacity,
"style": "pointer-events:inherit"
}
});
call("changed",[element]); call("changed",[element]);
} }
return element; return element;
@@ -4912,18 +4871,12 @@ function BatchCommand(text) {
d_attr = "M" + x + "," + y + " "; d_attr = "M" + x + "," + y + " ";
addSvgElementFromJson({ addSvgElementFromJson({
"element": "path", "element": "path",
"curStyles": true,
"attr": { "attr": {
"d": d_attr, "d": d_attr,
"id": getNextId(), "id": getNextId(),
"fill": cur_shape.fill,
"fill-opacity": cur_shape.fill_opacity,
"stroke": cur_shape.stroke,
"stroke-width": cur_shape.stroke_width,
"stroke-dasharray": cur_shape.stroke_dasharray,
"stroke-linejoin": cur_shape.stroke_linejoin,
"stroke-opacity": cur_shape.stroke_opacity,
"opacity": cur_shape.opacity / 2, "opacity": cur_shape.opacity / 2,
"style": "pointer-events:inherit"
} }
}); });
// set stretchy line to first point // set stretchy line to first point