Compare commits
19 commits
2f87621756
...
c3de29d634
| Author | SHA1 | Date | |
|---|---|---|---|
| c3de29d634 | |||
| a1aae6a902 | |||
| 6a574d92c2 | |||
| 91df239a42 | |||
| d0fde7cc6a | |||
| 7f4b4aeaee | |||
| 48b6e1d0ed | |||
| 10c71a3909 | |||
| 8d1d182be4 | |||
| 0aca2bf3ee | |||
| 5261754da5 | |||
| 8ce1e14fad | |||
| ee43638cbc | |||
| 56633b364e | |||
| 05f2ab1c0d | |||
| ad135a58c1 | |||
| 667269e4e7 | |||
| 62b21b5e68 | |||
| 743d9fba9e |
11 changed files with 525 additions and 373 deletions
4
TODO.md
4
TODO.md
|
|
@ -21,6 +21,10 @@
|
|||
- Move other things
|
||||
- Prevent styles to be global
|
||||
|
||||
# JS
|
||||
|
||||
- Use delegation for action attributes like: https://javascript.info/event-delegation#delegation-example-actions-in-markup
|
||||
|
||||
# Content
|
||||
|
||||
- *Intro*
|
||||
|
|
|
|||
|
|
@ -523,6 +523,22 @@ function capitalizeFirstLetter(text) {
|
|||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
|
||||
function mapRange(value, inMin, inMax, outMin, outMax, reverse = false, clamp = false) {
|
||||
let min = outMin;
|
||||
let max = outMax;
|
||||
|
||||
if (reverse) {
|
||||
[min, max] = [max, min];
|
||||
}
|
||||
|
||||
const mapped = (value - inMin) * (max - min) / (inMax - inMin) + min;
|
||||
|
||||
if (clamp) {
|
||||
return Math.max(Math.min(min, max), Math.min(Math.max(min, max), mapped));
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// CONCEPTS
|
||||
|
||||
// NOTE: Benutzt private Zuweisungen
|
||||
|
|
|
|||
|
|
@ -495,7 +495,7 @@ tags:
|
|||
oder das Element H<sub>2</sub>O</p>
|
||||
<p>Die Zeichen in Absätzen bis hin zu ganzen Texten können, mit einem geeigneten Eingabegerät, markiert werden.
|
||||
Dies stellt sich wie folgt dar:</p>
|
||||
<p class="txt_center">Bei <mark class="mark_cursor">spiel zum mark</mark>ieren 😉.</p>
|
||||
<p class="txt_center">Bei<mark class="mark_cursor">spiel zum mark</mark>ieren 😉.</p>
|
||||
<p>Eine Markierung kann, mittels
|
||||
<code><mark></code>, auch durch den Autor geschehen. Diese stellt sich ein wenig anders dar:
|
||||
<mark>Diese Worte sind markiert.</mark>
|
||||
|
|
@ -881,61 +881,63 @@ tags:
|
|||
<p>Innerhalb einer Gruppe können nicht nur Ein- und Ausgabefelder platziert werden. Andere Elemente ergänzen
|
||||
Information oder lockern das Erscheinungsbild auf.</p>
|
||||
<p>Hier nun eine Liste weiterer Arten von Eingabefeldern:</p>
|
||||
<div class="grid grid_column_2">
|
||||
<label class="">Farbauswahl<br>
|
||||
<code><input[type="color"]></code>
|
||||
</label>
|
||||
<div><input class="" type="color"></div>
|
||||
<label class="">Bereichsauswahl<br>
|
||||
<code><input[type="range"]></code>
|
||||
</label>
|
||||
<div><input class="" type="range"></div>
|
||||
<label class="">Datum<br>
|
||||
<code><input[type="date"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="date"></div>
|
||||
<label class="">Uhrzeit<br>
|
||||
<code><input[type="time"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="time"></div>
|
||||
<label class="">Datum und Zeit<br>
|
||||
<code><input[type="datetime-local"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="datetime-local"></div>
|
||||
<label class="">Kalendermonat<br>
|
||||
<code><input[type="month"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="month"></div>
|
||||
<label class="">Kalenderwoche<br>
|
||||
<code><input[type="week"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="week"></div>
|
||||
<label class="">@dresse<br>
|
||||
<code><input[type="email"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="email" placeholder="@"></div>
|
||||
<label class="">Passwort<br>
|
||||
<code><input[type="password"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="password" value="admin"></div>
|
||||
<label class="">Telefonnummer<br>
|
||||
<code><input[type="tel"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="tel" value="0190123456"></div>
|
||||
<label class="">URL<br>
|
||||
<code><input[type="url"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="url" placeholder="url://"></div>
|
||||
<label class="">Suche<br>
|
||||
<code><input[type="search"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="search"></div>
|
||||
<label class="">Datei<br>
|
||||
<code><input[type="file"]></code>
|
||||
</label>
|
||||
<div><input class="" type="file"></div>
|
||||
<label class="">Bild</label><input class="" type="image" alt="Alternativer Text"/>
|
||||
</div>
|
||||
<form action="">
|
||||
<div class="grid grid_column_2">
|
||||
<label class="">Farbauswahl<br>
|
||||
<code><input[type="color"]></code>
|
||||
</label>
|
||||
<div><input class="" type="color"></div>
|
||||
<label class="">Bereichsauswahl<br>
|
||||
<code><input[type="range"]></code>
|
||||
</label>
|
||||
<div><input class="" type="range"></div>
|
||||
<label class="">Datum<br>
|
||||
<code><input[type="date"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="date"></div>
|
||||
<label class="">Uhrzeit<br>
|
||||
<code><input[type="time"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="time"></div>
|
||||
<label class="">Datum und Zeit<br>
|
||||
<code><input[type="datetime-local"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="datetime-local"></div>
|
||||
<label class="">Kalendermonat<br>
|
||||
<code><input[type="month"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="month"></div>
|
||||
<label class="">Kalenderwoche<br>
|
||||
<code><input[type="week"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="week"></div>
|
||||
<label class="">@dresse<br>
|
||||
<code><input[type="email"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" placeholder="@" type="email"></div>
|
||||
<label class="">Passwort<br>
|
||||
<code><input[type="password"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" value="admin" autocomplete="off" type="password"></div>
|
||||
<label class="">Telefonnummer<br>
|
||||
<code><input[type="tel"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" value="0190123456" type="tel"></div>
|
||||
<label class="">URL<br>
|
||||
<code><input[type="url"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" placeholder="url://" type="url"></div>
|
||||
<label class="">Suche<br>
|
||||
<code><input[type="search"]></code>
|
||||
</label>
|
||||
<div><input class="input_io" type="search"></div>
|
||||
<label class="">Datei<br>
|
||||
<code><input[type="file"]></code>
|
||||
</label>
|
||||
<div><input class="" type="file"></div>
|
||||
<label class="">Bild</label><input class="" type="image" alt="Alternativer Text"/>
|
||||
</div>
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
<h2>Interaktive Elemente</h2>
|
||||
|
|
|
|||
|
|
@ -8,290 +8,453 @@ tags:
|
|||
|
||||
{% block body %}
|
||||
<header class="io pos_fix pin_top pin_right pin_left">
|
||||
<button id="tglFormat" title="Toggle hour display">12-Stunden-Format</button>
|
||||
<button id="tglSections" title="Toggle sections">Abschnitte</button>
|
||||
<button id="tglOverlay" title="Toggle overlay">☰</button>
|
||||
<nav>
|
||||
<button id="tglFormat" title="Toggle hour display">12-Stunden</button>
|
||||
<button id="tglSections" title="Toggle sections">Abschnitte</button>
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
<div class="wrap">
|
||||
<canvas id="background" width="768" height="768"></canvas>
|
||||
<canvas id="rings" width="768" height="768"></canvas>
|
||||
</div>
|
||||
</main>
|
||||
<main></main>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script src="/vendor/hippie-script.js"></script>
|
||||
<script src="/js/globals.js"></script>
|
||||
<script src="/js/app.js"></script>
|
||||
|
||||
<script>
|
||||
const canvasBkg = document.getElementById('background');
|
||||
const ctxBkg = canvasBkg.getContext('2d');
|
||||
const canvasRings = document.getElementById('rings');
|
||||
const ctxRings = canvasRings.getContext('2d');
|
||||
const wrap = document.querySelector('.wrap');
|
||||
class HippieClock {
|
||||
constructor(element, date, options) {
|
||||
this.element = element;
|
||||
this.date = this.getTime(date);
|
||||
this.options = options || {
|
||||
size: Math.floor(this.getSize().value * 0.9),
|
||||
h24: true,
|
||||
sections: true,
|
||||
overlay: false
|
||||
};
|
||||
this.parts = [];
|
||||
this.shapes = [];
|
||||
|
||||
let is24HourFormat = true;
|
||||
let drawSections = false;
|
||||
let currentDate = new Date();
|
||||
let currentMonth = currentDate.getMonth() + 1; // Get current month (0-11)
|
||||
let daysInCurrentMonth = daysInMonth(currentMonth, currentDate.getFullYear());
|
||||
|
||||
const outerMargin = 8;
|
||||
const ringWidth = 16;
|
||||
const ringGap = 8;
|
||||
let centerX = canvasRings.width / 2;
|
||||
let centerY = canvasRings.height / 2;
|
||||
let maxSize = (canvasRings.width / 2 - ringWidth / 2) - outerMargin;
|
||||
|
||||
resizeClock();
|
||||
|
||||
const rings = [
|
||||
{
|
||||
radius: maxSize,
|
||||
color: 'black'
|
||||
},
|
||||
{
|
||||
radius: maxSize - (ringWidth + ringGap),
|
||||
color: 'lightgrey'
|
||||
},
|
||||
{
|
||||
radius: maxSize - (ringWidth + ringGap) * 2,
|
||||
color: 'white'
|
||||
},
|
||||
{
|
||||
radius: maxSize - (ringWidth + ringGap) * 3 - ringGap,
|
||||
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-yellow').trim()
|
||||
},
|
||||
{
|
||||
radius: maxSize - (ringWidth + ringGap) * 4 - ringGap * 2,
|
||||
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-orange').trim()
|
||||
},
|
||||
{
|
||||
radius: maxSize - (ringWidth + ringGap) * 5 - ringGap * 3,
|
||||
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-pink').trim()
|
||||
},
|
||||
{
|
||||
radius: maxSize - (ringWidth + ringGap) * 6 - ringGap * 3,
|
||||
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-purple').trim()
|
||||
this.#init();
|
||||
}
|
||||
];
|
||||
const groups = [
|
||||
{
|
||||
radius: rings[1].radius,
|
||||
color: `rgba(0, 0, 0, .1)`,
|
||||
width: 72
|
||||
},
|
||||
{
|
||||
radius: rings[3].radius,
|
||||
color: `rgba(0, 0, 0, .2)`,
|
||||
width: ringWidth + ringGap
|
||||
},
|
||||
{
|
||||
radius: rings[4].radius,
|
||||
color: `rgba(0, 0, 0, .3)`,
|
||||
width: ringWidth + ringGap
|
||||
},
|
||||
{
|
||||
radius: maxSize - (ringWidth + ringGap) * 6 - ringGap - ringGap / 2,
|
||||
color: `rgba(0, 0, 0, .4)`,
|
||||
width: ringWidth * 2 + ringGap * 2
|
||||
}
|
||||
];
|
||||
const sectionMarkerColor = `rgba(0, 0, 0, .2)`;
|
||||
let sections = [
|
||||
{
|
||||
amount: 60,
|
||||
radius: maxSize,
|
||||
width: 1
|
||||
},
|
||||
{
|
||||
amount: 60,
|
||||
radius: rings[1].radius,
|
||||
width: 1
|
||||
},
|
||||
{
|
||||
amount: is24HourFormat ? 24 : 12,
|
||||
radius: rings[2].radius,
|
||||
width: 3
|
||||
},
|
||||
{
|
||||
amount: 7,
|
||||
radius: rings[3].radius,
|
||||
width: 5
|
||||
},
|
||||
{
|
||||
amount: daysInCurrentMonth,
|
||||
radius: rings[4].radius,
|
||||
width: 3
|
||||
},
|
||||
{
|
||||
amount: 365,
|
||||
radius: rings[5].radius,
|
||||
width: 1
|
||||
},
|
||||
{
|
||||
amount: 12,
|
||||
radius: rings[6].radius,
|
||||
width: 3
|
||||
}
|
||||
];
|
||||
|
||||
#init() {
|
||||
this.#createContext(['background', 'hands']);
|
||||
this.createOverlay();
|
||||
|
||||
this.addRing('seconds', 1, 21, 60, `rgb(250, 216, 3)`);
|
||||
this.addRing('minutes', .9, 46, 60, `rgb(242, 175, 19)`);
|
||||
this.addRing('hours', .8, 6, this.options.h24 ? 24 : 12, `rgb(211, 10, 81)`);
|
||||
this.addRing('dotweek', .7, 2, 7, `rgb(142, 31, 104)`);
|
||||
this.addRing('dotmonth', .6, 12, this.getTime().daysMonth, `rgb(39, 63, 139)`);
|
||||
this.addRing('dotyear', .5, 256, this.getTime().daysYear, `rgb(60, 87, 154)`);
|
||||
this.addRing('week', .4, 10, this.getTime().weeksYear, `rgb(183, 224, 240)`);
|
||||
this.addRing('month', .3, 10, 12, `rgb(107, 199, 217)`);
|
||||
this.addRing('moon', .2, 4, 8, `rgb(82, 190, 209)`);
|
||||
|
||||
this.#resize();
|
||||
window.addEventListener('resize', () => this.#resize());
|
||||
|
||||
console.debug(this);
|
||||
console.debug(this.getTime());
|
||||
}
|
||||
|
||||
#resize() {
|
||||
this.updateOptions({size: Math.floor(this.getSize().value * 0.9)});
|
||||
this.parts.forEach(part => {
|
||||
if (part.name === 'wrap') {
|
||||
part.element.style.height = this.options.size + 'px';
|
||||
part.element.style.width = this.options.size + 'px';
|
||||
}
|
||||
|
||||
part.element.width = part.element.offsetWidth;
|
||||
part.element.height = part.element.offsetHeight;
|
||||
|
||||
this.draw();
|
||||
});
|
||||
}
|
||||
|
||||
draw() {
|
||||
// TODO: Nur geänderte Teile löschen
|
||||
this.parts.forEach(part => {
|
||||
part.context?.clearRect(0, 0, part.element.width, part.element.height);
|
||||
});
|
||||
|
||||
let ctx = undefined;
|
||||
|
||||
this.shapes
|
||||
.filter(item => item.type === 'circle')
|
||||
.forEach((shape) => {
|
||||
const radius = this.#toPixelSize(shape.radius) / 2;
|
||||
ctx = this.parts[0].context;
|
||||
|
||||
ctx.fillStyle = shape.color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(
|
||||
this.#toPixelX(shape.center),
|
||||
this.#toPixelY(shape.center),
|
||||
radius,
|
||||
0,
|
||||
Math.PI * 2
|
||||
);
|
||||
ctx.fill();
|
||||
});
|
||||
|
||||
this.shapes
|
||||
.filter(item => item.type === 'ring')
|
||||
.forEach((shape) => {
|
||||
if (this.options.sections) {
|
||||
const outerRadius = this.#toPixelSize(shape.radius) / 2;
|
||||
const innerRadius = this.#toPixelSize(shape.radius) / 2 - shape.stroke;
|
||||
ctx = this.parts[0].context;
|
||||
|
||||
for (let i = 0; i < shape.max; i++) {
|
||||
const angle = (i * (360 / shape.max) - 90) * (Math.PI / 180); // -90 to start at top
|
||||
const outerX = this.#toPixelX(shape.center) + outerRadius * Math.cos(angle);
|
||||
const outerY = this.#toPixelY(shape.center) + outerRadius * Math.sin(angle);
|
||||
const innerX = this.#toPixelX(shape.center) + innerRadius * Math.cos(angle);
|
||||
const innerY = this.#toPixelY(shape.center) + innerRadius * Math.sin(angle);
|
||||
|
||||
ctx.strokeStyle = `rgba(0, 0, 0, .25)`;
|
||||
ctx.lineWidth = mapRange(shape.max, 7, 72, .1, 5, true, true);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(outerX, outerY);
|
||||
ctx.lineTo(innerX, innerY);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
const radius = this.#toPixelSize(shape.radius) / 2 - shape.stroke / 2;
|
||||
const start = -0.5 * Math.PI; // Start at the top
|
||||
const angle = start + (2 * Math.PI * (shape.angle / shape.max));
|
||||
ctx = this.parts[1].context;
|
||||
|
||||
ctx.strokeStyle = shape.color;
|
||||
ctx.lineWidth = shape.stroke;
|
||||
ctx.beginPath();
|
||||
ctx.arc(
|
||||
this.#toPixelX(shape.center),
|
||||
this.#toPixelY(shape.center),
|
||||
radius,
|
||||
start,
|
||||
angle
|
||||
);
|
||||
ctx.stroke();
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Erfassung für geänderte Formen ergänzen
|
||||
update() {
|
||||
const second = this.getTime().second;
|
||||
const minute = this.getTime().minute;
|
||||
const hour = this.getTime().hour;
|
||||
|
||||
this.updateShape('seconds', (second === 0) ? 60 : second);
|
||||
this.updateShape('minutes', (minute === 0) ? 60 : minute);
|
||||
this.updateShape('hours', this.options.h24 ? hour : hour % 12, this.options.h24 ? 24 : 12);
|
||||
this.updateShape('dotweek', this.getTime().dayWeek);
|
||||
this.updateShape('dotmonth', this.getTime().dayMonth, this.getTime().daysMonth);
|
||||
this.updateShape('dotyear', this.getTime().dayYear);
|
||||
this.updateShape('week', this.getTime().week);
|
||||
this.updateShape('month', this.getTime().month);
|
||||
this.updateShape('moon', this.getTime().moon);
|
||||
this.draw();
|
||||
}
|
||||
|
||||
#toPixelX(number) {
|
||||
return number * this.parts[0].element.width;
|
||||
}
|
||||
|
||||
#toPixelY(number) {
|
||||
return number * this.parts[0].element.height;
|
||||
}
|
||||
|
||||
#toPixelSize(number) {
|
||||
return number * Math.min(this.parts[0].element.width, this.parts[0].element.height);
|
||||
}
|
||||
|
||||
// TODO: DateDisplay und TimeDisplay benutzen
|
||||
// TODO: Parameter für Wochenstart ergänzen
|
||||
getWeekday(date) {
|
||||
const weekday = date.getDay(); // 0 (Sunday) to 6 (Saturday)
|
||||
|
||||
return (weekday === 0) ? 7 : weekday;
|
||||
}
|
||||
|
||||
getYearDay(date) {
|
||||
const start = new Date(date.getFullYear(), 0, 0);
|
||||
|
||||
return Math.floor((date - start) / 86400000);
|
||||
}
|
||||
|
||||
isLeapYear(year) {
|
||||
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
|
||||
}
|
||||
|
||||
getDaysInYear(year) {
|
||||
return this.isLeapYear(year) ? 366 : 365;
|
||||
}
|
||||
|
||||
getYearInfo(date) {
|
||||
const current = this.getYearDay(date);
|
||||
const total = this.getDaysInYear(date.getFullYear());
|
||||
const remaining = total - current;
|
||||
|
||||
return {
|
||||
total: total,
|
||||
current: current,
|
||||
remaining: remaining
|
||||
}
|
||||
}
|
||||
|
||||
getDaysInMonth(month, year) {
|
||||
return new Date(year, month, 0).getDate();
|
||||
}
|
||||
|
||||
// ISO 8601
|
||||
getISOWeek(date) {
|
||||
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||
const dayNum = d.getUTCDay() || 7;
|
||||
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
||||
const start = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||||
|
||||
return Math.ceil((((d - start) / 86400000) + 1) / 7);
|
||||
}
|
||||
|
||||
getISOWeeksInYear(year) {
|
||||
// Check if Dec 28 is in week 53
|
||||
return this.getISOWeek(new Date(year, 11, 28)) === 53 ? 53 : 52;
|
||||
}
|
||||
|
||||
getISOWeekInfo(date) {
|
||||
const current = this.getISOWeek(date);
|
||||
const weeksYear = this.getISOWeeksInYear(date.getFullYear());
|
||||
|
||||
return {
|
||||
current,
|
||||
weeksYear
|
||||
};
|
||||
}
|
||||
|
||||
getMoonNameFrom(phase) {
|
||||
if (phase < 0.125) return 'New Moon';
|
||||
if (phase < 0.25) return 'Waxing Crescent';
|
||||
if (phase < 0.375) return 'First Quarter';
|
||||
if (phase < 0.5) return 'Waxing Gibbous';
|
||||
if (phase < 0.625) return 'Full Moon';
|
||||
if (phase < 0.75) return 'Waning Gibbous';
|
||||
if (phase < 0.875) return 'Last Quarter';
|
||||
return 'Waning Crescent';
|
||||
}
|
||||
|
||||
getMoonPhase(date) {
|
||||
// Known new moon date: January 6, 2000
|
||||
const newMoon = new Date(2000, 0, 6);
|
||||
const lunarCycle = 29.53058867; // days
|
||||
|
||||
const daysSinceNewMoon = (date - newMoon) / (1000 * 60 * 60 * 24);
|
||||
const phase = (daysSinceNewMoon % lunarCycle) / lunarCycle;
|
||||
|
||||
return {
|
||||
illumination: Math.abs(Math.cos(Math.PI * phase)),
|
||||
phase: mapRange(phase, 0, 1, 1, 8),
|
||||
phaseName: this.getMoonNameFrom(phase)
|
||||
};
|
||||
}
|
||||
|
||||
getSize() {
|
||||
const height = window.innerHeight;
|
||||
const width = window.innerWidth;
|
||||
|
||||
return {
|
||||
value: Math.min(height, width),
|
||||
smaller: height < width ? 'height' : 'width'
|
||||
};
|
||||
}
|
||||
|
||||
getTime(date) {
|
||||
this.date = date || new Date();
|
||||
|
||||
return {
|
||||
second: this.date.getSeconds(),
|
||||
minute: this.date.getMinutes(),
|
||||
hour: this.date.getHours(),
|
||||
dayWeek: this.getWeekday(this.date),
|
||||
dayMonth: this.date.getDate(),
|
||||
dayYear: this.getYearInfo(this.date).current,
|
||||
daysYear: this.getYearInfo(this.date).total,
|
||||
week: this.getISOWeekInfo(this.date).current,
|
||||
weeksYear: this.getISOWeekInfo(this.date).weeksYear,
|
||||
month: this.date.getMonth() + 1, // Get current month (0-11)
|
||||
daysMonth: this.getDaysInMonth(this.date.getMonth() + 1, this.date.getFullYear()),
|
||||
moon: this.getMoonPhase(this.date).phase
|
||||
};
|
||||
}
|
||||
|
||||
#createContext(names) {
|
||||
let parts = [];
|
||||
const wrap = document.createElement('div');
|
||||
|
||||
wrap.style.position = 'relative';
|
||||
wrap.style.height = this.options.size + 'px';
|
||||
wrap.style.width = this.options.size + 'px';
|
||||
|
||||
names.forEach(name => {
|
||||
const canvas = document.createElement('canvas');
|
||||
|
||||
canvas.style.position = 'absolute';
|
||||
canvas.style.top = '0px';
|
||||
canvas.style.left = '0px';
|
||||
canvas.style.height = '100%';
|
||||
canvas.style.width = '100%';
|
||||
canvas.height = canvas.offsetHeight;
|
||||
canvas.width = canvas.offsetWidth;
|
||||
|
||||
wrap.appendChild(canvas);
|
||||
this.parts.push({name: name, element: canvas, context: canvas.getContext('2d')});
|
||||
});
|
||||
|
||||
this.element.appendChild(wrap);
|
||||
this.parts.push({name: 'wrap', element: wrap});
|
||||
}
|
||||
|
||||
createOverlay() {
|
||||
const overlay = document.createElement('div');
|
||||
const text = document.createElement('p');
|
||||
const timeElement = document.createElement('span');
|
||||
const dateElement = document.createElement('span');
|
||||
|
||||
new DateDisplay(dateElement);
|
||||
new TimeDisplay(timeElement);
|
||||
|
||||
Object.assign(overlay.style, {
|
||||
zIndex: 5,
|
||||
position: 'absolute',
|
||||
top: '0px',
|
||||
left: '0px',
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
display: this.options.overlay ? 'flex' : 'none',
|
||||
// display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: `rgba(0, 0, 0, .6)`,
|
||||
color: 'white'
|
||||
});
|
||||
overlay.dataset.part = 'overlay';
|
||||
|
||||
text.appendChild(timeElement);
|
||||
text.insertAdjacentText('beforeend', ' ');
|
||||
text.appendChild(dateElement);
|
||||
overlay.appendChild(text);
|
||||
this.element.appendChild(overlay);
|
||||
this.parts.push({name: 'overlay', element: overlay});
|
||||
}
|
||||
|
||||
removeOverlay() {
|
||||
const index = this.parts.findIndex(s => s.name === 'overlay');
|
||||
|
||||
if (index !== -1) {
|
||||
this.parts[index].element.remove();
|
||||
this.parts.splice(index, 1);
|
||||
this.draw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
updateOptions(changes) {
|
||||
this.options = {...this.options, ...changes};
|
||||
}
|
||||
|
||||
updateShape(id, angle, max) {
|
||||
const shape = this.shapes.find(s => s.id === id);
|
||||
|
||||
if (shape) {
|
||||
shape.angle = angle;
|
||||
if (max) shape.max = max;
|
||||
}
|
||||
}
|
||||
|
||||
removeShape(id) {
|
||||
const index = this.shapes.findIndex(s => s.id === id);
|
||||
|
||||
if (index !== -1) {
|
||||
this.shapes.splice(index, 1);
|
||||
this.draw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
clearShapes() {
|
||||
this.shapes = [];
|
||||
this.draw();
|
||||
}
|
||||
|
||||
findShape(id) {
|
||||
return this.shapes.some(s => s.id === id);
|
||||
}
|
||||
|
||||
getShape(id) {
|
||||
return this.shapes.find(s => s.id === id);
|
||||
}
|
||||
|
||||
addCircle(id, center, radius, color = `rgba(0, 0, 0, .1)`) {
|
||||
this.shapes.push({type: 'circle', id, center, radius, color});
|
||||
}
|
||||
|
||||
addRing(id, radius, angle, max, color = 'white', center = .5, stroke = 16) {
|
||||
this.shapes.push({type: 'ring', id, radius, angle, max, color, center, stroke});
|
||||
}
|
||||
|
||||
addSection(id, radius, color = 'black', center = .5, stroke = 1) {
|
||||
this.shapes.push({type: 'section', id, radius, color, center, stroke});
|
||||
}
|
||||
}
|
||||
|
||||
const container = document.querySelector('#clock main');
|
||||
const clock = new HippieClock(container);
|
||||
|
||||
clock.addCircle('base', .5, 1);
|
||||
clock.draw();
|
||||
|
||||
// TODO: Alternative mit requestAnimationFrame()
|
||||
setInterval(() => {
|
||||
clock.update();
|
||||
}, 1000);
|
||||
|
||||
// TODO: Aktionen gehören quasi zu HippieClock
|
||||
document.getElementById('tglFormat').addEventListener('click', () => {
|
||||
is24HourFormat = !is24HourFormat;
|
||||
document.getElementById('tglFormat').textContent = is24HourFormat ? '12-Stunden-Format' : '24-Stunden-Format';
|
||||
sections[2].amount = is24HourFormat ? 24 : 12;
|
||||
drawBackground();
|
||||
if (clock) {
|
||||
clock.updateOptions({h24: !clock.options.h24});
|
||||
document.getElementById('tglFormat').textContent = clock.options.h24 ? '12-Stunden' : '24-Stunden';
|
||||
} else {
|
||||
console.log('No clock available');
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('tglSections').addEventListener('click', () => {
|
||||
drawSections = !drawSections;
|
||||
drawBackground();
|
||||
if (clock) {
|
||||
clock.updateOptions({sections: !clock.options.sections});
|
||||
} else {
|
||||
console.log('No clock available');
|
||||
}
|
||||
});
|
||||
|
||||
// FIXME: Konstanten mit maxSize werden nicht verändert
|
||||
window.addEventListener('resize', resizeClock);
|
||||
|
||||
drawBackground();
|
||||
updateRings();
|
||||
// TODO: TimeDisplay nutzen, ev. erweitern oder ähnliche Umsetzung anwenden
|
||||
setInterval(updateRings, 1000);
|
||||
|
||||
function updateRings() {
|
||||
currentDate = new Date();
|
||||
const currentSeconds = currentDate.getSeconds();
|
||||
const currentMinutes = currentDate.getMinutes();
|
||||
const currentHours = currentDate.getHours();
|
||||
const currentDayOfWeek = getNumericWeekday(currentDate);
|
||||
const currentDayOfMonth = currentDate.getDate();
|
||||
const currentDayOfYear = getNumericYearDay(currentDate);
|
||||
currentMonth = currentDate.getMonth() + 1; // Get current month (0-11)
|
||||
daysInCurrentMonth = daysInMonth(currentMonth, currentDate.getFullYear());
|
||||
|
||||
drawRings(
|
||||
currentSeconds,
|
||||
currentMinutes,
|
||||
currentHours,
|
||||
currentDayOfWeek,
|
||||
currentDayOfMonth,
|
||||
currentMonth,
|
||||
currentDayOfYear,
|
||||
daysInCurrentMonth
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Parameter für Wochenstart ergänzen
|
||||
function getNumericWeekday(date) {
|
||||
const weekday = date.getDay(); // 0 (Sunday) to 6 (Saturday)
|
||||
return (weekday === 0) ? 7 : weekday;
|
||||
}
|
||||
|
||||
function getNumericYearDay(date) {
|
||||
const start = new Date(date.getFullYear(), 0, 0);
|
||||
return Math.floor((date - start) / 86400000);
|
||||
}
|
||||
|
||||
function daysInMonth(month, year) {
|
||||
return new Date(year, month, 0).getDate();
|
||||
}
|
||||
|
||||
function drawArc(value, maxValue, radius, strokeStyle) {
|
||||
const startAngle = -0.5 * Math.PI; // Start at the top
|
||||
const endAngle = startAngle + (2 * Math.PI * (value / maxValue));
|
||||
|
||||
ctxRings.lineWidth = 16;
|
||||
ctxRings.strokeStyle = strokeStyle;
|
||||
ctxRings.beginPath();
|
||||
ctxRings.arc(centerX, centerY, radius, startAngle, endAngle, false);
|
||||
ctxRings.stroke();
|
||||
}
|
||||
|
||||
// TODO: Array rings nutzen
|
||||
function drawRings(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, dayOfYear, daysInCurrentMonth) {
|
||||
ctxRings.clearRect(0, 0, canvasRings.width, canvasRings.height);
|
||||
|
||||
drawArc(
|
||||
(seconds === 0) ? 60 : seconds,
|
||||
60,
|
||||
rings[0].radius,
|
||||
rings[0].color
|
||||
);
|
||||
drawArc(
|
||||
(minutes === 0) ? 60 : minutes,
|
||||
60,
|
||||
rings[1].radius,
|
||||
rings[1].color
|
||||
);
|
||||
drawArc(
|
||||
// is24HourFormat ? ((hours === 0) ? 24 : hours) : hours % 12,
|
||||
is24HourFormat ? hours : hours % 12,
|
||||
is24HourFormat ? 24 : 12,
|
||||
rings[2].radius,
|
||||
rings[2].color
|
||||
);
|
||||
drawArc(dayOfWeek, 7, rings[3].radius, rings[3].color);
|
||||
drawArc(dayOfMonth, daysInCurrentMonth, rings[4].radius, rings[4].color);
|
||||
drawArc(dayOfYear, 365, rings[5].radius, rings[5].color);
|
||||
drawArc(month, 12, rings[6].radius, rings[6].color);
|
||||
}
|
||||
|
||||
function drawBackground() {
|
||||
ctxBkg.clearRect(0, 0, canvasBkg.width, canvasBkg.height);
|
||||
|
||||
groups.forEach((section) => {
|
||||
ctxBkg.strokeStyle = section.color;
|
||||
ctxBkg.lineWidth = section.width;
|
||||
ctxBkg.beginPath();
|
||||
ctxBkg.arc(centerX, centerY, section.radius, 0, 2 * Math.PI);
|
||||
ctxBkg.stroke();
|
||||
});
|
||||
|
||||
if (drawSections) {
|
||||
sections.forEach((marker) => {
|
||||
for (let i = 0; i < marker.amount; i++) {
|
||||
const angle = (i * (360 / marker.amount) - 90) * (Math.PI / 180); // -90 to start at top
|
||||
const outerRadius = marker.radius + ringWidth / 2;
|
||||
const outerX = centerX + outerRadius * Math.cos(angle);
|
||||
const outerY = centerY + outerRadius * Math.sin(angle);
|
||||
const innerRadius = marker.radius - ringWidth / 2;
|
||||
const innerX = centerX + innerRadius * Math.cos(angle);
|
||||
const innerY = centerY + innerRadius * Math.sin(angle);
|
||||
|
||||
ctxBkg.strokeStyle = sectionMarkerColor;
|
||||
ctxBkg.lineWidth = marker.width;
|
||||
ctxBkg.beginPath();
|
||||
ctxBkg.moveTo(outerX, outerY);
|
||||
ctxBkg.lineTo(innerX, innerY);
|
||||
ctxBkg.stroke();
|
||||
}
|
||||
});
|
||||
document.getElementById('tglOverlay').addEventListener('click', () => {
|
||||
if (clock) {
|
||||
// TODO: Anzeigen und ausblenden, anstatt löschen und hinzufügen?
|
||||
clock.options.overlay ? clock.removeOverlay() : clock.createOverlay();
|
||||
clock.updateOptions({overlay: !clock.options.overlay});
|
||||
} else {
|
||||
console.log('No clock available');
|
||||
}
|
||||
}
|
||||
|
||||
function resizeClock() {
|
||||
const height = window.innerHeight;
|
||||
const width = window.innerWidth;
|
||||
const windowDimension = {
|
||||
value: Math.min(height, width),
|
||||
smaller: height < width ? 'height' : 'width'
|
||||
};
|
||||
const clockSize = Math.floor(windowDimension.value * 0.9);
|
||||
|
||||
canvasBkg.style.width = clockSize + 'px';
|
||||
canvasBkg.style.height = clockSize + 'px';
|
||||
canvasRings.style.width = clockSize + 'px';
|
||||
canvasRings.style.height = clockSize + 'px';
|
||||
canvasBkg.width = clockSize;
|
||||
canvasBkg.height = clockSize;
|
||||
canvasRings.width = clockSize;
|
||||
canvasRings.height = clockSize;
|
||||
|
||||
centerX = canvasRings.width / 2;
|
||||
centerY = canvasRings.height / 2;
|
||||
maxSize = (canvasRings.width / 2 - ringWidth / 2) - outerMargin;
|
||||
|
||||
wrap.style.width = clockSize + 'px';
|
||||
wrap.style.height = clockSize + 'px';
|
||||
|
||||
console.debug(windowDimension);
|
||||
console.debug('Clock size: ', clockSize);
|
||||
console.debug('Radius: ', maxSize);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -50,9 +50,8 @@ tags:
|
|||
{% endblock %}
|
||||
|
||||
{%- block script %}
|
||||
{% comment %}<script src="/js/globals.js"></script>{% endcomment %}
|
||||
<script src="/vendor/hippie-script.js"></script>
|
||||
<script src="/js/app.js"></script>
|
||||
{{ block.super -}}
|
||||
|
||||
<script src="/js/windows.js"></script>
|
||||
<script>
|
||||
console.log(HIPPIE.brand);
|
||||
|
|
@ -61,6 +60,7 @@ tags:
|
|||
const start = document.querySelector('[data-action=start]');
|
||||
const draggableElement = document.getElementById('task-bar');
|
||||
const placeholderElement = document.getElementById('placeholder');
|
||||
// TODO: TimeDisplay in HippieTaskbar aufnehmen
|
||||
const timeElement = document.getElementById('time');
|
||||
|
||||
const taskBar = new HippieTaskBar(draggableElement, placeholderElement);
|
||||
|
|
|
|||
|
|
@ -63,13 +63,3 @@ tags:
|
|||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
{{ block.super -}}
|
||||
{% render 'hippie/partials/log-assets', state: true -%}
|
||||
{% render 'hippie/partials/log-log', msg: 'BODY :: Assets loaded, running page specific script...', arg: true -%}
|
||||
<script>
|
||||
// Page script
|
||||
</script>
|
||||
{% render 'hippie/partials/log-log' with 'Application ready... or is it?' as msg -%}
|
||||
{% endblock %}
|
||||
|
|
@ -1,18 +1,12 @@
|
|||
@use "../hippie-style/hippie";
|
||||
|
||||
:root {
|
||||
--clock-color-yellow: rgb(250, 216, 3);
|
||||
--clock-color-orange: rgb(242, 175, 19);
|
||||
--clock-color-pink: rgb(211, 10, 81);
|
||||
--clock-color-purple: rgb(142, 31, 104);
|
||||
--clock-color-blue: rgb(39, 63, 139);
|
||||
--clock-color-pblue: rgb(60, 87, 154);
|
||||
--clock-color-lblue: rgb(183, 224, 240);
|
||||
--clock-color-lcyan: rgb(107, 199, 217);
|
||||
--clock-color-cyan: rgb(82, 190, 209);
|
||||
}
|
||||
@use "sass:map";
|
||||
|
||||
.body_clock {
|
||||
header {
|
||||
z-index: map.get(hippie.$z-indexes, "content-top");
|
||||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
flex-flow: column nowrap;
|
||||
|
|
@ -22,18 +16,4 @@
|
|||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
<body{{ bodyClassAttr }}>
|
||||
{%- block body %}{% endblock -%}
|
||||
<script>
|
||||
// {{ title }} script
|
||||
// {{ title }} script using default template
|
||||
</script>
|
||||
{%- block script %}{% endblock -%}
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -37,9 +37,12 @@
|
|||
{%- block body %}{% endblock -%}
|
||||
{% render 'hippie/partials/log-log' with 'BODY :: Loading script assets...' as msg -%}
|
||||
<script>
|
||||
// Full script
|
||||
// {{ title }} script using full template
|
||||
</script>
|
||||
{%- block script %}{% endblock -%}
|
||||
{% render 'hippie/partials/log-assets', state: true -%}
|
||||
{% render 'hippie/partials/log-log', msg: 'BODY :: Assets loaded, running page specific script...', arg: true -%}
|
||||
{% render 'hippie/partials/log-log' with 'BODY end :: Page script might still be loading.' as msg -%}
|
||||
{% render 'hippie/partials/log-log' with 'Application ready... or is it?' as msg -%}
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -7,9 +7,3 @@
|
|||
{{ block.super -}}
|
||||
<link href="/css/demo.css" media="all" rel="stylesheet"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script src="/vendor/hippie-script.js"></script>
|
||||
<script src="/js/globals.js"></script>
|
||||
<script src="/js/app.js"></script>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue