Fix Issue 228: Cloned children are given unique ids

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@785 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-10-09 05:34:01 +00:00
parent f7fb4255b6
commit 48a2aa8dc7
1 changed files with 25 additions and 34 deletions

View File

@ -4326,34 +4326,25 @@ function BatchCommand(text) {
} }
}; };
// this creates deep DOM copies (clones) of all selected elements // this function no longer uses cloneNode because we need to update the id
this.cloneSelectedElements = function() { // of every copied element (even the descendants)
var copyElem = function(el) { // we also do it manually because Opera/Win/non-EN puts , instead of .
// Manual clone function for Opera/Win/non-EN. var copyElem = function(el) {
// Needed because cloneNode changes "." to "," on float values // manually create a copy of the element
if(!window.opera) { var new_el = document.createElementNS(svgns, el.nodeName);
var newElem = el.cloneNode(true); $.each(el.attributes, function(i, attr) {
// Webkit has a bug where a cloned element's transforms become matrix() var ns = attr.nodeName == 'href'?xlinkns:null;
// we need to replace those with the original element's transforms new_el.setAttributeNS(ns, attr.nodeName, attr.nodeValue);
// TODO: raise webkit bug });
var origtlist = el.transform.baseVal, // set the copied element's new id
newtlist = newElem.transform.baseVal; new_el.removeAttribute("id");
while (newtlist.numberOfItems > 0) { new_el.id = getNextId();
newtlist.removeItem(0); // manually increment obj_num because our cloned elements are not in the DOM yet
} obj_num++;
for (var j = 0; j < origtlist.numberOfItems; ++j) {
newtlist.appendItem( origtlist.getItem(j) );
}
return newElem;
}
var new_el = document.createElementNS(svgns, el.nodeName);
$.each(el.attributes, function(i, attr) {
var ns = attr.nodeName == 'href'?xlinkns:null;
new_el.setAttributeNS(ns, attr.nodeName, attr.nodeValue);
});
$.each(el.childNodes, function(i, child) { // now create copies of all children
switch(child.nodeType) { $.each(el.childNodes, function(i, child) {
switch(child.nodeType) {
case 1: // element node case 1: // element node
new_el.appendChild(copyElem(child)); new_el.appendChild(copyElem(child));
break; break;
@ -4362,11 +4353,13 @@ function BatchCommand(text) {
break; break;
default: default:
break; break;
} }
}); });
return new_el; return new_el;
} };
// this creates deep DOM copies (clones) of all selected elements
this.cloneSelectedElements = function() {
var batchCmd = new BatchCommand("Clone Elements"); var batchCmd = new BatchCommand("Clone Elements");
// find all the elements selected (stop at first null) // find all the elements selected (stop at first null)
var len = selectedElements.length; var len = selectedElements.length;
@ -4383,8 +4376,6 @@ function BatchCommand(text) {
while (i--) { while (i--) {
// clone each element and replace it within copiedElements // clone each element and replace it within copiedElements
var elem = copiedElements[i] = copyElem(copiedElements[i]); var elem = copiedElements[i] = copyElem(copiedElements[i]);
elem.removeAttribute("id");
elem.id = getNextId();
current_layer.appendChild(elem); current_layer.appendChild(elem);
batchCmd.addSubCommand(new InsertElementCommand(elem)); batchCmd.addSubCommand(new InsertElementCommand(elem));
} }