-
Notifications
You must be signed in to change notification settings - Fork 0
/
_index.html
1106 lines (963 loc) · 34.6 KB
/
_index.html
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Foradex</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://andrewcopeland.github.io/foradex" />
{{ if eq .Mode "dev" }}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
{{ else if eq .Mode "prod" }}
<link rel="stylesheet" href="/foradex/css/water.css">
{{ else }}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
{{ end }}
<script type="text/javascript">
try {
if (navigator.serviceWorker) {
navigator.serviceWorker.register('/foradex/sw.js', {scope: '/foradex/'})
}
} catch (e) {
console.error(e)
}
const dbVersion = 3;
const defaultResourceTypes = [
"Mushroom",
"Berry",
"Tree",
"Herb",
"Flower",
"Other"
]
const defaultResources = [
// mushrooms
{
"type": "Mushroom",
"name": "Chicken of the Woods"
},
{
"type": "Mushroom",
"name": "Black Trumpet"
},
{
"type": "Mushroom",
"name": "Hen of the Woods"
},
{
"type": "Mushroom",
"name": "Chanterelle"
},
{
"type": "Mushroom",
"name": "Morel"
},
// berries
{
"type": "Berry",
"name": "Blueberry"
},
{
"type": "Berry",
"name": "Rasberry"
},
{
"type": "Berry",
"name": "Blackberry"
},
{
"type": "Berry",
"name": "Serviceberry"
},
// tree
{
"type": "Tree",
"name": "PawPaw"
},
{
"type": "Tree",
"name": "Apple"
},
{
"type": "Tree",
"name": "Chestnut"
},
{
"type": "Tree",
"name": "Black Cherry"
}
]
const defaultForadexConfig = {
"defaultResourceType": "Mushroom",
}
// copied from -> https://www.w3schools.com/howto/howto_js_slideshow.asp
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
console.log("slides: " + slides + " length: " + slides.length)
if (slides.length == 0) {
return
}
slides[slideIndex-1].style.display = "block";
if (dots.length == 0) {
return
}
dots[slideIndex-1].className += " active";
}
//internal functions
function createUUID(){
let dt = new Date().getTime()
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = (dt + Math.random()*16)%16 | 0
dt = Math.floor(dt/16)
return (c=='x' ? r :(r&0x3|0x8)).toString(16)
})
return uuid
}
function userUploadImages(id) {
const input = document.getElementById('imageInput');
if (input.files && input.files.length > 0) {
for (let i = 0; i < input.files.length; i++) {
const reader = new FileReader();
reader.onload = function(e) {
const imageData = e.target.result;
setImage(id, imageData);
};
reader.readAsDataURL(input.files[i]);
}
}
}
function findUpdateUploadImages(id) {
const input = document.getElementById('find-update-image-input');
if (input.files && input.files.length > 0) {
for (let i = 0; i < input.files.length; i++) {
const reader = new FileReader();
reader.onload = function(e) {
const imageData = e.target.result;
setImage(id, imageData);
};
reader.readAsDataURL(input.files[i]);
}
}
}
const copyToClipboard = (textToCopy) => {
const textArea = document.createElement('textarea');
textArea.value = textToCopy;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}
const createOption = (value) => {
let opt = document.createElement("option")
opt.value = value
opt.innerHTML = value
return opt
}
const findFind = (body) => {
let foradex = getForadex()
for(const find of foradex.find) {
console.log("FIND: " + find)
console.log("BODY: " + body)
if (find.date === body.date && find.name === body.name && find.type === body.type && find.locationName === body.locationName && find.locationLong === body.locationLong && find.locationLat === body.locationLat) {
return find
}
}
return null
}
const deleteFind = (deleteFind) => {
let foradex = getForadex()
foradex.find.map((find, i) => {
// I wish javascript had a built in ability to compare objects here
// this implementation is also a little silly but will due for now.
// I think we might run out of localStorage place before this
// starts to become noticably ineffecient.
console.log("attempting to delete")
if (find.date === deleteFind.date && find.name === deleteFind.name && find.type === deleteFind.type && find.locationName === deleteFind.locationName && find.locationLong === deleteFind.locationLong && find.locationLat === deleteFind.locationLat) {
foradex.find.splice(i, 1)
setForadex(foradex)
}
})
}
const convertNewlinesToBr = (inputString) => {
return inputString.replace(/\n/g, '<br>');
}
const setFindInfo = (find) => {
setSelectedFind(find)
const googleMapsUrl = `https://www.google.com/maps/search/?api=1&query=${find.locationLat},${find.locationLong}`
const findBlob = btoa(JSON.stringify(find))
const shareUrl = `https://andrewcopeland.github.io/foradex?share=${findBlob}`
console.log("THIS IS TYHE FIND", find)
const findInfoMapping = {
"find-info-title": { innerHtml: `<p><b>${find.date} | ${find.locationName} - ${find.name} (${find.type})</b></p>`},
"find-info-location": { innerHtml: `<p>${find.locationLat}, ${find.locationLong}</p>`},
"find-info-note": {innerHtml: `<p>${convertNewlinesToBr(find.note)}</p>`}
}
console.log("select find info 2222")
for (const [elementId, config] of Object.entries(findInfoMapping)) {
console.log(`setting element with id ${elementId}`)
let e = document.getElementById(elementId)
e.innerHTML = config.innerHtml
if ("listener" in config) {
config.listener(e)
}
}
getImages(displayImages)
findInfoOn()
}
const refreshForadexTable = () => {
console.log("Refreshing foradex table")
const actualForadex = getForadex()
const createForadexCell = (value) => {
let cell = document.createElement("th")
cell.innerText = value
return cell
}
const createActionCell = (find) => {
let cell = document.createElement("th")
let share = document.createElement("a")
share.innerText = "Info"
share.href = "#find-info-header"
share.addEventListener("click", () => {
setFindInfo(find)
})
cell.appendChild(share)
return cell
}
const createForadexRow = (find) => {
let row = document.createElement("tr")
row.appendChild(createForadexCell(find.date))
row.appendChild(createForadexCell(find.locationName))
row.appendChild(createForadexCell(find.name))
// row.appendChild(createForadexCell(find.type))
// row.appendChild(createForadexCell(find.locationLat))
// row.appendChild(createForadexCell(find.locationLong))
row.appendChild(createActionCell(find))
return row
}
let tableForadex = document.getElementById("foradex-table-body")
tableForadex.innerHTML = ""
actualForadex.find.reverse().map((find, i ) => {
tableForadex.appendChild(createForadexRow(find))
})
}
const mergeSharedFind = () => {
const urlParams = new URL(window.location.href)
const shareParam = urlParams.searchParams.get("share")
if (shareParam !== null) {
const find = JSON.parse(atob(shareParam))
console.log("a share param was provided")
appendResource("find", find)
} else {
console.log("a share param was not provided")
}
}
const findInfoOn = () => {
let findInfo = document.getElementById("find-info")
findInfo.style = ""
setTimeout(() => {
window.location.hash = "find-info-header"
}, 200)
}
const findInfoOff = () => {
setTimeout(() => {
let findInfo = document.getElementById("find-info")
findInfo.style = "display: none;"
}, 200)
}
const findUpdateOn = () => {
let findInfo = document.getElementById("find-update")
findInfo.style = ""
setTimeout(() => {
window.location.hash = "find-update-header"
}, 200)
}
const findUpdateOff = () => {
setTimeout(() => {
let findInfo = document.getElementById("find-update")
findInfo.style = "display: none;"
}, 200)
}
const setSelectedFind = (find) => {
localStorage.setItem("selectedFind", JSON.stringify(find))
setUpdateFind()
}
const getSelectedFind = () => {
return JSON.parse(localStorage.getItem("selectedFind"))
}
const initForadex = () => {
const foradex = localStorage.getItem("foradex")
if (foradex === null) {
setForadex({
"resource": defaultResources,
"find": [],
"resourceType": defaultResourceTypes,
"config": defaultForadexConfig
})
} else {
// perform certain types of foradex migrations here
let foradex = getForadex()
for (const [i, find] of foradex.find.entries()) {
let newFind = find
// add uuid in the id field for all finds that do not have them
if (!('id' in find)) {
newFind['id']= createUUID()
}
// add note field as empty string
if (!('note' in find)) {
newFind['note'] = ""
}
foradex.find[i] = newFind
}
setForadex(foradex)
}
const actualForadex = getForadex()
// populate the selects for resource and find type
let selectResourceType = document.getElementById("resource-type")
let selectFindType = document.getElementById("find-type")
let selectFindUpdateType = document.getElementById("find-update-type")
actualForadex.resourceType.map((resourceType, i) => {
selectResourceType.appendChild(createOption(resourceType))
selectFindType.appendChild(createOption(resourceType))
selectFindUpdateType.appendChild(createOption(resourceType))
})
// refresh table
refreshForadexTable()
// refresh name select
refreshFindNameSelect()
// populate the find date
let dateFindDate = document.getElementById("find-date")
const currentDate = getCurrentDate()
console.log("current date: " + currentDate)
dateFindDate.value = currentDate
// at this point on initializing the foradex
// check if the `share` query parameter exists so we can
// merge this shared find
mergeSharedFind()
}
const getCurrentDate = () => {
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
const formattedDate = `${year}-${month}-${day}`;
return formattedDate;
}
const getForadex = () => {
return JSON.parse(localStorage.getItem("foradex"))
}
const setForadex = (foradex) => {
localStorage.setItem("foradex", JSON.stringify(foradex))
refreshFindNameSelect()
refreshForadexTable()
}
const updateForadexFind = (updatedFind) => {
let foradex = getForadex()
for (const [i, find] of foradex.find.entries()) {
if (find.id === updatedFind.id) {
foradex.find[i] = updatedFind
}
}
setForadex(foradex)
}
const appendResource = (type, body) => {
if (type === "find") {
const find = findFind(body)
console.log("Found this find: " + find)
if (find !== null) {
alert("Failed to add find - Already exists")
throw new Error("Failed to add find - Already exists")
}
}
let foradex = getForadex()
const currentItems = foradex[type]
for(const item of currentItems) {
let duplicateItem = true
for (const [field, value] of Object.entries(item)) {
// iterate over all the fields and if any of the currentValues are not
if (body[field] !== value) {
duplicateItem = false
}
}
}
foradex[type].push(body)
setForadex(foradex)
}
const saveFormData = () => {
const name = document.getElementById("find-name").value;
const type = document.getElementById("find-type").value;
const date= document.getElementById("find-date").value;
const locationName = document.getElementById("find-locationName").value;
const note = document.getElementById("find-note").value;
const locationLong = document.getElementById("find-locationLong").value;
const locationLat = document.getElementById("find-locationLat").value;
const formData = {
id: createUUID(),
name: name,
type: type,
date: date,
locationName: locationName,
note: note,
locationLong: locationLong,
locationLat: locationLat
};
appendResource("find", formData)
userUploadImages(formData.id)
alert("Find saved!");
}
const saveUpdatedFind = () => {
const name = document.getElementById("find-update-name").value;
const type = document.getElementById("find-update-type").value;
const date= document.getElementById("find-update-date").value;
const locationName = document.getElementById("find-update-locationName").value;
const note = document.getElementById("find-update-note").value;
const locationLong = document.getElementById("find-update-locationLong").value;
const locationLat = document.getElementById("find-update-locationLat").value;
const updatedFind = {
id: getSelectedFind().id,
name: name,
type: type,
date: date,
locationName: locationName,
note: note,
locationLong: locationLong,
locationLat: locationLat
};
updateForadexFind(updatedFind)
// TODO - give ability to upload more images
findUpdateUploadImages(updatedFind.id)
alert("Find updated!");
findUpdateOff()
findInfoOn()
}
const saveResourceForm = () => {
const type = document.getElementById("resource-type").value
const name = document.getElementById("resource-name").value
const data = {
type: type,
name: name
}
appendResource("resource", data)
alert("Resource saved!");
}
const getCurrentLocation = () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// Do something with the latitude and longitude values
console.log(position.coords)
console.log("Latitude: " + latitude);
console.log("Longitude: " + longitude);
// set the elements
let locationLongElement = document.getElementById("find-locationLong")
let locationLatElement = document.getElementById("find-locationLat")
locationLongElement.value = longitude
locationLatElement.value = latitude
},
function(error) {
console.error("Error getting location:", error);
}
);
} else {
console.error("Geolocation is not supported by this browser.");
}
}
const initWebsite = () => {
initForadex()
getCurrentLocation()
// add UUIDs to objects in foradex that might be from an older version
getForadex()
}
const refreshFindNameSelect = () => {
console.log("refreshing find-name select")
let findTypeSelect = document.getElementById("find-type")
const resourceType = findTypeSelect.value
let findNameSelect = document.getElementById("find-name")
let findUpdateNameSelect = document.getElementById("find-update-name")
findNameSelect.innerHTML = ""
findUpdateNameSelect.innerHTML = ""
const foradex = getForadex()
foradex.resource.map((resource, i) => {
if (resource.type === resourceType) {
findNameSelect.appendChild(createOption(resource.name))
findUpdateNameSelect.append(createOption(resource.name))
}
})
}
const downloadFile = (content, fileName, contentType) => {
const a = document.createElement('a');
const blob = new Blob([content], { type: contentType });
a.href = window.URL.createObjectURL(blob);
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(a.href);
}
const restoreForadexFromFile = () => {
const fileInput = document.getElementById('restore-foradex-input');
fileInput.click();
fileInput.addEventListener('change', function() {
const selectedFile = fileInput.files[0];
if (selectedFile) {
const reader = new FileReader();
reader.onload = function(event) {
const fileContent = event.target.result;
console.log('File content as string:', fileContent);
setForadex(JSON.parse(fileContent))
location.reload()
};
reader.readAsText(selectedFile);
}
});
}
const setUpdateFind = () => {
const find = getSelectedFind()
const idToValue = {
"find-update-type": find.type,
"find-update-name": find.name,
"find-update-locationName": find.locationName,
"find-update-note": find.note,
"find-update-locationLat": find.locationLat,
"find-update-locationLong": find.locationLong,
"find-update-date": find.date,
}
for (const [elementId, value] of Object.entries(idToValue)) {
let element = document.getElementById(elementId)
element.value = value
}
}
const setImage = (id, imageData) => {
const dbName = 'foradex-images';
const objectStoreName = 'images';
const request = indexedDB.open(dbName, dbVersion);
request.onerror = function(event) {
console.error('Error opening IndexedDB:', event.target.error);
};
request.onupgradeneeded = function(event) {
const db = event.target.result;
console.log("on upgraded needed")
if (!db.objectStoreNames.contains(objectStoreName)) {
const objectStore = db.createObjectStore(objectStoreName, { keyPath: 'id', autoIncrement: true });
console.log("creating object store")
objectStore.createIndex('findId', 'findId', { unique: false });
objectStore.createIndex('data', 'data', { unique: false });
}
};
request.onsuccess = function(event) {
console.log("setImage on success triggered")
const db = event.target.result;
const transaction = db.transaction([objectStoreName], 'readwrite');
const objectStore = transaction.objectStore(objectStoreName);
const imageDataObj = {
findId: id,
data: imageData
};
const addRequest = objectStore.add(imageDataObj);
addRequest.onsuccess = function() {
console.log('Image added to IndexedDB');
};
addRequest.onerror = function() {
console.error('Error adding image to IndexedDB:', addRequest.error);
};
transaction.oncomplete = function() {
db.close();
};
};
}
const displayImages = (images) => {
const imageList = document.getElementById("find-info-image-container")
imageList.innerHTML = ''
const findInfoDots = document.getElementById("find-info-dots")
findInfoDots.innerHTML = ''
images.forEach(function(imageData, index) {
console.log("displaying find-info image")
// container div
let div = document.createElement("div")
div.className = "mySlides fade"
// we should also add our dot
const dot = document.createElement("span")
dot.className = "dot"
dot.onclick = currentSlide(index + 1)
findInfoDots.appendChild(dot)
// image element
const image = new Image()
image.src = imageData
// height=300px should help with mobile viewing but if image is wide could still run into issues.
image.style = "height:300px;display:block;margin-left:auto;margin-right:auto;"
image.alt = 'Image ' + (index + 1)
div.appendChild(image)
console.log("appending div as child to imageList. " + div)
imageList.appendChild(div);
});
showSlides(1)
}
const getImages = (callback) => {
const dbName = 'foradex-images';
const objectStoreName = 'images';
const request = indexedDB.open(dbName, dbVersion);
const selectedFind = getSelectedFind()
request.onerror = function(event) {
console.error('Error opening IndexedDB:', event.target.error);
};
request.onsuccess = function(event) {
const db = event.target.result;
const transaction = db.transaction([objectStoreName], 'readonly');
const objectStore = transaction.objectStore(objectStoreName);
const images = [];
// TODO - it would be better to scope down the query to the exact findId
// look into querying for a specific key
objectStore.openCursor().onsuccess = function(event) {
const cursor = event.target.result;
if (cursor) {
// console.log("cursor.value: " + JSON.stringify(cursor.value))
if (cursor.value.findId == selectedFind.id) {
images.push(cursor.value.data)
cursor.continue()
} else {
cursor.continue()
}
} else {
callback(images);
db.close();
}
};
};
}
window.addEventListener("DOMContentLoaded", () => {
// listener config gets the element by the id provided as the key and sets
// an event listener
const listenerConfig = {
"find-type": {
type: "change",
listener: (e) => {
refreshFindNameSelect()
}
},
"reset-foradex": {
type: "click",
listener: (e) => {
if (confirm("Are you sure you want to delete your entire Foradex?")) {
localStorage.clear()
location.reload()
}
}
},
"backup-foradex": {
type: "click",
listener: (e) => {
downloadFile(JSON.stringify(getForadex()), `foradex-${getCurrentDate()}.json`, "application/json")
}
},
"restore-foradex": {
type: "click",
listener: (e) => {
if (confirm("Are you sure you want to restore Foradex (this will override your current foradex)?")) {
restoreForadexFromFile()
}
}
},
"find-info-hide": {
type: "click",
listener: (e) => {
findInfoOff()
}
},
"find-info-map": {
type: "click",
listener: (e) => {
const find = getSelectedFind()
const googleMapsUrl = `https://www.google.com/maps/search/?api=1&query=${find.locationLat},${find.locationLong}`
window.location.href = googleMapsUrl
}
},
"find-info-share": {
type: "click",
listener: (e) => {
const find = getSelectedFind()
const findBlob = btoa(JSON.stringify(find))
const shareUrl = `https://andrewcopeland.github.io/foradex?share=${findBlob}`
copyToClipboard(shareUrl)
alert("Copied foradex share link to clipboard.")
}
},
"find-info-update": {
type: "click",
listener: (e) => {
findInfoOff()
findUpdateOn()
}
},
"find-info-delete": {
type: "click",
listener: (e) => {
const find = getSelectedFind()
if(confirm("Are you sure you want to Delete this find?")) {
deleteFind(find)
findInfoOff()
}
}
}
}
for (const [elementId, config] of Object.entries(listenerConfig)) {
let element = document.getElementById(elementId)
element.addEventListener(config.type, config.listener)
}
})
window.onload = initWebsite
</script>
<style>
* {box-sizing:border-box}
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: grey;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
</style>
</head>
<body>
<h1>Foradex</h1>
<h4>a tool that logs a forager's findings and location</h4>
<hr/>
<h2 id="new-resource">New Resource</h2>
<form>
<div style="display: flex;column-gap: 10px;">
<div>
<label for="type">Type:</label>
<select id="resource-type" name="type" required>
</select>
</div>
<div>
<label for="name">Name:</label>
<input type="text" id="resource-name" name="name" required>
</div>
</div>
<button type="button" onclick="saveResourceForm()">Submit</button>
</form>
<hr/>
<h2>New Find</h2>
<form>
<div style="display: flex;column-gap: 10px;">
<div>
<label for="type">Type:</label>
<select id="find-type" name="type" required>
</select>
</div>
<div>
<label for="name">Name:</label>
<select id="find-name" name="name" style="max-width: 220px;"required>
<option value="" selected disabled>Select an option</option>
</select>
</div>
</div>
<label for="locationName">Location Name:</label>
<input type="text" id="find-locationName" name="locationName" required>
<label for="find-note">Notes:</label>
<textarea id="find-note" style="height: 100px; resize: none;"></textarea>
<div style="display: flex;column-gap: 10px;">
<div>
<label for="locationLat">Latitude:</label>
<input type="text" id="find-locationLat" name="locationLat" style="width: 100px;" required>
</div>
<div>
<label for="locationLong">Longitude:</label>
<input type="text" id="find-locationLong" name="locationLong" style="width: 100px;" required>
</div>
</div>
<label for="date">Date:</label>
<input type="date" id="find-date" name="date" required>
<label for="imageInput">Upload Images:</label>
<input type="file" id="imageInput" accept="image/*" multiple>
<button type="button" onclick="saveFormData()">Submit</button>
</form>
<hr/>
<div id="find-update" style="display: none;">
<h3 id="find-update-header">Update Find</h3>
<form>
<div style="display: flex;column-gap: 10px;">
<div>
<label for="type">Type:</label>
<select id="find-update-type" name="type" required>
</select>