Jake Vanderwerf
2025-12-21 3aada9949d51024a92a8b5c6cb70d12f9c3cac16
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
class FrontendVotes {
    constructor() {
        // Initialize DataStore for queue persistence
        this.store = window.jvbStore.register('votes',
            {
                endpoint: 'votes',
                useIndexedDB: true,
                TTL: 6 * 60 * 1000,
                showLoading: false
            });
    }
 
    handleVote(button) {
        if (!window.auth.getUser()) {
            window.location.href = jvbSettings.redirect + '&action=register&type=vote';
            return;
        }
        window.jvbQueue.handleVote(button);
 
        const parent = button.closest('.vote');
        const alreadyVoted = parent.querySelector('.voted');
 
        // Handle previous vote if exists
        if (alreadyVoted) {
            const count = alreadyVoted.querySelector('.count');
            if (alreadyVoted.classList.contains('up')) {
                count.textContent = parseInt(count.textContent) - 1;
            } else {
                count.textContent = parseInt(count.textContent) + 1;
            }
            alreadyVoted.classList.remove('voted');
        }
 
        // Update current vote
        button.classList.add('voted');
        const count = button.querySelector('.count');
        if (button.classList.contains('up')) {
            count.textContent = parseInt(count.textContent) + 1;
        } else {
            count.textContent = parseInt(count.textContent) - 1;
        }
    }
 
    isFavourited(content, id){
        if(!window.auth.getUser()){
            return false;
        }
        let item = this.store.getItem(id);
        return (item) ? item.action === 'add' : false;
    }
}
window.jvbVotes = false;
if (window.auth.getUser() !== '') {
    window.jvbVotes = new FrontendFavourites();
}
 
window.toggleFavourite = function(button) {
    window.jvbVotes.toggleVote(button);
}
 
 
window.handleVote = function(button) {
    window.jvbVotes.handleVote(button);
};