-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
129 lines (116 loc) · 4.12 KB
/
index.js
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
// index.js
function openModal(element) {
const photosJson = element.getAttribute('data-photos');
const photos = JSON.parse(photosJson);
const carouselIndicators = document.getElementById('carouselIndicators');
const carouselInner = document.getElementById('carouselInner');
// Clear existing carousel items
carouselIndicators.innerHTML = '';
carouselInner.innerHTML = '';
// Populate carousel with images
photos.forEach((photo, index) => {
// Indicators
const indicator = document.createElement('li');
indicator.setAttribute('data-target', '#imageCarousel');
indicator.setAttribute('data-slide-to', index.toString());
if (index === 0) {
indicator.classList.add('active');
}
carouselIndicators.appendChild(indicator);
// Carousel items
const carouselItem = document.createElement('div');
carouselItem.classList.add('carousel-item');
if (index === 0) {
carouselItem.classList.add('active');
}
const img = document.createElement('img');
img.classList.add('d-block', 'w-100');
img.src = photo;
carouselItem.appendChild(img);
carouselInner.appendChild(carouselItem);
});
// Initialize the carousel without animation
$('#imageCarousel').carousel({
interval: false,
ride: false,
keyboard: true,
pause: true,
wrap: true
});
// Show the modal
$('#imageModal').modal('show');
}
function sortTable(n) {
const table = document.getElementById("dolphinTable");
let rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
switching = true;
dir = "asc";
while (switching) {
switching = false;
rows = table.rows;
// Loop through all table rows except the header
for (i = 1; i < (rows.length - 1); i++) {
shouldSwitch = false;
x = rows[i].getElementsByTagName("TD")[n];
y = rows[i + 1].getElementsByTagName("TD")[n];
let cmp = x.innerText.localeCompare(y.innerText, undefined, { numeric: true });
if (dir === "asc") {
if (cmp > 0) {
shouldSwitch = true;
break;
}
} else if (dir === "desc") {
if (cmp < 0) {
shouldSwitch = true;
break;
}
}
}
if (shouldSwitch) {
// Swap rows
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
switchcount++;
} else {
// If no switching has been done AND the direction is "asc",
// set the direction to "desc" and run the loop again.
if (switchcount === 0 && dir === "asc") {
dir = "desc";
switching = true;
}
}
}
}
function search() {
const input = document.getElementById("searchInput");
const filter = input.value.toUpperCase();
const table = document.getElementById("dolphinTable");
const cards = document.getElementById("dolphinCards");
const tr = table.getElementsByTagName("tr");
const cardDivs = cards.getElementsByClassName("card");
// Filter table rows
for (let i = 1; i < tr.length; i++) {
const td = tr[i].getElementsByTagName("td")[0]; // Name column
if (td) {
const txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
// Filter cards
for (let i = 0; i < cardDivs.length; i++) {
const card = cardDivs[i];
const cardTitle = card.getElementsByClassName("card-title")[0];
if (cardTitle) {
const txtValue = cardTitle.textContent || cardTitle.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
card.style.display = "";
} else {
card.style.display = "none";
}
}
}
}