You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Modelbahn/webinterface/gui/guiwindow.js

138 lines
3.4 KiB

function gWindowGetClient(elmnt) {
var notes = null;
var result = null;
for (var i = 0; i < elmnt.childNodes.length; i++) {
if (elmnt.childNodes[i].className == "GUIwindowClient") {
result = elmnt.childNodes[i];
break;
}
}
return result;
}
function gWindowGetHead(elmnt) {
var notes = null;
var result = null;
for (var i = 0; i < elmnt.childNodes.length; i++) {
if (elmnt.childNodes[i].className == "GUIwindowHead") {
result = elmnt.childNodes[i];
break;
}
}
return result;
};
function gWindowDragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (gWindowGetHead(elmnt) != null) {
// if present, the header is where you move the DIV from:
gWindowGetHead(elmnt).onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2 - 1) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1 - 1) + "px";
}
function closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
}
function gWindowCreate(id, title, sizex, sizey, clientHTML) {
var win = document.getElementById(id);
if (!win) {
debug("create Title:" + title);
var head = document.createElement("div");
head.setAttribute("id", id+"Head");
head.setAttribute("class", "GUIwindowHead");
head.innerHTML = title;
var client = document.createElement("div");
client.setAttribute("id", id+"Client");
client.setAttribute("class", "GUIwindowClient");
client.setAttribute("style", "max-height:"+sizey+"px;max-width:"+sizex+"px;");
client.innerHTML = clientHTML;
win = document.createElement("div");
win.setAttribute("id", id);
win.setAttribute("class", "GUIwindow");
win.appendChild (head);
win.appendChild (client);
document.body.appendChild(win);
gWindowDragElement(win);
debug ("move to 100px from top");
win.style.top = "100px";
}
return win;
}
function gWindowCreateSize(id, title, sizex, sizey) {
var win = document.getElementById(id);
if (!win) {
debug("create Title:" + title);
var head = document.createElement("div");
head.setAttribute("id", id+"Head");
head.setAttribute("class", "GUIwindowHead");
head.innerHTML = title;
var client = document.createElement("div");
client.setAttribute("id", id+"Client");
client.setAttribute("class", "GUIwindowClient");
client.setAttribute("style", "max-height:"+sizey+"px;max-width:"+sizex+"px;");
client.style.height = sizey+"px";
client.style.width = sizex+"px";
win = document.createElement("div");
win.setAttribute("id", id);
win.setAttribute("class", "GUIwindow");
win.appendChild (head);
win.appendChild (client);
document.body.appendChild(win);
gWindowDragElement(win);
debug ("move to 100px from top");
win.style.top = "100px";
}
return win;
}