-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
212 lines (184 loc) · 6.81 KB
/
script.js
File metadata and controls
212 lines (184 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Load Navigation Bar on All Pages
document.addEventListener("DOMContentLoaded", function() {
let navPlaceholder = document.getElementById("nav-placeholder");
if (navPlaceholder) {
fetch("nav.html")
.then(response => response.text())
.then(data => {
navPlaceholder.innerHTML = data;
})
.catch(error => console.error("Error loading navigation:", error));
}
});
// Back Button Functionality
function goBack() {
window.history.back();
}
// Save Inputs in LocalStorage
document.addEventListener("DOMContentLoaded", function() {
// Restore saved outcome input
if (document.getElementById("outcome")) {
let savedOutcome = localStorage.getItem("outcome");
if (savedOutcome) {
document.getElementById("outcome").value = savedOutcome;
}
document.getElementById("outcome").addEventListener("input", function() {
localStorage.setItem("outcome", this.value);
});
}
// Restore saved precondition input
if (document.getElementById("precondition")) {
let savedPrecondition = localStorage.getItem("precondition");
if (savedPrecondition) {
document.getElementById("precondition").value = savedPrecondition;
}
document.getElementById("precondition").addEventListener("input", function() {
localStorage.setItem("precondition", this.value);
});
}
// Load saved map on Map Page
if (document.getElementById("map")) {
loadMap();
}
});
// Handle End Goal submission
document.addEventListener("DOMContentLoaded", function() {
const outcomeInput = document.getElementById("outcome");
const submitOutcomeBtn = document.getElementById("submit-outcome-btn");
const outcomeDisplay = document.getElementById("outcome-display");
const mapContainer = document.getElementById("map");
if (submitOutcomeBtn) {
submitOutcomeBtn.addEventListener("click", function() {
const outcomeText = outcomeInput.value.trim();
if (outcomeText !== "") {
outcomeDisplay.textContent = "End Goal: " + outcomeText;
// Add End Goal block to map
mapContainer.innerHTML = `<div class="map-block" id="end-goal-block">${outcomeText}</div>`;
localStorage.setItem("endGoal", outcomeText);
}
});
}
// Restore saved End Goal
const savedEndGoal = localStorage.getItem("endGoal");
if (savedEndGoal && document.getElementById("end-goal-block") === null) {
outcomeDisplay.textContent = "End Goal: " + savedEndGoal;
mapContainer.innerHTML = `<div class="map-block" id="end-goal-block">${savedEndGoal}</div>`;
}
// Add preconditions to the map
const addPreconditionBtn = document.getElementById("add-precondition-btn");
if (addPreconditionBtn) {
addPreconditionBtn.addEventListener("click", function() {
const precondition = document.getElementById("precondition").value.trim();
if (precondition !== "") {
const block = document.createElement("div");
block.className = "map-block";
block.textContent = precondition;
const removeBtn = document.createElement("button");
removeBtn.className = "remove-btn";
removeBtn.innerHTML = "×";
removeBtn.addEventListener("click", () => block.remove());
block.appendChild(removeBtn);
mapContainer.appendChild(block);
document.getElementById("precondition").value = "";
}
});
}
// Finish Map button
const finishMapBtn = document.getElementById("finish-map-btn");
if (finishMapBtn) {
finishMapBtn.addEventListener("click", function() {
alert("Map submitted! AI feedback is now being generated (feature coming soon).");
});
}
});
// Add Preconditions to Map (Fix Button Click Issue)
document.addEventListener("DOMContentLoaded", function() {
let addPreconditionButton = document.getElementById("add-precondition-btn");
if (addPreconditionButton) {
addPreconditionButton.addEventListener("click", addPrecondition);
}
});
// Add Precondition to Map & Save
function addPrecondition() {
let precondition = document.getElementById("precondition").value.trim();
if (precondition === "") return;
let mapContainer = document.getElementById("map");
let block = document.createElement("div");
block.textContent = precondition;
block.className = "map-block";
block.draggable = true;
block.ondragstart = dragStart;
block.ondragover = dragOver;
block.ondrop = drop;
mapContainer.appendChild(block);
saveMap();
}
// Drag and Drop Functionality
function dragStart(event) {
event.dataTransfer.setData("text/plain", event.target.innerText);
event.target.classList.add("dragging");
}
function dragOver(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
let data = event.dataTransfer.getData("text/plain");
let block = document.createElement("div");
block.textContent = data;
block.className = "map-block";
block.draggable = true;
block.ondragstart = dragStart;
block.ondragover = dragOver;
block.ondrop = drop;
event.target.closest("#map").appendChild(block);
saveMap();
}
// Save & Load Map from LocalStorage
function saveMap() {
let preconditions = [];
document.querySelectorAll("#map .map-block").forEach(block => {
preconditions.push(block.textContent);
});
localStorage.setItem("userMap", JSON.stringify(preconditions));
}
function loadMap() {
let mapContainer = document.getElementById("map");
mapContainer.innerHTML = ""; // Clear existing blocks
let savedMap = JSON.parse(localStorage.getItem("userMap") || "[]");
savedMap.forEach(precondition => {
let block = document.createElement("div");
block.textContent = precondition;
block.className = "map-block";
block.draggable = true;
block.ondragstart = dragStart;
block.ondragover = dragOver;
block.ondrop = drop;
mapContainer.appendChild(block);
});
}
// Share Map (Copyable Link)
function shareMap() {
let link = `${window.location.origin}/map.html`;
navigator.clipboard.writeText(link).then(() => {
alert("Map link copied to clipboard!");
}).catch(err => {
console.error("Failed to copy: ", err);
});
}
// Theme Selection
function changeTheme() {
let theme = document.getElementById("theme").value;
if (theme === "dark") {
document.body.style.background = "#333";
document.body.style.color = "#fff";
} else {
document.body.style.background = "";
document.body.style.color = "";
}
}
// Logout Function
function logout() {
alert("You have been logged out.");
window.location.href = "index.html";
}