-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
289 lines (235 loc) · 10 KB
/
script.js
File metadata and controls
289 lines (235 loc) · 10 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
document.addEventListener('DOMContentLoaded', () => {
const downloadButtons = document.querySelectorAll('.download-btn');
const searchInput = document.getElementById("search-input");
const templateCards = document.querySelectorAll(".template-card");
const tagElements = document.querySelectorAll(".keyword");
// Download Button Logic
downloadButtons.forEach(button => {
button.addEventListener('click', () => {
const template = button.getAttribute('data-template');
const link = document.createElement('a');
link.href = `downloads/${template}`;
link.download = template;
link.click();
});
});
// Search Filter Logic
searchInput.addEventListener("input", function () {
const query = this.value.trim().toLowerCase();
templateCards.forEach(card => {
const tags = card.getAttribute("data-tags")?.toLowerCase() || "";
const isMatch = tags.includes(query) || query === "";
card.classList.toggle("hidden", !isMatch);
});
});
// Tag Click = Filter
tagElements.forEach(tag => {
tag.addEventListener("click", () => {
const tagText = tag.getAttribute("data-tag");
searchInput.value = tagText;
searchInput.dispatchEvent(new Event("input"));
});
});
// File Upload Preview (optional enhancement)
const fileInput = document.getElementById("actual-btn");
fileInput?.addEventListener("change", function () {
if (this.files && this.files[0]) {
alert(`Selected file: ${this.files[0].name}`);
}
});
});
const modal = document.getElementById("uploadModal");
const btn = document.getElementById("upload-template-card");
const span = document.querySelector(".close");
btn.onclick = () => modal.style.display = "block";
span.onclick = () => modal.style.display = "none";
window.onclick = (event) => {
if (event.target === modal) {
modal.style.display = "none";
}
};
// document.getElementById("templateUploadForm").addEventListener("submit", function (e) {
// e.preventDefault();
// // const name = document.getElementById("templateName").value;
// // const keywords = document.getElementById("templateKeywords").value;
// // const description = document.getElementById("templateDescription").value;
// // const files = document.getElementById("templateFiles").files;
// // need to send to backend or save to local storage
// // console.log({ name, keywords, description, files });
// // alert("Template submitted! (Form handling not yet implemented)");
// // modal.style.display = "none";
// // this.reset();
// const name = document.getElementById('templateName').value;
// const keywords = document.getElementById('templateKeywords').value;
// // const file = document.getElementById('templateFile').files[0];
// // Create new grid item
// const newCard = document.createElement('div');
// newCard.classList.add('template-card');
// newCard.innerHTML = `
// <div class="template-thumb">📦</div>
// <div class="template-info">
// <h3>${name}</h3>
// <p>${keywords}</p>
// <a href="#" class="download-link">Download</a>
// </div>
// `;
// // Append to the grid
// document.getElementById('template-grid').appendChild(newCard);
// // Optional: clear form & close modal
// document.getElementById('templateForm').reset();
// document.getElementById('uploadModal').style.display = 'none';
// });
// document.addEventListener("DOMContentLoaded", function () {
// document.getElementById("templateUploadForm").addEventListener("submit", function (e) {
// e.preventDefault();
// const name = document.getElementById('templateName').value;
// const keywords = document.getElementById('templateKeywords').value;
// const newCard = document.createElement('div');
// newCard.innerHTML = `
// <img src="template-placeholder.jpg" alt="${name}">
// <h3>${name}</h3>
// <p>${'No description provided.'}</p>
// <div class="tags">
// ${keywords.split(',').map(tag => `<span class="keyword">${tag.trim()}</span>`).join('')}
// </div>
// <button class="preview-btn" data-template="#">Preview</button>
// <button class="download-btn" data-template="#">Download</button>
// <p class="creator">Created by: You</p>
// `;
// const grid = document.getElementById('template-grid');
// const lastCard = grid.lastElementChild;
// grid.insertBefore(newCard, lastCard)
// document.getElementById('templateUploadForm').reset();
// document.getElementById('uploadModal').style.display = 'none';
// });
// });
// document.addEventListener("DOMContentLoaded", function () {
// document.getElementById("templateUploadForm").addEventListener("submit", function (e) {
// e.preventDefault();
// const name = document.getElementById('templateName').value;
// const keywords = document.getElementById('templateKeywords').value;
// const newCard = document.createElement('div');
// newCard.classList.add('template-card'); // <-- add class here
// newCard.innerHTML = `
// <img src="template-placeholder.jpg" alt="${name}">
// <h3>${name}</h3>
// <p>${'No description provided.'}</p>
// <div class="tags">
// ${keywords.split(',').map(tag => `<span class="keyword">${tag.trim()}</span>`).join('')}
// </div>
// <button class="preview-btn" data-template="#">Preview</button>
// <button class="download-btn" data-template="#">Download</button>
// <p class="creator">Created by: You</p>
// `;
// // const grid = document.getElementById('template-grid');
// // // Append at the end instead of insertBefore lastCard
// // grid.appendChild(newCard);
// const grid = document.getElementById('template-grid');
// const lastCard = grid.lastElementChild;
// grid.insertBefore(newCard, grid.firstChild);
// document.getElementById('templateUploadForm').reset();
// document.getElementById('uploadModal').style.display = 'none';
// });
// });
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("templateUploadForm");
form.addEventListener("submit", function (e) {
e.preventDefault();
const name = document.getElementById('templateName').value;
const keywords = document.getElementById('templateKeywords').value;
const description = document.getElementById('templateDescription').value || "No description provided.";
const imageFile = document.getElementById('templateImage').files[0];
const folderFiles = document.getElementById('templateFiles').files;
if (!imageFile || folderFiles.length === 0) {
alert("Please upload an image and a folder.");
return;
}
const reader = new FileReader();
reader.onload = function (e) {
const imageSrc = e.target.result;
const newCard = document.createElement('div');
newCard.classList.add("template-card");
newCard.setAttribute("data-tags", keywords);
const firstFileName = folderFiles[0].webkitRelativePath.split('/')[0];
const fakeZipName = firstFileName + '.zip';
newCard.innerHTML = `
<img src="${imageSrc}" alt="${name}">
<span class="type-tag">Custom Template</span>
<h3>${name}</h3>
<p>${description}</p>
<div class="tags">
${keywords.split(',').map(tag => `<span class="keyword">${tag.trim()}</span>`).join('')}
</div>
<button class="preview-btn" data-template="${fakeZipName}">Preview</button>
<button class="download-btn" data-template="${fakeZipName}">Download</button>
<p class="creator">Created by: You</p>
`;
const grid = document.getElementById('template-grid');
const cards = grid.querySelectorAll(".template-card");
const secondToLastCard = cards.length > 1 ? cards[cards.length - 1].previousElementSibling : null;
if (secondToLastCard) {
grid.insertBefore(newCard, secondToLastCard.nextSibling);
} else {
grid.appendChild(newCard);
}
form.reset();
document.getElementById('uploadModal').style.display = 'none';
document.body.style.overflow = '';
};
reader.readAsDataURL(imageFile);
});
});
// download function
function download(url) {
const a = document.createElement('a');
a.href = url;
a.download = url.split('/').pop();
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
// for real estate
document.getElementById("preview1").onclick = () => {
document.getElementById("mapModal1").style.display = "flex";
};
document.getElementById("closeMapBtn1").onclick = () => {
document.getElementById("mapModal1").style.display = "none";
};
window.onclick = (event) => {
if (event.target === document.getElementById("mapModal1")) {
document.getElementById("mapModal1").style.display = "none";
}
};
// for tour map
document.getElementById("preview2").onclick = () => {
document.getElementById("mapModal2").style.display = "flex";
};
document.getElementById("closeMapBtn2").onclick = () => {
document.getElementById("mapModal2").style.display = "none";
};
window.onclick = (event) => {
if (event.target === document.getElementById("mapModal2")) {
document.getElementById("mapModal2").style.display = "none";
}
};
// for basic map
document.getElementById("preview5").onclick = () => {
document.getElementById("mapModal5").style.display = "flex";
};
document.getElementById("closeMapBtn5").onclick = () => {
document.getElementById("mapModal5").style.display = "none";
};
window.onclick = (event) => {
if (event.target === document.getElementById("mapModal5")) {
document.getElementById("mapModal5").style.display = "none";
}
};
// function download(filename) {
// console.log("Downloading:", filename); // should appear in console
// const link = document.createElement('a');
// link.href = filename;
// link.download = filename;
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
// }