mirror of https://github.com/lgc-4/DataTools3.git
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
function addElement(type) {
|
|
if (type == "TextBox") {
|
|
document.getElementById("playground").appendChild(new TextBox().buildElement());
|
|
}
|
|
if (type == "Base64Converter") {
|
|
document.getElementById("playground").appendChild(new Base64Converter().buildElement());
|
|
}
|
|
}
|
|
|
|
class ConnectionController {
|
|
static currentlySelectedConnector = null;
|
|
|
|
static clickConnector(connector) {
|
|
if (this.currentlySelectedConnector) {
|
|
|
|
let a = this.currentlySelectedConnector;
|
|
let b = connector;
|
|
|
|
if (a == b) {
|
|
this.unselect();
|
|
return;
|
|
}
|
|
if (a.direction == b.direction) {
|
|
this.unselect();
|
|
this.clickConnector(b);
|
|
return;
|
|
}
|
|
|
|
if (b.connection) {
|
|
b.disconnectBoth();
|
|
}
|
|
|
|
a.element.classList.add("connected");
|
|
b.element.classList.add("connected");
|
|
|
|
a.connect(b);
|
|
b.connect(a);
|
|
|
|
a.element.classList.remove("connecting");
|
|
this.currentlySelectedConnector = null;
|
|
} else {
|
|
|
|
if (connector.connection) {
|
|
connector.disconnectBoth();
|
|
}
|
|
|
|
connector.element.classList.add("connecting");
|
|
this.currentlySelectedConnector = connector;
|
|
}
|
|
}
|
|
|
|
static unselect() {
|
|
if (!this.currentlySelectedConnector) return;
|
|
this.currentlySelectedConnector.element.classList.remove("connecting");
|
|
this.currentlySelectedConnector = null;
|
|
}
|
|
} |