Files
webthink/workspaceResize.js

79 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2017-02-07 20:13:14 +00:00
const BOTTOMBORDER=100;
const RIGHTBORDER=300;
const LEFTBORDER=50;
const TOPBORDER=50;
document.maxX=0;
document.maxY=0;
dragNDrop.addSubscriber(notifyObjectMove,"endMoving");
function notifyObjectMove(publisher,eventType,addInfo){
if (("endMoving"==eventType) && (addInfo != null)){
var posX=parseInt(addInfo.style.left.split("px")[0]);
var posY=parseInt(addInfo.style.top.split("px")[0]);
if (posY<TOPBORDER){
moveAllNodes("vert",TOPBORDER);
}
if (posX<LEFTBORDER){
moveAllNodes("horiz",LEFTBORDER);
}
if (((posX+RIGHTBORDER)>document.maxX) || ((posY+BOTTOMBORDER)>document.maxY)) {
document.maxX=posX+RIGHTBORDER;
document.maxY=posY+BOTTOMBORDER;
resizeWorkspace();
}
}
}
function moveAllNodes(axis,pixels){
var allNodes=document.getElementById("nodes").childNodes;
for (var i=0;i<allNodes.length;i++){
var theNode=allNodes[i];
if (axis=="horiz"){
theNode.style.left=(parseInt(theNode.style.left.split("px")[0])+pixels)+"px";
} else {
theNode.style.top=(parseInt(theNode.style.top.split("px")[0])+pixels)+"px";
}
theNode.redrawNodeRelations();
}
}
function resizeWorkspace(){
var rightBottom=document.getElementById("rightBottom");
rightBottom.style.left=document.maxX + "px";
rightBottom.style.top=document.maxY + "px";
}
function autoRepositionNodes(){
var minLeft=99999;
var minTop=99999;
var allNodes=document.getElementById("nodes").childNodes;
for (var i=0;i<allNodes.length;i++){
var theNode=allNodes[i];
var currTop=parseInt(theNode.style.top.split("px")[0]);
var currLeft=parseInt(theNode.style.left.split("px")[0]);
if (currTop < minTop) { minTop=currTop; }
if (currLeft < minLeft) { minLeft=currLeft; }
}
moveAllNodes("horiz",(minLeft*-1)+LEFTBORDER);
moveAllNodes("vert",(minTop*-1)+TOPBORDER);
}
function drawBorders(){
var horizTopBorder=document.createElement("div");
horizTopBorder.setAttribute("class","horizTopBorder");
document.getElementById("generalControls").appendChild(horizTopBorder);
horizTopBorder.style.height=TOPBORDER + "px";
var vertLeftBorder=document.createElement("div");
vertLeftBorder.setAttribute("class","vertLeftBorder");
document.getElementById("generalControls").appendChild(vertLeftBorder);
vertLeftBorder.style.width=LEFTBORDER + "px";
}