Use getNextId() when creating new elements, this ensures uniqueness (even if a file was loaded in)
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@311 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
a94592a52e
commit
b3484861e8
|
@ -494,6 +494,18 @@ function SvgCanvas(c)
|
||||||
return idprefix + obj_num;
|
return idprefix + obj_num;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getNextId = function() {
|
||||||
|
// ensure the ID does not exist
|
||||||
|
var id = getId();
|
||||||
|
while (svgdoc.getElementById(id)) {
|
||||||
|
obj_num++;
|
||||||
|
id = getId();
|
||||||
|
}
|
||||||
|
console.log(id);
|
||||||
|
return id;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
var call = function(event, arg) {
|
var call = function(event, arg) {
|
||||||
if (events[event]) {
|
if (events[event]) {
|
||||||
return events[event](this,arg);
|
return events[event](this,arg);
|
||||||
|
@ -875,7 +887,7 @@ function SvgCanvas(c)
|
||||||
"element": "path",
|
"element": "path",
|
||||||
"attr": {
|
"attr": {
|
||||||
"d": d_attr,
|
"d": d_attr,
|
||||||
"id": getId(),
|
"id": getNextId(),
|
||||||
"fill": "none",
|
"fill": "none",
|
||||||
"stroke": current_stroke,
|
"stroke": current_stroke,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke-width": current_stroke_width,
|
||||||
|
@ -903,7 +915,7 @@ function SvgCanvas(c)
|
||||||
"y": y,
|
"y": y,
|
||||||
"width": 0,
|
"width": 0,
|
||||||
"height": 0,
|
"height": 0,
|
||||||
"id": getId(),
|
"id": getNextId(),
|
||||||
"fill": current_fill,
|
"fill": current_fill,
|
||||||
"stroke": current_stroke,
|
"stroke": current_stroke,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke-width": current_stroke_width,
|
||||||
|
@ -923,7 +935,7 @@ function SvgCanvas(c)
|
||||||
"y1": y,
|
"y1": y,
|
||||||
"x2": x,
|
"x2": x,
|
||||||
"y2": y,
|
"y2": y,
|
||||||
"id": getId(),
|
"id": getNextId(),
|
||||||
"stroke": current_stroke,
|
"stroke": current_stroke,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke-width": current_stroke_width,
|
||||||
"stroke-dasharray": current_stroke_style,
|
"stroke-dasharray": current_stroke_style,
|
||||||
|
@ -941,7 +953,7 @@ function SvgCanvas(c)
|
||||||
"cx": x,
|
"cx": x,
|
||||||
"cy": y,
|
"cy": y,
|
||||||
"r": 0,
|
"r": 0,
|
||||||
"id": getId(),
|
"id": getNextId(),
|
||||||
"fill": current_fill,
|
"fill": current_fill,
|
||||||
"stroke": current_stroke,
|
"stroke": current_stroke,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke-width": current_stroke_width,
|
||||||
|
@ -961,7 +973,7 @@ function SvgCanvas(c)
|
||||||
"cy": y,
|
"cy": y,
|
||||||
"rx": 0,
|
"rx": 0,
|
||||||
"ry": 0,
|
"ry": 0,
|
||||||
"id": getId(),
|
"id": getNextId(),
|
||||||
"fill": current_fill,
|
"fill": current_fill,
|
||||||
"stroke": current_stroke,
|
"stroke": current_stroke,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke-width": current_stroke_width,
|
||||||
|
@ -979,7 +991,7 @@ function SvgCanvas(c)
|
||||||
"attr": {
|
"attr": {
|
||||||
"x": x,
|
"x": x,
|
||||||
"y": y,
|
"y": y,
|
||||||
"id": getId(),
|
"id": getNextId(),
|
||||||
"fill": current_fill,
|
"fill": current_fill,
|
||||||
"stroke": current_stroke,
|
"stroke": current_stroke,
|
||||||
"stroke-width": current_stroke_width,
|
"stroke-width": current_stroke_width,
|
||||||
|
@ -1292,7 +1304,6 @@ function SvgCanvas(c)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
d_attr = null;
|
d_attr = null;
|
||||||
obj_num++;
|
|
||||||
if (!keep && element != null) {
|
if (!keep && element != null) {
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
element = null;
|
element = null;
|
||||||
|
@ -1324,6 +1335,7 @@ function SvgCanvas(c)
|
||||||
|
|
||||||
// this function returns false if the set was unsuccessful, true otherwise
|
// this function returns false if the set was unsuccessful, true otherwise
|
||||||
// TODO: should this function keep throwing the exception?
|
// TODO: should this function keep throwing the exception?
|
||||||
|
// FIXME: after parsing in the new file, how do we synchronize getId()?
|
||||||
this.setSvgString = function(xmlString) {
|
this.setSvgString = function(xmlString) {
|
||||||
try {
|
try {
|
||||||
// convert string into XML document
|
// convert string into XML document
|
||||||
|
|
Loading…
Reference in New Issue