-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.js
33 lines (30 loc) · 1.08 KB
/
post.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
// post.js
document.addEventListener('DOMContentLoaded', () => {
// Add back-to-top button
const backToTopButton = document.createElement('button');
backToTopButton.id = 'back-to-top';
backToTopButton.innerHTML = '↑';
backToTopButton.title = 'Về đầu trang';
document.body.appendChild(backToTopButton);
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopButton.style.display = 'block';
} else {
backToTopButton.style.display = 'none';
}
});
backToTopButton.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// Get post tags from data attribute
const postId = document.getElementById('post-content').dataset.postId;
const post = posts.find(p => p.id.toString() === postId);
if (post) {
const tagList = document.getElementById('post-tags');
if (tagList) {
tagList.innerHTML = post.tags.map(tag =>
`<span class="tag">${tag}</span>`
).join('');
}
}
});