style: Reformat and comment

This commit is contained in:
sthag 2025-11-02 09:18:12 +01:00
parent 9d15f22f5d
commit abf393191c
3 changed files with 8 additions and 9 deletions

View file

@ -239,6 +239,7 @@ class TimeDisplay {
this.interval = interval || 1000; this.interval = interval || 1000;
this.isPaused = false; this.isPaused = false;
this.locale = navigator.language || 'en-US'; this.locale = navigator.language || 'en-US';
this.updateTime(); this.updateTime();
console.group('Time information'); console.group('Time information');
@ -251,6 +252,7 @@ class TimeDisplay {
return time.toLocaleTimeString(this.locale, this.options); return time.toLocaleTimeString(this.locale, this.options);
} }
// TODO: Zeit nur im Sekundentakt aktualisieren wenn Sekunden angezeigt werden
async updateTime() { async updateTime() {
while (true) { while (true) {
if (!this.isPaused) { if (!this.isPaused) {
@ -261,12 +263,10 @@ class TimeDisplay {
} }
} }
// Method to pause updates
pause() { pause() {
this.isPaused = true; this.isPaused = true;
} }
// Method to resume updates
resume() { resume() {
this.isPaused = false; this.isPaused = false;
} }
@ -276,6 +276,7 @@ class DateDisplay {
constructor(element, options) { constructor(element, options) {
this.element = element; this.element = element;
this.options = options || {year: 'numeric', month: 'long', day: 'numeric'}; this.options = options || {year: 'numeric', month: 'long', day: 'numeric'};
this.updateDate(); this.updateDate();
this.checkForDateChange(); this.checkForDateChange();
@ -291,12 +292,14 @@ class DateDisplay {
updateDate() { updateDate() {
const now = new Date(); const now = new Date();
this.element.textContent = this.formatDate(now); this.element.textContent = this.formatDate(now);
} }
getTimeUntilNextMidnight() { getTimeUntilNextMidnight() {
const now = new Date(); const now = new Date();
const nextMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1); const nextMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
return nextMidnight - now; return nextMidnight - now;
} }

View file

@ -210,14 +210,12 @@ class DragAdv {
const rect = this.placeholder.getBoundingClientRect(); const rect = this.placeholder.getBoundingClientRect();
const windowWidth = window.innerWidth; const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight; const windowHeight = window.innerHeight;
const distances = { const distances = {
left: rect.left,
right: windowWidth - rect.right,
top: rect.top, top: rect.top,
bottom: windowHeight - rect.bottom right: windowWidth - rect.right,
bottom: windowHeight - rect.bottom,
left: rect.left
}; };
const closestEdge = Object.keys(distances).reduce((a, b) => distances[a] < distances[b] ? a : b); const closestEdge = Object.keys(distances).reduce((a, b) => distances[a] < distances[b] ? a : b);
this.setPosition(closestEdge, this.barSize); this.setPosition(closestEdge, this.barSize);

View file

@ -68,11 +68,9 @@ tags:
timeDisplay.pause(); timeDisplay.pause();
console.info('Pause time'); console.info('Pause time');
}); });
document.getElementById('resumeButton').addEventListener('click', () => { document.getElementById('resumeButton').addEventListener('click', () => {
timeDisplay.resume(); timeDisplay.resume();
console.info('Resume time'); console.info('Resume time');
}); });
</script> </script>
{% endblock %} {% endblock %}