diff --git a/planet/js/Planet.js b/planet/js/Planet.js index d50fd9aec1..ae8c2d84a8 100644 --- a/planet/js/Planet.js +++ b/planet/js/Planet.js @@ -95,6 +95,71 @@ class Planet { this.GlobalPlanet.openGlobalProject(id, error); } + showNewProjectConfirmation() { + const button = document.getElementById("planet-new-project"); + const rect = button.getBoundingClientRect(); + + // Remove existing confirmation if any + const old = document.getElementById("new-project-confirmation"); + if (old) old.remove(); + + const modal = document.createElement("div"); + modal.id = "new-project-confirmation"; + modal.style.position = "absolute"; + modal.style.top = rect.bottom + window.scrollY + 8 + "px"; + modal.style.left = rect.left + window.scrollX + "px"; + modal.style.background = "#1b5e20"; // dark green + modal.style.color = "#ffffff"; + modal.style.padding = "16px"; + modal.style.borderRadius = "10px"; + modal.style.width = "260px"; + modal.style.boxShadow = "0 6px 16px rgba(0,0,0,0.3)"; + modal.style.zIndex = "10000"; + modal.style.fontFamily = "sans-serif"; + modal.style.animation = "fadeIn 0.15s ease-out"; + + modal.innerHTML = ` +
+ Start New Project? +
+
+ Unsaved changes will be lost. +
+
+ + +
+ `; + + document.body.appendChild(modal); + + // Cancel + modal.querySelector("#cancel-new").onclick = e => { + e.stopPropagation(); + modal.remove(); + }; + + // Confirm + modal.querySelector("#confirm-new").onclick = () => { + modal.remove(); + this.loadNewProject(); + }; + + // Click outside to close + document.addEventListener("click", function handler(e) { + if (!modal.contains(e.target) && e.target !== button) { + modal.remove(); + document.removeEventListener("click", handler); + } + }); + } + async init() { this.StringHelper = new StringHelper(this); this.StringHelper.init(); @@ -116,7 +181,9 @@ class Planet { // eslint-disable-next-line no-unused-vars document.getElementById("planet-new-project").addEventListener("click", evt => { - this.loadNewProject(); + evt.preventDefault(); + evt.stopPropagation(); + this.showNewProjectConfirmation(); }); this.ServerInterface.getTagManifest( @@ -127,10 +194,7 @@ class Planet { } closeButton() { - if (this.ProjectStorage.getCurrentProjectID() !== this.oldCurrentProjectID) { - const data = this.ProjectStorage.getCurrentProjectData(); - !data ? this.loadNewProject() : this.loadProjectFromData(data); - } else this.planetClose(); + this.planetClose(); } initPlanets(tags) {