-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
392 lines (338 loc) · 12.4 KB
/
Copy pathscript.js
File metadata and controls
392 lines (338 loc) · 12.4 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
// Konfigurationskonstanten
const LIGHT_MODE_HOUR = 7;
const DARK_MODE_HOUR = 20;
const COLLAPSED_CATEGORIES_COOKIE = 'collapsedCats';
// --- Hilfsfunktionen für Cookies ---
function setCookie(name, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
let nameEQ = name + "=";
let ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
// --- Dark Mode Logik ---
function applyMode(mode) {
let finalMode = mode;
if (mode === 'auto') {
const now = new Date();
const hour = now.getHours();
if (hour >= LIGHT_MODE_HOUR && hour < DARK_MODE_HOUR) {
finalMode = 'light';
} else {
finalMode = 'dark';
}
}
document.body.classList.remove('light-mode', 'dark-mode');
if (finalMode === 'light') {
document.body.classList.add('light-mode');
} else if (finalMode === 'dark') {
document.body.classList.add('dark-mode');
}
const switchEl = document.getElementById('modeSwitch');
if (switchEl) {
switchEl.setAttribute('data-mode', mode);
let icon = '';
if (mode === 'auto') {
icon = `<i class="fa-solid fa-sync-alt"></i> ${finalMode === 'light' ? 'Day' : 'Night'} (Auto)`;
} else if (mode === 'light') {
icon = '<i class="fa-solid fa-sun"></i> Day Mode';
} else {
icon = '<i class="fa-solid fa-moon"></i> Night Mode';
}
switchEl.innerHTML = icon;
}
setCookie('colorMode', mode, 365);
}
function toggleMode() {
const currentMode = getCookie('colorMode') || 'auto';
let newMode = 'auto';
if (currentMode === 'auto') {
newMode = 'light';
} else if (currentMode === 'light') {
newMode = 'dark';
} else {
newMode = 'auto';
}
applyMode(newMode);
}
// --- Größen-Toggle Logik ---
function applySizeMode(mode) {
document.body.classList.remove('compact-mode', 'normal-mode');
if (mode === 'compact') {
document.body.classList.add('compact-mode');
} else {
document.body.classList.add('normal-mode');
}
setCookie('sizeMode', mode, 365);
updateSizeSwitchUI(mode);
}
function toggleSizeMode() {
const currentMode = getCookie('sizeMode') || 'compact';
const newMode = (currentMode === 'compact') ? 'normal' : 'compact';
applySizeMode(newMode);
}
function updateSizeSwitchUI(mode) {
const switchEl = document.getElementById('sizeSwitch');
if (switchEl) {
switchEl.setAttribute('data-mode', mode);
const text = mode === 'compact' ? 'Compact View' : 'Normal View';
const icon = mode === 'compact' ? 'fa-compress-alt' : 'fa-expand-alt';
switchEl.innerHTML = `<i class="fa-solid ${icon}"></i> ${text}`;
}
}
// --- Intelligente Uhrzeit/Datum ---
function updateDateTime() {
const now = new Date();
const dateStr = now.toLocaleDateString('de-DE', {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric'
});
const timeStr = now.toLocaleTimeString('de-DE', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
const dateTimeEl = document.getElementById('currentDateTime');
if (dateTimeEl) {
dateTimeEl.innerHTML = `${dateStr}<br>${timeStr}`;
}
}
// --- Sortierungs-Logik ---
function getCurrentBubbleOrder(container) {
return Array.from(container.children)
.map(el => el.querySelector('.bubble-text').textContent.trim());
}
function getCurrentCategoryOrder() {
const grid = document.querySelector('.categories-grid');
if (!grid) return [];
return Array.from(grid.children)
.filter(el => el.classList.contains('category-group'))
.map(el => el.getAttribute('data-id'));
}
function saveOrder(orderArray, type = 'category_order') {
const dataToSave = {};
if (type === 'category_order') {
dataToSave['category_order'] = orderArray;
const bubbleOrders = {};
document.querySelectorAll('.category-group').forEach(group => {
const categoryId = group.getAttribute('data-id');
const linksContainer = group.querySelector('.links-container');
bubbleOrders[categoryId] = getCurrentBubbleOrder(linksContainer);
});
dataToSave['bubble_orders'] = bubbleOrders;
} else {
dataToSave[type] = orderArray;
}
fetch('save_order.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(dataToSave)
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log(data.message);
} else {
console.error('Save failed:', data.message);
}
})
.catch(error => console.error('Error saving order:', error));
}
function resetOrder() {
if (!confirm('Sind Sie sicher, dass Sie die Reihenfolge auf den Originalzustand zurücksetzen möchten?')) {
return;
}
const defaultOrderElement = document.getElementById('defaultOrder');
if (!defaultOrderElement) {
alert('Fehler: Die Standardreihenfolge konnte nicht gefunden werden.');
return;
}
const defaultOrder = JSON.parse(defaultOrderElement.textContent);
const resetData = {
category_order: defaultOrder,
bubble_orders: {}
};
fetch('save_order.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(resetData)
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.reload();
} else {
alert('Fehler beim Zurücksetzen: ' + data.message);
}
})
.catch(error => console.error('Error saving order:', error));
}
function initSortableGrid() {
const grid = document.querySelector('.categories-grid');
if (!grid || typeof Sortable === 'undefined') return;
// Sortierung für Kategorien
new Sortable(grid, {
animation: 250,
delay: 50,
filter: ".system-panel",
fallbackOnBody: true,
swapThreshold: 0.65,
handle: ".category-title",
onEnd: function (evt) {
const newOrder = getCurrentCategoryOrder();
saveOrder(newOrder, 'category_order');
},
});
// Sortierung für Bubbles innerhalb jeder Kategorie
document.querySelectorAll('.links-container').forEach(container => {
new Sortable(container, {
animation: 150,
group: 'bubbles',
handle: '.bubble-icon',
delay: 100,
onEnd: function (evt) {
const currentCategoryOrder = getCurrentCategoryOrder();
saveOrder(currentCategoryOrder, 'category_order');
}
});
});
}
// --- Quick Link Form Logik ---
function initAddLink() {
const form = document.getElementById('addLinkForm');
if (!form) return;
const messageEl = document.getElementById('formMessage');
const submitButton = document.getElementById('submitLinkButton');
form.addEventListener('submit', function (e) {
e.preventDefault();
messageEl.textContent = 'Saving...';
messageEl.classList.remove('success', 'error');
submitButton.disabled = true;
const linkData = {
text: document.getElementById('linkText').value,
url: document.getElementById('linkUrl').value,
icon: document.getElementById('linkIcon').value || 'link',
category: document.getElementById('linkCategory').value
};
fetch('add_link.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(linkData)
})
.then(response => response.json())
.then(data => {
if (data.success) {
messageEl.textContent = 'Link erfolgreich hinzugefügt! Seite wird neu geladen...';
messageEl.classList.add('success');
setTimeout(() => {
window.location.reload();
}, 1500);
} else {
messageEl.textContent = 'FEHLER: ' + (data.message || 'Unbekannter Fehler.');
messageEl.classList.add('error');
submitButton.disabled = false;
}
})
.catch(error => {
console.error('Network Error:', error);
messageEl.textContent = 'FEHLER: Netzwerkproblem beim Speichern.';
messageEl.classList.add('error');
submitButton.disabled = false;
});
});
}
// --- Collapsible-Logik ---
function saveCollapsedState(collapsedCategories) {
setCookie(COLLAPSED_CATEGORIES_COOKIE, collapsedCategories.join(','), 365);
}
function getCollapsedState() {
const cookie = getCookie(COLLAPSED_CATEGORIES_COOKIE);
return cookie ? cookie.split(',') : [];
}
function toggleCategoryCollapse(categoryGroup) {
const categoryId = categoryGroup.getAttribute('data-category-id');
const isCollapsed = categoryGroup.classList.toggle('collapsed');
categoryGroup.setAttribute('aria-expanded', !isCollapsed);
const collapsedCategories = getCollapsedState().filter(id => id !== categoryId);
if (isCollapsed) {
collapsedCategories.push(categoryId);
}
saveCollapsedState(collapsedCategories);
}
function initCategoryCollapse() {
const collapsedCategories = getCollapsedState();
document.querySelectorAll('.category-group').forEach(group => {
const categoryId = group.getAttribute('data-category-id');
const titleElement = group.querySelector('.category-title');
if (collapsedCategories.includes(categoryId)) {
group.classList.add('collapsed');
group.setAttribute('aria-expanded', 'false');
} else {
group.setAttribute('aria-expanded', 'true');
}
titleElement.addEventListener('click', (e) => {
if (e.target.closest('.drag-handle')) {
return;
}
toggleCategoryCollapse(group);
});
});
}
// Starten der Anwendung beim Laden der Seite
document.addEventListener('DOMContentLoaded', () => {
// Modus-Initialisierung
const initialMode = getCookie('colorMode') || 'auto';
applyMode(initialMode);
// Größen-Modus Initialisierung
const initialSizeMode = getCookie('sizeMode') || 'compact';
applySizeMode(initialSizeMode);
// Initialisierungen
initCategoryCollapse();
initSortableGrid();
initAddLink();
// Zentrale Intervalle (nur Uhrzeit und Auto-Mode-Check)
updateDateTime();
setInterval(updateDateTime, 1000);
// Auto-Mode-Check alle 5 Minuten
setInterval(() => {
const currentMode = getCookie('colorMode');
if (currentMode === 'auto') {
applyMode('auto');
}
}, 5 * 60 * 1000);
// Event-Listener
const resetOrderButton = document.getElementById('resetOrderButton');
if(resetOrderButton) resetOrderButton.addEventListener('click', resetOrder);
const modeSwitch = document.getElementById('modeSwitch');
if(modeSwitch) modeSwitch.addEventListener('click', toggleMode);
const sizeSwitch = document.getElementById('sizeSwitch');
if(sizeSwitch) sizeSwitch.addEventListener('click', toggleSizeMode);
// Matomo Tracking Code
var _paq = window._paq = window._paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.jerabek.fi/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '4']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
});