-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (67 loc) · 2.33 KB
/
Copy pathscript.js
File metadata and controls
79 lines (67 loc) · 2.33 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
document.addEventListener('DOMContentLoaded', function () {
//-----------------------------------
//----------- MAP SCRIPTS -----------
//-----------------------------------
if (document.body.classList.contains('map-page')) {
const fab = document.getElementById('fab');
const menu = document.getElementById('fabMenu');
if (fab && menu) {
fab.onclick = () => {
menu.classList.toggle('show');
};
}
}
//-----------------------------------
//---------- TABLE SCRIPTS ----------
//-----------------------------------
if (document.body.classList.contains('table-page')) {
if ($('#birresTable').length) {
Papa.parse("../data/dades_birres.csv", {
download: true,
header: true,
complete: function(results) {
let data = results.data;
const seen = new Map();
data.forEach(row => {
if (row.Local) {
seen.set(row.Local, row);
}
});
data = Array.from(seen.values());
const tableBody = $('#birresTable tbody');
data.forEach(row => {
if (!row.Local) return;
const link = `<a href="${row.Link}" target="_blank">Maps</a>`;
const cleanedPrice = row.Preu.replace(',', '.').replace(/[^\d.]/g, '');
const price = parseFloat(cleanedPrice).toFixed(2);
const tr = `
<tr>
<td>${row.Local}</td>
<td>${price}</td>
<td>${row.Districte || "—"}</td>
<td>${link}</td>
</tr>`;
tableBody.append(tr);
});
$('#birresTable').DataTable({
paging: false,
lengthChange: false,
info: false,
language: {
search: '<i class="fas fa-search"></i> ',
zeroRecords: "No s'han trobat resultats"
}
});
}
});
}
const backButton = document.querySelector('.back-button');
window.addEventListener('scroll', () => {
if (window.scrollY > 80) {
backButton.classList.add('visible');
} else {
backButton.classList.remove('visible');
}
});
}
});