window.windowManager = (function () { const container = document.getElementById("AppWindows"); let zIndexCounter = 1000; function open(options) { const win = document.createElement("div"); win.className = "app-window"; win.style.width = (options.width || 800) + "px"; win.style.height = (options.height || 600) + "px"; win.style.left = "50px"; win.style.top = "50px"; win.style.zIndex = ++zIndexCounter; // Titelbalk const titlebar = document.createElement("div"); titlebar.className = "app-titlebar"; const title = document.createElement("div"); title.className = "title"; title.textContent = options.title; const buttons = document.createElement("div"); buttons.className = "buttons"; const btnMin = document.createElement("button"); btnMin.textContent = "_"; const btnClose = document.createElement("button"); btnClose.textContent = "x"; buttons.appendChild(btnMin); buttons.appendChild(btnClose); titlebar.appendChild(title); titlebar.appendChild(buttons); // Content const content = document.createElement("div"); content.className = "app-content"; const iframe = document.createElement("iframe"); iframe.src = options.url; content.appendChild(iframe); win.appendChild(titlebar); win.appendChild(content); container.appendChild(win); // Drag makeDraggable(win, titlebar); // Close btnClose.addEventListener("click", () => { win.remove(); }); // Minimize btnMin.addEventListener("click", () => { win.style.display = "none"; minimizeToAppsBar(options, win); }); return win; } function minimizeToAppsBar(app, win) { const bar = document.getElementById("AppsBar"); const icon = document.createElement("div"); icon.className = "app-icon"; icon.title = app.title; const img = document.createElement("img"); img.src = app.icon; img.width = 32; img.height = 32; icon.appendChild(img); icon.addEventListener("click", () => { win.style.display = "flex"; win.style.zIndex = ++zIndexCounter; icon.remove(); }); bar.appendChild(icon); } function makeDraggable(win, handle) { let offsetX = 0, offsetY = 0; let dragging = false; handle.addEventListener("mousedown", (e) => { dragging = true; offsetX = e.clientX - win.offsetLeft; offsetY = e.clientY - win.offsetTop; win.style.zIndex = ++zIndexCounter; }); document.addEventListener("mousemove", (e) => { if (!dragging) return; win.style.left = (e.clientX - offsetX) + "px"; win.style.top = (e.clientY - offsetY) + "px"; }); document.addEventListener("mouseup", () => { dragging = false; }); } return { open }; })();