Fixed issue 487: foreignObject extension breaks connect two objects tool and made sure both extensions work together

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1409 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-02-18 15:42:10 +00:00
parent 8e0bf800bf
commit 78c9ae4ad7
3 changed files with 73 additions and 74 deletions

View File

@ -72,74 +72,48 @@ $(function() {
setPoint(elem, 1, (pt_end.x + pt_start.x)/2, (pt_end.y + pt_start.y)/2);
}
}
function findConnectors() {
// Check if selected elements have connections
var elems = selElems;
var i = elems.length;
var connectors = $(svgcontent).find(conn_sel);
if(!connectors.length) return;
connections = [];
var sel = ':not(a,g,svg,'+conn_sel+')';
var all_els = [];
// Get children from groups
while(i--) {
var elem = elems[i];
if(!elem) continue;
// Get all children that cannot contain children
var solid_elems = $(elem).find(sel);
// Include self if okay
if($(elem).filter(sel).length) {
solid_elems.push(elem);
}
$.merge(all_els, solid_elems);
}
i = all_els.length;
if(i > 1) {
// Multiselected, so unselect connector
svgCanvas.removeFromSelection($(conn_sel).toArray());
}
// Loop through selected elements
while(i--) {
var elem = all_els[i];
if(!elem) continue;
// Loop through connectors to see if one is connected to the element
connectors.each(function() {
var start = $(this).data("c_start");
var end = $(this).data("c_end");
// Element was deleted, so delete connector
var was_deleted = !elem.parentNode;
// Skip connector
if($(elem).data('c_start')) continue;
// Loop through connectors to see if one is connected to the element
connectors.each(function() {
var start = $(this).data("c_start");
var end = $(this).data("c_end");
// Connector found for this element
if(start == elem.id || end == elem.id) {
if(was_deleted) {
$(this).remove();
return;
var parts = [getElem(start), getElem(end)];
for(var i=0; i<2; i++) {
var c_elem = parts[i];
var add_this = false;
// The connected element might be part of a selected group
$(c_elem).parents().each(function() {
if($.inArray(this, elems) !== -1) {
// Pretend this element is selected
add_this = true;
}
var bb = svgCanvas.getStrokedBBox([elem]);
});
if(!c_elem || !c_elem.parentNode) {
$(this).remove();
continue;
}
if($.inArray(c_elem, elems) !== -1 || add_this) {
var bb = svgCanvas.getStrokedBBox([c_elem]);
connections.push({
elem: elem,
elem: c_elem,
connector: this,
is_start: start == elem.id,
is_start: (i === 0),
start_x: bb.x,
start_y: bb.y
});
}
});
}
}
});
}
function updateConnectors() {
// Updates connector lines based on selected elements
// Is not used on mousemove, as it runs getStrokedBBox every time,
@ -300,7 +274,6 @@ $(function() {
},
mouseDown: function(opts) {
var e = opts.event;
start_x = opts.start_x,
start_y = opts.start_y;
var mode = svgCanvas.getMode();
@ -315,8 +288,10 @@ $(function() {
if($.inArray(svgcontent, parents) != -1) {
// Connectable element
start_elem = mouse_target;
// If child of foreignObject, use parent
var fo = $(mouse_target).closest("foreignObject");
start_elem = fo.length ? fo[0] : mouse_target;
// Get center of source element
var bb = svgCanvas.getStrokedBBox([start_elem]);
@ -422,10 +397,13 @@ $(function() {
var zoom = svgCanvas.getZoom();
var e = opts.event,
x = opts.mouse_x/zoom,
y = opts.mouse_y/zoom;
y = opts.mouse_y/zoom,
mouse_target = e.target;
if(svgCanvas.getMode() == "connector") {
if(e.target.parentNode.parentNode != svgcontent) {
var fo = $(mouse_target).closest("foreignObject");
if(fo.length) mouse_target = fo[0];
if(mouse_target.parentNode.parentNode != svgcontent) {
// Not a valid target element, so remove line
$(cur_line).remove();
started = false;
@ -434,7 +412,7 @@ $(function() {
element: null,
started: started
}
} else if(e.target == start_elem) {
} else if(mouse_target == start_elem) {
// Start line through click
started = true;
return {
@ -444,7 +422,8 @@ $(function() {
}
} else {
// Valid end element
end_elem = e.target;
end_elem = mouse_target;
var start_id = start_elem.id, end_id = end_elem.id;
var conn_str = start_id + " " + end_id;
var alt_str = end_id + " " + start_id;

View File

@ -63,7 +63,6 @@ $(function() {
var newDoc = Utils.text2xml('<svg xmlns="'+svgns+'" xmlns:xlink="'+xlinkns+'">'+xmlString+'</svg>');
// run it through our sanitizer to remove anything we do not support
S.sanitizeSvg(newDoc.documentElement);
elt.parentNode.replaceChild(svgdoc.importNode(newDoc.documentElement.firstChild, true), elt);
S.call("changed", [elt]);
svgCanvas.clearSelection();

View File

@ -2653,6 +2653,7 @@ function BatchCommand(text) {
};
var hasMatrixTransform = function(tlist) {
if(!tlist) return false;
var num = tlist.numberOfItems;
while (num--) {
var xform = tlist.getItem(num);
@ -3089,11 +3090,13 @@ function BatchCommand(text) {
start_x: start_x,
start_y: start_y,
selectedElements: selectedElements
});
}, true);
if(ext_result) {
started = ext_result.started;
}
$.each(ext_result, function(i, r) {
if(r && r.started) {
started = true;
}
});
};
// in this function we do not record any state changes yet (but we do update
@ -3610,13 +3613,15 @@ function BatchCommand(text) {
event: evt,
mouse_x: mouse_x,
mouse_y: mouse_y
});
}, true);
if(ext_result) {
keep = ext_result.keep;
element = ext_result.element;
started = ext_result.started;
}
$.each(ext_result, function(i, r) {
if(r) {
keep = r.keep || keep;
element = r.element;
started = r.started || started;
}
});
if (!keep && element != null) {
element.parentNode.removeChild(element);
@ -6613,7 +6618,19 @@ function BatchCommand(text) {
ret.y += parseFloat(selected.getAttribute('y'));
} else {
try { ret = selected.getBBox(); }
catch(e) { ret = null; }
catch(e) {
// Check if element is child of a foreignObject
var fo = $(selected).closest("foreignObject");
if(fo.length) {
try {
ret = fo[0].getBBox();
} catch(e) {
ret = null;
}
} else {
ret = null;
}
}
}
// get the bounding box from the DOM (which is in that element's coordinate system)
@ -7337,6 +7354,7 @@ function BatchCommand(text) {
// re-creating the getCheckedBBox() function? shouldn't we make this a function
// at the 'canvas' level
var getCheckedBBox = function(elem) {
try {
// TODO: Fix issue with rotated groups. Currently they work
// fine in FF, but not in other browsers (same problem mentioned
@ -7410,7 +7428,10 @@ function BatchCommand(text) {
}
return bb;
} catch(e) { return null; }
} catch(e) {
console.log(elem, e);
return null;
}
}
var full_bb;