Jake Vanderwerf
2025-09-30 2143fc670fa245750ac7f774fcb38ea8cfbf7edb
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
148
149
150
151
152
153
154
155
class LoadingManager {
    constructor() {
        this.quips = {
            logo: [
                "Fetching items...",
            ],
            uploading: [
                "Sending to server..."
            ],
            ... JSON.parse(loadingQuips.quips),
        };
 
        this.isLoading = false;
        this.overlay = document.querySelector('.loading-overlay');
        if (!this.overlay) {
            return;
        }
        this.overlayMessage = this.overlay.querySelector('.message');
        this.overlayTitle = this.overlay.querySelector('h3');
        this.overlayIcon = this.overlay.querySelector('div.icon');
        this.quipInterval = null;
        this.activeLoads = 0;
        this.currentQuips = this.defaultQuips;
    }
 
    showLoading(message = '', title = 'Loading', customQuips = null) {
        this.isLoading = true;
        this.activeLoads++;
        this.overlayTitle.textContent = title;
 
        // Set custom or default quips
        this.currentQuips = customQuips || this.defaultQuips;
 
        if (message) {
            this.overlayMessage.textContent = message;
        }
        this.overlay.classList.add('active');
        document.body.classList.add('loading');
        document.body.style.overflow = 'hidden';
        this.startQuipCycle();
    }
 
    hideLoading() {
        this.activeLoads--;
        if (this.activeLoads <= 0) {
            this.activeLoads = 0;
            this.overlay.classList.remove('active');
            document.body.style.overflow = '';
            document.body.classList.remove('loading');
            this.stopQuipCycle();
        }
        this.isLoading = false;
        // if(window.formManager.pendingChanges){
        //     window.formManager.handleFormChange();
        // }
    }
 
    setContent(content) {
        console.log(content);
        let keys = Object.keys(this.quips);
        content = keys.map((c) => {
            return (keys.includes(content)) ? content : false;
        }).filter(Boolean);
        content = (content.length === 0) ? ['logo'] : content;
        this.currentContent = content;
    }
 
    startQuipCycle() {
        if (this.quipInterval) {
            clearInterval(this.quipInterval);
        }
 
        let quips = {};
        this.currentContent.forEach(content => {
            this.quips[content].forEach((c) => {
                quips[c] = content;
            });
        });
        let keys = this.shuffleArray(Object.keys(quips));
 
        let currentIndex = 0;
        // Set initial message
        this.overlayMessage.textContent = keys[0];
        this.overlayMessage.classList.remove('changing');
        let content = '';
        let lastContent = '';
        this.quipInterval = setInterval(() => {
            this.overlayMessage.classList.add('changing');
 
            setTimeout(() => {
                currentIndex = (currentIndex + 1) % keys.length;
 
                content = quips[keys[currentIndex]];
                if (content !== lastContent) {
                    window.removeChildren(this.overlayIcon);
                    this.overlayIcon.append(window.getIcon(content));
                }
                window.typeText(this.overlayMessage, keys[currentIndex]);
                this.overlayMessage.classList.remove('changing');
                lastContent = content;
            }, 300);
        }, 2000);
    }
 
    stopQuipCycle() {
        if (this.quipInterval) {
            clearInterval(this.quipInterval);
            this.quipInterval = null;
        }
    }
 
    shuffleArray(array) {
        for (let i = array.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [array[i], array[j]] = [array[j], array[i]];
        }
        return array;
    }
 
    startAutosaving() {
        document.body.classList.add('autosaving');
    }
 
    stopAutosaving(message = 'Saved!') {
        document.body.classList.remove('autosaving');
        // Show the save popup
        const popup = document.querySelector('.save-popup');
        popup.classList.add('show');
        if(message !== 'Saved!'){
            popup.innerText = message;
        }
 
        setTimeout(() => {
            popup.classList.remove('show');
        }, 1500);
    }
    showError(message) {
        // Update overlay to show error state
        this.overlayTitle.textContent = 'Error';
        this.overlayMessage.textContent = message;
        this.overlay.classList.add('active', 'error');
        document.body.style.overflow = 'hidden';
 
        // Auto-hide after delay
        setTimeout(() => {
            this.overlay.classList.remove('active', 'error');
            document.body.style.overflow = '';
        }, 3000);
    }
}
 
 
document.addEventListener('DOMContentLoaded', () => {
    window.jvbLoading = new LoadingManager();
});