-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfooter.php
147 lines (135 loc) · 5.46 KB
/
footer.php
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
</div>
</div>
<script src="assets/js/highlight.min.js"></script>
<script src="assets/js/alpine-collaspe.min.js"></script>
<script src="assets/js/alpine-persist.min.js"></script>
<script src="assets/js/flatpickr.js"></script>
<script defer src="assets/js/alpine-ui.min.js"></script>
<script defer src="assets/js/alpine-focus.min.js"></script>
<script defer src="assets/js/alpine.min.js"></script>
<script src="assets/js/custom.js"></script>
<script defer src="assets/js/apexcharts.js"></script>
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('scrollToTop', () => ({
showTopButton: false,
init() {
window.onscroll = () => {
this.scrollFunction();
};
},
scrollFunction() {
if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
this.showTopButton = true;
} else {
this.showTopButton = false;
}
},
goToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
},
}));
// sidebar section
Alpine.data('sidebar', () => ({
init() {
const selector = document.querySelector('.sidebar ul a[href="' + window.location.pathname + '"]');
if (selector) {
selector.classList.add('active');
const ul = selector.closest('ul.sub-menu');
if (ul) {
let ele = ul.closest('li.menu').querySelectorAll('.nav-link');
if (ele) {
ele = ele[0];
setTimeout(() => {
ele.click();
});
}
}
}
},
}));
// header section
Alpine.data('header', () => ({
notifications: [],
init() {
const selector = document.querySelector('ul.horizontal-menu a[href="' + window.location
.pathname + '"]');
if (selector) {
selector.classList.add('active');
const ul = selector.closest('ul.sub-menu');
if (ul) {
let ele = ul.closest('li.menu').querySelectorAll('.nav-link');
if (ele) {
ele = ele[0];
setTimeout(() => {
ele.classList.add('active');
});
}
}
}
this.getNotifications();
setInterval(() => {
this.getNotifications();
}, 6000);
},
getNotifications() {
fetch('./ajax/notifications.php?action=get_notification')
.then(response => response.json())
.then(data => {
if (data.length > 0) {
this.notifications = data;
this.playNotificationSound();
}
})
.catch(error => {
console.error('Error fetching notifications:', error);
});
},
readAllNotification(){
const http = new XMLHttpRequest();
http.onload = () => {
this.getNotifications();
}
http.open("GET", "./ajax/notifications.php?action=read_all_notification");
http.send();
},
playNotificationSound() {
fetch('./ajax/notifications.php?action=play_noti_sound')
.then(res => res.text())
.then(data => {
const [numNotifications, notificationIds] = data.split('@@@');
if (numNotifications > 0) {
let audioSource = '<source src="./assets/sound.mp3" type="audio/mpeg">';
document.getElementById("sound").innerHTML = `<audio autoplay>${audioSource}</audio>`;
this.removeNotificationSound(notificationIds);
}
})
.catch(error => {
console.error('Error Playing sound:', error);
})
},
removeNotificationSound(id) {
const http = new XMLHttpRequest();
http.onload = () => {
console.log(http.responseText);
document.getElementById("sound").innerHTML = "";
}
http.open("GET", "./ajax/notifications.php?action=remove_noti_sound&ids=" + id);
http.send();
},
removeNotification(id) {
console.log(id);
const http = new XMLHttpRequest();
http.onload = () => {
console.log(http.responseText)
}
http.open("GET", "./ajax/notifications.php?action=remove_notification&id=" + id);
http.send();
this.notifications = this.notifications.filter(notification => notification.id !== id);
},
}));
});
</script>
</body>
</html>