Sindbad~EG File Manager
// The following function is used to put SVG output into whatever container
// the interface designers choose.
function moveSvgElementToContainer(svgElementId, destinationContainerId) {
var svgElement = document.getElementById(svgElementId);
var destinationContainer = document.getElementById(destinationContainerId);
if (svgElement && destinationContainer) {
destinationContainer.style.position = 'absolute';
// destinationContainer.style.left = what you want, e.g. svgElement.style.left;
// This should be done by the calling function
// destinationContainer.style.top = svgElement.style.top;
var computedStyle = window.getComputedStyle(destinationContainer);
var paddingLeft = parseFloat(computedStyle.paddingLeft);
var paddingTop = parseFloat(computedStyle.paddingTop);
var borderLeftWidth = parseFloat(computedStyle.borderLeftWidth);
var borderTopWidth = parseFloat(computedStyle.borderTopWidth);
var svgRect = svgElement.getBoundingClientRect();
// console.log(svgElementId,svgRect,paddingLeft,borderLeftWidth);
let newWidth = 2*paddingLeft+2*borderLeftWidth + svgRect.width;
destinationContainer.style.width = newWidth + 'px';
// console.log(svgElementId,destinationContainer.style.width);
//destinationContainer.style.width = destinationContainer.style.width + 'px';
// This old code did not allow for padding and border in the containter.
//console.log(svgElementId,destinationContainer.style.width);
destinationContainer.style.height = svgRect.height + 'px';
// Now move the SVG element to the destination container
destinationContainer.appendChild(svgElement);
// console.log("moving ",svgElement, " to ", destinationContainer);
// Since the SVG is now positioned relative to its new container, reset its position
let newleft = paddingLeft + borderLeftWidth -4 ; // the svg element allows 8 pixels of space, but it looks better with 4 here, not 8
svgElement.style.left = newleft + 'px';
svgElement.style.top = '0px';
// Also set x and y; I thought this might help with Firefox, but it didn't. Anyway I left it here.
if (svgElement.hasAttribute("x") && svgElement.hasAttribute("y")) {
svgElement.setAttribute("x", newleft);
svgElement.setAttribute("y", 0);
}
}
else
{
if(svgElement)
{
console.error('destination container not found; not necessarily an error.');
}
else
{
console.error('SVG element not found; not necessarily an error.');
console.error(svgElementId);
}
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists