function addElement(element) { document.getElementById("playground").appendChild(element.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; } }