1316 lines
37 KiB
HTML
1316 lines
37 KiB
HTML
|
||
<!DOCTYPE html>
|
||
<html lang="de">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Lernprojekt – HTML, CSS & JavaScript</title>
|
||
|
||
<style>
|
||
/* =========================
|
||
1. GRUNDDESIGN / CSS
|
||
========================= */
|
||
|
||
* {
|
||
box-sizing: border-box;
|
||
margin: 0;
|
||
padding: 0;
|
||
}
|
||
|
||
:root {
|
||
--bg: #f4f6fb;
|
||
--card: #ffffff;
|
||
--text: #202438;
|
||
--muted: #6b7280;
|
||
--primary: #635bdb;
|
||
--primary-hover: #4d46c5;
|
||
--border: #e1e5ee;
|
||
--success: #16845b;
|
||
--danger: #d93650;
|
||
--input: #ffffff;
|
||
}
|
||
|
||
body.dark {
|
||
--bg: #171925;
|
||
--card: #222536;
|
||
--text: #f3f4fa;
|
||
--muted: #b3b7c8;
|
||
--primary: #938cff;
|
||
--primary-hover: #aaa5ff;
|
||
--border: #3a3e52;
|
||
--success: #54d6a0;
|
||
--danger: #ff7588;
|
||
--input: #2b2f43;
|
||
}
|
||
|
||
body {
|
||
font-family: Arial, Helvetica, sans-serif;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
line-height: 1.6;
|
||
transition: background 0.2s, color 0.2s;
|
||
}
|
||
|
||
button,
|
||
input {
|
||
font: inherit;
|
||
}
|
||
|
||
button {
|
||
cursor: pointer;
|
||
}
|
||
|
||
.container {
|
||
width: min(1100px, 92%);
|
||
margin: 0 auto;
|
||
}
|
||
|
||
/* =========================
|
||
2. KOPFBEREICH
|
||
========================= */
|
||
|
||
header {
|
||
background: var(--card);
|
||
border-bottom: 1px solid var(--border);
|
||
padding: 18px 0;
|
||
}
|
||
|
||
.header-content {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
gap: 15px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.logo {
|
||
font-size: 22px;
|
||
font-weight: bold;
|
||
color: var(--primary);
|
||
}
|
||
|
||
.header-actions {
|
||
display: flex;
|
||
gap: 10px;
|
||
}
|
||
|
||
/* =========================
|
||
3. BUTTONS
|
||
========================= */
|
||
|
||
.btn {
|
||
border: none;
|
||
border-radius: 9px;
|
||
padding: 10px 15px;
|
||
background: var(--primary);
|
||
color: white;
|
||
font-weight: bold;
|
||
transition: 0.2s;
|
||
}
|
||
|
||
.btn:hover {
|
||
background: var(--primary-hover);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.btn-secondary {
|
||
background: transparent;
|
||
color: var(--text);
|
||
border: 1px solid var(--border);
|
||
}
|
||
|
||
.btn-secondary:hover {
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
}
|
||
|
||
.btn-danger {
|
||
background: var(--danger);
|
||
}
|
||
|
||
/* =========================
|
||
4. HAUPTBEREICH
|
||
========================= */
|
||
|
||
main {
|
||
padding: 35px 0;
|
||
}
|
||
|
||
.intro {
|
||
margin-bottom: 25px;
|
||
}
|
||
|
||
.intro h1 {
|
||
font-size: clamp(26px, 4vw, 36px);
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.intro p {
|
||
color: var(--muted);
|
||
}
|
||
|
||
.grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||
gap: 20px;
|
||
}
|
||
|
||
.card {
|
||
background: var(--card);
|
||
border: 1px solid var(--border);
|
||
border-radius: 15px;
|
||
padding: 22px;
|
||
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.03);
|
||
}
|
||
|
||
.card h2 {
|
||
font-size: 20px;
|
||
margin-bottom: 14px;
|
||
}
|
||
|
||
.card p {
|
||
color: var(--muted);
|
||
}
|
||
|
||
.full-width {
|
||
grid-column: 1 / -1;
|
||
}
|
||
|
||
/* =========================
|
||
5. FORMULARE
|
||
========================= */
|
||
|
||
.form-group {
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
label {
|
||
display: block;
|
||
font-weight: bold;
|
||
margin-bottom: 6px;
|
||
}
|
||
|
||
input {
|
||
width: 100%;
|
||
padding: 11px 12px;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
background: var(--input);
|
||
color: var(--text);
|
||
outline: none;
|
||
}
|
||
|
||
input:focus {
|
||
border-color: var(--primary);
|
||
box-shadow: 0 0 0 3px rgba(99, 91, 219, 0.13);
|
||
}
|
||
|
||
.password-row {
|
||
display: flex;
|
||
gap: 8px;
|
||
}
|
||
|
||
.password-row input {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.password-row button {
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.message {
|
||
min-height: 24px;
|
||
margin-top: 10px;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.success-text {
|
||
color: var(--success);
|
||
}
|
||
|
||
.error-text {
|
||
color: var(--danger);
|
||
}
|
||
|
||
/* =========================
|
||
6. SUCHE UND LISTEN
|
||
========================= */
|
||
|
||
.search-box {
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.item-list,
|
||
.task-list {
|
||
list-style: none;
|
||
}
|
||
|
||
.item-list li,
|
||
.task-list li {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
padding: 12px;
|
||
border-bottom: 1px solid var(--border);
|
||
}
|
||
|
||
.item-list li:last-child,
|
||
.task-list li:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.tag {
|
||
display: inline-block;
|
||
padding: 3px 9px;
|
||
border-radius: 20px;
|
||
background: rgba(99, 91, 219, 0.12);
|
||
color: var(--primary);
|
||
font-size: 12px;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.empty-message {
|
||
padding: 12px 0;
|
||
color: var(--muted);
|
||
}
|
||
|
||
/* =========================
|
||
7. AUFGABENLISTE
|
||
========================= */
|
||
|
||
.add-task-row {
|
||
display: flex;
|
||
gap: 10px;
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.add-task-row input {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.task-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
min-width: 0;
|
||
}
|
||
|
||
.task-left input {
|
||
width: auto;
|
||
}
|
||
|
||
.task-text {
|
||
overflow-wrap: anywhere;
|
||
}
|
||
|
||
.completed .task-text {
|
||
text-decoration: line-through;
|
||
color: var(--muted);
|
||
}
|
||
|
||
.delete-task {
|
||
padding: 5px 9px;
|
||
border: none;
|
||
border-radius: 7px;
|
||
background: rgba(217, 54, 80, 0.12);
|
||
color: var(--danger);
|
||
}
|
||
|
||
/* =========================
|
||
8. TABS
|
||
========================= */
|
||
|
||
.tab-buttons {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.tab-button {
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 8px 13px;
|
||
background: transparent;
|
||
color: var(--text);
|
||
}
|
||
|
||
.tab-button.active {
|
||
background: var(--primary);
|
||
border-color: var(--primary);
|
||
color: white;
|
||
}
|
||
|
||
.tab-panel {
|
||
display: none;
|
||
padding: 15px;
|
||
border-radius: 10px;
|
||
background: var(--bg);
|
||
}
|
||
|
||
.tab-panel.active {
|
||
display: block;
|
||
}
|
||
|
||
/* =========================
|
||
9. CODE-BEISPIELE
|
||
========================= */
|
||
|
||
.code-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
gap: 10px;
|
||
flex-wrap: wrap;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
pre {
|
||
white-space: pre-wrap;
|
||
overflow-wrap: anywhere;
|
||
padding: 16px;
|
||
border-radius: 10px;
|
||
background: #171925;
|
||
color: #e8e9f5;
|
||
overflow-x: auto;
|
||
font-size: 13px;
|
||
}
|
||
|
||
select {
|
||
max-width: 100%;
|
||
padding: 9px;
|
||
border-radius: 8px;
|
||
border: 1px solid var(--border);
|
||
background: var(--input);
|
||
color: var(--text);
|
||
}
|
||
|
||
/* =========================
|
||
10. MODAL-FENSTER
|
||
========================= */
|
||
|
||
.modal {
|
||
display: none;
|
||
position: fixed;
|
||
inset: 0;
|
||
z-index: 100;
|
||
background: rgba(0, 0, 0, 0.6);
|
||
justify-content: center;
|
||
align-items: center;
|
||
padding: 20px;
|
||
}
|
||
|
||
.modal.open {
|
||
display: flex;
|
||
}
|
||
|
||
.modal-content {
|
||
width: min(450px, 100%);
|
||
padding: 25px;
|
||
border-radius: 15px;
|
||
background: var(--card);
|
||
}
|
||
|
||
.modal-content h2 {
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.modal-content p {
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
/* =========================
|
||
11. TOAST-NACHRICHTEN
|
||
========================= */
|
||
|
||
.toast-container {
|
||
position: fixed;
|
||
right: 20px;
|
||
bottom: 20px;
|
||
z-index: 200;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 10px;
|
||
}
|
||
|
||
.toast {
|
||
max-width: 320px;
|
||
padding: 13px 18px;
|
||
border-radius: 10px;
|
||
color: white;
|
||
background: #25283a;
|
||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
|
||
animation: slideIn 0.25s ease;
|
||
}
|
||
|
||
.toast.success {
|
||
background: #16845b;
|
||
}
|
||
|
||
.toast.error {
|
||
background: #c92f49;
|
||
}
|
||
|
||
@keyframes slideIn {
|
||
from {
|
||
opacity: 0;
|
||
transform: translateY(10px);
|
||
}
|
||
|
||
to {
|
||
opacity: 1;
|
||
transform: translateY(0);
|
||
}
|
||
}
|
||
|
||
/* =========================
|
||
12. FOOTER
|
||
========================= */
|
||
|
||
footer {
|
||
text-align: center;
|
||
color: var(--muted);
|
||
padding: 25px 0;
|
||
}
|
||
|
||
/* =========================
|
||
13. RESPONSIVE DESIGN
|
||
========================= */
|
||
|
||
@media (max-width: 700px) {
|
||
.grid {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.full-width {
|
||
grid-column: auto;
|
||
}
|
||
|
||
.card {
|
||
padding: 17px;
|
||
}
|
||
|
||
.add-task-row {
|
||
flex-direction: column;
|
||
}
|
||
|
||
.header-content {
|
||
align-items: flex-start;
|
||
}
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
|
||
<!-- =========================
|
||
HTML: KOPFBEREICH
|
||
========================= -->
|
||
|
||
<header>
|
||
<div class="container header-content">
|
||
<div class="logo">CodeLernen</div>
|
||
|
||
<div class="header-actions">
|
||
<button class="btn btn-secondary" id="themeButton">
|
||
🌙 Dark Mode
|
||
</button>
|
||
|
||
<button class="btn" id="openModalButton">
|
||
Info anzeigen
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</header>
|
||
|
||
<!-- =========================
|
||
HTML: HAUPTINHALT
|
||
========================= -->
|
||
|
||
<main class="container">
|
||
|
||
<section class="intro">
|
||
<h1>HTML, CSS & JavaScript</h1>
|
||
<p>
|
||
Ein kleines Lernprojekt mit Formularen, Events, Listen,
|
||
Suche, Bedingungen und DOM-Manipulation.
|
||
</p>
|
||
</section>
|
||
|
||
<div class="grid">
|
||
|
||
<!-- LOGIN-FORMULAR -->
|
||
|
||
<section class="card">
|
||
<h2>1. Login-Formular</h2>
|
||
|
||
<form id="loginForm">
|
||
<div class="form-group">
|
||
<label for="username">Benutzername</label>
|
||
<input
|
||
type="text"
|
||
id="username"
|
||
placeholder="z. B. Max"
|
||
>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="password">Passwort</label>
|
||
|
||
<div class="password-row">
|
||
<input
|
||
type="password"
|
||
id="password"
|
||
placeholder="Mindestens 4 Zeichen"
|
||
>
|
||
|
||
<button
|
||
type="button"
|
||
class="btn btn-secondary"
|
||
id="togglePassword"
|
||
>
|
||
Anzeigen
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<button type="submit" class="btn">
|
||
Einloggen
|
||
</button>
|
||
|
||
<p id="loginMessage" class="message"></p>
|
||
</form>
|
||
|
||
<p>
|
||
<strong>Lernziel:</strong>
|
||
form submit, preventDefault(), if/else und value.
|
||
</p>
|
||
</section>
|
||
|
||
<!-- KLICKZÄHLER -->
|
||
|
||
<section class="card">
|
||
<h2>2. Event Listener</h2>
|
||
|
||
<p>
|
||
Jeder Klick erhöht den Zähler um eins.
|
||
</p>
|
||
|
||
<h1 id="clickCount">0</h1>
|
||
|
||
<button class="btn" id="countButton">
|
||
Klick mich!
|
||
</button>
|
||
|
||
<button class="btn btn-secondary" id="resetCountButton">
|
||
Zurücksetzen
|
||
</button>
|
||
|
||
<p>
|
||
<strong>Lernziel:</strong>
|
||
addEventListener() und Variablen.
|
||
</p>
|
||
</section>
|
||
|
||
<!-- SUCHE -->
|
||
|
||
<section class="card">
|
||
<h2>3. Live-Suche</h2>
|
||
|
||
<input
|
||
type="text"
|
||
id="searchInput"
|
||
class="search-box"
|
||
placeholder="Person suchen..."
|
||
>
|
||
|
||
<ul id="peopleList" class="item-list">
|
||
<li>
|
||
<span>Max Mustermann</span>
|
||
<span class="tag">HTML</span>
|
||
</li>
|
||
<li>
|
||
<span>Anna Müller</span>
|
||
<span class="tag">CSS</span>
|
||
</li>
|
||
<li>
|
||
<span>Lisa Berger</span>
|
||
<span class="tag">JavaScript</span>
|
||
</li>
|
||
<li>
|
||
<span>Tom Wagner</span>
|
||
<span class="tag">HTML</span>
|
||
</li>
|
||
<li>
|
||
<span>Sarah Bauer</span>
|
||
<span class="tag">JavaScript</span>
|
||
</li>
|
||
</ul>
|
||
|
||
<p id="searchMessage" class="empty-message"></p>
|
||
|
||
<p>
|
||
<strong>Lernziel:</strong>
|
||
input-Event, includes() und toLowerCase().
|
||
</p>
|
||
</section>
|
||
|
||
<!-- AUFGABENLISTE -->
|
||
|
||
<section class="card">
|
||
<h2>4. Aufgabenliste</h2>
|
||
|
||
<div class="add-task-row">
|
||
<input
|
||
type="text"
|
||
id="taskInput"
|
||
placeholder="Neue Aufgabe eingeben..."
|
||
>
|
||
|
||
<button class="btn" id="addTaskButton">
|
||
Hinzufügen
|
||
</button>
|
||
</div>
|
||
|
||
<ul id="taskList" class="task-list">
|
||
<li>
|
||
<div class="task-left">
|
||
<input type="checkbox">
|
||
<span class="task-text">HTML wiederholen</span>
|
||
</div>
|
||
<button class="delete-task">Löschen</button>
|
||
</li>
|
||
|
||
<li>
|
||
<div class="task-left">
|
||
<input type="checkbox">
|
||
<span class="task-text">CSS lernen</span>
|
||
</div>
|
||
<button class="delete-task">Löschen</button>
|
||
</li>
|
||
</ul>
|
||
|
||
<p>
|
||
<strong>Lernziel:</strong>
|
||
createElement(), appendChild() und remove().
|
||
</p>
|
||
</section>
|
||
|
||
<!-- TABS -->
|
||
|
||
<section class="card full-width">
|
||
<h2>5. Tabs / Registerkarten</h2>
|
||
|
||
<div class="tab-buttons">
|
||
<button class="tab-button active" data-tab="htmlTab">
|
||
HTML
|
||
</button>
|
||
|
||
<button class="tab-button" data-tab="cssTab">
|
||
CSS
|
||
</button>
|
||
|
||
<button class="tab-button" data-tab="jsTab">
|
||
JavaScript
|
||
</button>
|
||
</div>
|
||
|
||
<div id="htmlTab" class="tab-panel active">
|
||
<h3>HTML</h3>
|
||
<p>
|
||
HTML strukturiert die Website.
|
||
Beispiele sind h1, p, div, form und button.
|
||
</p>
|
||
</div>
|
||
|
||
<div id="cssTab" class="tab-panel">
|
||
<h3>CSS</h3>
|
||
<p>
|
||
CSS gestaltet die Website mit Farben,
|
||
Abständen, Schriftarten und Layouts.
|
||
</p>
|
||
</div>
|
||
|
||
<div id="jsTab" class="tab-panel">
|
||
<h3>JavaScript</h3>
|
||
<p>
|
||
JavaScript macht die Website interaktiv,
|
||
zum Beispiel mit Events, Bedingungen und Funktionen.
|
||
</p>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- CODE-REFERENZ -->
|
||
|
||
<section class="card full-width">
|
||
<h2>6. JavaScript-Code zum Lernen</h2>
|
||
|
||
<div class="code-row">
|
||
<label for="codeSelect">Beispiel auswählen</label>
|
||
|
||
<select id="codeSelect">
|
||
<option value="event">Event Listener</option>
|
||
<option value="condition">if / else</option>
|
||
<option value="loop">Schleife</option>
|
||
<option value="filter">Array filter()</option>
|
||
<option value="element">Element erstellen</option>
|
||
<option value="class">classList</option>
|
||
<option value="form">Formular überprüfen</option>
|
||
</select>
|
||
</div>
|
||
|
||
<pre><code id="codeDisplay"></code></pre>
|
||
|
||
<button class="btn" id="copyCodeButton">
|
||
Code kopieren
|
||
</button>
|
||
|
||
<p id="copyMessage" class="message"></p>
|
||
</section>
|
||
|
||
<!-- ZUSAMMENFASSUNG -->
|
||
|
||
<section class="card full-width">
|
||
<h2>7. Wichtige Begriffe für die Prüfung</h2>
|
||
|
||
<ul>
|
||
<li>
|
||
<strong>querySelector():</strong>
|
||
Wählt das erste passende HTML-Element aus.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>getElementById():</strong>
|
||
Sucht ein Element anhand seiner ID.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>addEventListener():</strong>
|
||
Führt eine Funktion aus, wenn ein Ereignis eintritt.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>if / else:</strong>
|
||
Führt abhängig von einer Bedingung unterschiedlichen
|
||
Code aus.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>value:</strong>
|
||
Liest den Wert eines Eingabefelds.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>textContent:</strong>
|
||
Liest oder ändert den Text eines Elements.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>createElement():</strong>
|
||
Erstellt ein neues HTML-Element.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>appendChild():</strong>
|
||
Fügt ein Element einem anderen Element hinzu.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>classList.add():</strong>
|
||
Fügt eine CSS-Klasse hinzu.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>preventDefault():</strong>
|
||
Verhindert die Standardaktion eines Ereignisses.
|
||
</li>
|
||
|
||
<li>
|
||
<strong>filter():</strong>
|
||
Erstellt ein Array mit Elementen, die eine Bedingung erfüllen.
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
|
||
</div>
|
||
</main>
|
||
|
||
<footer>
|
||
<div class="container">
|
||
Lernprojekt für HTML, CSS und JavaScript
|
||
</div>
|
||
</footer>
|
||
|
||
<!-- MODAL-FENSTER -->
|
||
|
||
<div class="modal" id="infoModal">
|
||
<div class="modal-content">
|
||
<h2>Willkommen!</h2>
|
||
|
||
<p>
|
||
Dieses Projekt zeigt typische Grundlagen für eine
|
||
HTML-, CSS- und JavaScript-Prüfung.
|
||
</p>
|
||
|
||
<button class="btn" id="closeModalButton">
|
||
Schließen
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- TOAST-NACHRICHTEN -->
|
||
|
||
<div class="toast-container" id="toastContainer"></div>
|
||
|
||
<!-- =========================
|
||
JAVASCRIPT
|
||
========================= -->
|
||
|
||
<script>
|
||
// ==================================
|
||
// 1. HILFSFUNKTION: TOAST-MELDUNGEN
|
||
// ==================================
|
||
|
||
function showToast(message, type = "success") {
|
||
// Erstellt ein neues div-Element.
|
||
const toast = document.createElement("div");
|
||
|
||
// Fügt CSS-Klassen hinzu.
|
||
toast.classList.add("toast", type);
|
||
|
||
// Legt den angezeigten Text fest.
|
||
toast.textContent = message;
|
||
|
||
// Fügt die Nachricht in den Container ein.
|
||
document.getElementById("toastContainer").appendChild(toast);
|
||
|
||
// Entfernt die Nachricht nach 3 Sekunden.
|
||
setTimeout(function () {
|
||
toast.remove();
|
||
}, 3000);
|
||
}
|
||
|
||
|
||
// ==================================
|
||
// 2. DARK MODE
|
||
// ==================================
|
||
|
||
const themeButton = document.getElementById("themeButton");
|
||
|
||
themeButton.addEventListener("click", function () {
|
||
// Fügt die Klasse dark hinzu oder entfernt sie.
|
||
document.body.classList.toggle("dark");
|
||
|
||
// Prüft, ob der Dark Mode aktiv ist.
|
||
if (document.body.classList.contains("dark")) {
|
||
themeButton.textContent = "☀️ Light Mode";
|
||
} else {
|
||
themeButton.textContent = "🌙 Dark Mode";
|
||
}
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 3. LOGIN-FORMULAR
|
||
// ==================================
|
||
|
||
const loginForm = document.getElementById("loginForm");
|
||
|
||
loginForm.addEventListener("submit", function (event) {
|
||
// Verhindert, dass das Formular die Seite neu lädt.
|
||
event.preventDefault();
|
||
|
||
// Liest die Werte aus den Eingabefeldern.
|
||
const username = document.getElementById("username").value.trim();
|
||
const password = document.getElementById("password").value;
|
||
|
||
const loginMessage = document.getElementById("loginMessage");
|
||
|
||
// Überprüft die Eingaben mit if / else.
|
||
if (username === "" || password === "") {
|
||
loginMessage.textContent = "Bitte alle Felder ausfüllen.";
|
||
loginMessage.className = "message error-text";
|
||
|
||
showToast("Bitte alle Felder ausfüllen.", "error");
|
||
} else if (password.length < 4) {
|
||
loginMessage.textContent =
|
||
"Das Passwort muss mindestens 4 Zeichen haben.";
|
||
|
||
loginMessage.className = "message error-text";
|
||
|
||
showToast("Passwort ist zu kurz.", "error");
|
||
} else {
|
||
loginMessage.textContent =
|
||
"Hallo " + username + "! Demo-Login erfolgreich.";
|
||
|
||
loginMessage.className = "message success-text";
|
||
|
||
showToast("Login-Demo erfolgreich!");
|
||
}
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 4. PASSWORT ANZEIGEN / VERSTECKEN
|
||
// ==================================
|
||
|
||
const togglePasswordButton =
|
||
document.getElementById("togglePassword");
|
||
|
||
togglePasswordButton.addEventListener("click", function () {
|
||
const passwordInput = document.getElementById("password");
|
||
|
||
// Ändert den Typ zwischen password und text.
|
||
if (passwordInput.type === "password") {
|
||
passwordInput.type = "text";
|
||
togglePasswordButton.textContent = "Verstecken";
|
||
} else {
|
||
passwordInput.type = "password";
|
||
togglePasswordButton.textContent = "Anzeigen";
|
||
}
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 5. KLICKZÄHLER
|
||
// ==================================
|
||
|
||
let count = 0;
|
||
|
||
const countButton = document.getElementById("countButton");
|
||
const resetCountButton = document.getElementById("resetCountButton");
|
||
const clickCount = document.getElementById("clickCount");
|
||
|
||
countButton.addEventListener("click", function () {
|
||
// Erhöht den Zähler um eins.
|
||
count++;
|
||
|
||
// Aktualisiert die Anzeige auf der Website.
|
||
clickCount.textContent = count;
|
||
});
|
||
|
||
resetCountButton.addEventListener("click", function () {
|
||
// Setzt den Zähler zurück.
|
||
count = 0;
|
||
|
||
clickCount.textContent = count;
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 6. LIVE-SUCHE
|
||
// ==================================
|
||
|
||
const searchInput = document.getElementById("searchInput");
|
||
const peopleList = document.getElementById("peopleList");
|
||
const searchMessage = document.getElementById("searchMessage");
|
||
|
||
searchInput.addEventListener("input", function () {
|
||
// Macht den Suchtext unabhängig von Groß- und Kleinschreibung.
|
||
const searchTerm = searchInput.value.toLowerCase().trim();
|
||
|
||
// Holt alle li-Elemente aus der Liste.
|
||
const people = peopleList.querySelectorAll("li");
|
||
|
||
let visibleCount = 0;
|
||
|
||
// Geht alle Personen nacheinander durch.
|
||
people.forEach(function (person) {
|
||
const personName = person.textContent.toLowerCase();
|
||
|
||
// Prüft, ob der Suchtext enthalten ist.
|
||
if (personName.includes(searchTerm)) {
|
||
person.style.display = "flex";
|
||
visibleCount++;
|
||
} else {
|
||
person.style.display = "none";
|
||
}
|
||
});
|
||
|
||
// Zeigt eine Meldung an, wenn es keine Treffer gibt.
|
||
if (visibleCount === 0) {
|
||
searchMessage.textContent = "Keine Ergebnisse gefunden.";
|
||
} else {
|
||
searchMessage.textContent =
|
||
visibleCount + " Ergebnis(se) gefunden.";
|
||
}
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 7. AUFGABEN HINZUFÜGEN
|
||
// ==================================
|
||
|
||
const taskInput = document.getElementById("taskInput");
|
||
const addTaskButton = document.getElementById("addTaskButton");
|
||
const taskList = document.getElementById("taskList");
|
||
|
||
function addTask() {
|
||
// Entfernt unnötige Leerzeichen am Anfang und Ende.
|
||
const taskText = taskInput.value.trim();
|
||
|
||
// Prüft, ob überhaupt Text eingegeben wurde.
|
||
if (taskText === "") {
|
||
showToast("Bitte eine Aufgabe eingeben.", "error");
|
||
return;
|
||
}
|
||
|
||
// Erstellt die benötigten HTML-Elemente.
|
||
const listItem = document.createElement("li");
|
||
const taskLeft = document.createElement("div");
|
||
const checkbox = document.createElement("input");
|
||
const textSpan = document.createElement("span");
|
||
const deleteButton = document.createElement("button");
|
||
|
||
// Setzt die Eigenschaften der Elemente.
|
||
taskLeft.classList.add("task-left");
|
||
|
||
checkbox.type = "checkbox";
|
||
|
||
textSpan.classList.add("task-text");
|
||
textSpan.textContent = taskText;
|
||
|
||
deleteButton.textContent = "Löschen";
|
||
deleteButton.classList.add("delete-task");
|
||
|
||
// Fügt die Elemente zusammen.
|
||
taskLeft.appendChild(checkbox);
|
||
taskLeft.appendChild(textSpan);
|
||
|
||
listItem.appendChild(taskLeft);
|
||
listItem.appendChild(deleteButton);
|
||
|
||
// Fügt die neue Aufgabe in die Liste ein.
|
||
taskList.appendChild(listItem);
|
||
|
||
// Löscht den Text aus dem Eingabefeld.
|
||
taskInput.value = "";
|
||
|
||
showToast("Aufgabe hinzugefügt.");
|
||
}
|
||
|
||
addTaskButton.addEventListener("click", addTask);
|
||
|
||
// Erlaubt das Hinzufügen mit der Enter-Taste.
|
||
taskInput.addEventListener("keydown", function (event) {
|
||
if (event.key === "Enter") {
|
||
addTask();
|
||
}
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 8. AUFGABEN ABHAKEN UND LÖSCHEN
|
||
// ==================================
|
||
|
||
// Event Delegation:
|
||
// Ein Listener behandelt Klicks innerhalb der gesamten Liste.
|
||
|
||
taskList.addEventListener("change", function (event) {
|
||
// Prüft, ob eine Checkbox geändert wurde.
|
||
if (event.target.type === "checkbox") {
|
||
const listItem = event.target.closest("li");
|
||
|
||
if (listItem) {
|
||
listItem.classList.toggle(
|
||
"completed",
|
||
event.target.checked
|
||
);
|
||
}
|
||
}
|
||
});
|
||
|
||
taskList.addEventListener("click", function (event) {
|
||
// Prüft, ob auf einen Löschen-Button geklickt wurde.
|
||
if (event.target.classList.contains("delete-task")) {
|
||
const listItem = event.target.closest("li");
|
||
|
||
if (listItem) {
|
||
listItem.remove();
|
||
showToast("Aufgabe gelöscht.");
|
||
}
|
||
}
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 9. TABS WECHSELN
|
||
// ==================================
|
||
|
||
const tabButtons = document.querySelectorAll(".tab-button");
|
||
const tabPanels = document.querySelectorAll(".tab-panel");
|
||
|
||
tabButtons.forEach(function (button) {
|
||
button.addEventListener("click", function () {
|
||
// Entfernt active von allen Buttons.
|
||
tabButtons.forEach(function (item) {
|
||
item.classList.remove("active");
|
||
});
|
||
|
||
// Versteckt alle Inhaltsbereiche.
|
||
tabPanels.forEach(function (panel) {
|
||
panel.classList.remove("active");
|
||
});
|
||
|
||
// Aktiviert den angeklickten Button.
|
||
button.classList.add("active");
|
||
|
||
// Liest die ID des zugehörigen Inhaltsbereichs.
|
||
const targetId = button.dataset.tab;
|
||
|
||
// Zeigt den passenden Bereich an.
|
||
document.getElementById(targetId).classList.add("active");
|
||
});
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 10. MODAL-FENSTER ÖFFNEN / SCHLIESSEN
|
||
// ==================================
|
||
|
||
const infoModal = document.getElementById("infoModal");
|
||
const openModalButton = document.getElementById("openModalButton");
|
||
const closeModalButton = document.getElementById("closeModalButton");
|
||
|
||
openModalButton.addEventListener("click", function () {
|
||
infoModal.classList.add("open");
|
||
});
|
||
|
||
closeModalButton.addEventListener("click", function () {
|
||
infoModal.classList.remove("open");
|
||
});
|
||
|
||
// Schließt das Modal, wenn außerhalb des Fensters geklickt wird.
|
||
infoModal.addEventListener("click", function (event) {
|
||
if (event.target === infoModal) {
|
||
infoModal.classList.remove("open");
|
||
}
|
||
});
|
||
|
||
// Schließt das Modal auch mit der Escape-Taste.
|
||
document.addEventListener("keydown", function (event) {
|
||
if (event.key === "Escape") {
|
||
infoModal.classList.remove("open");
|
||
}
|
||
});
|
||
|
||
|
||
// ==================================
|
||
// 11. CODE-REFERENZ
|
||
// ==================================
|
||
|
||
const codeExamples = {
|
||
event: `// Event Listener
|
||
const button = document.querySelector("#meinButton");
|
||
|
||
button.addEventListener("click", function () {
|
||
console.log("Button wurde geklickt!");
|
||
});`,
|
||
|
||
condition: `// if / else
|
||
const alter = 18;
|
||
|
||
if (alter >= 18) {
|
||
console.log("Volljährig");
|
||
} else {
|
||
console.log("Nicht volljährig");
|
||
}`,
|
||
|
||
loop: `// Schleife
|
||
const namen = ["Anna", "Max", "Lisa"];
|
||
|
||
namen.forEach(function (name) {
|
||
console.log(name);
|
||
});`,
|
||
|
||
filter: `// filter() gibt ein neues Array zurück
|
||
const zahlen = [1, 2, 3, 4, 5];
|
||
|
||
const grosseZahlen = zahlen.filter(function (zahl) {
|
||
return zahl > 3;
|
||
});
|
||
|
||
console.log(grosseZahlen); // [4, 5]`,
|
||
|
||
element: `// Neues Element erstellen
|
||
const neuesElement = document.createElement("p");
|
||
|
||
neuesElement.textContent = "Hallo Welt!";
|
||
|
||
document.body.appendChild(neuesElement);`,
|
||
|
||
class: `// CSS-Klasse hinzufügen oder entfernen
|
||
const box = document.querySelector(".box");
|
||
|
||
box.classList.add("aktiv");
|
||
box.classList.remove("aktiv");
|
||
box.classList.toggle("aktiv");`,
|
||
|
||
form: `// Formular überprüfen
|
||
const formular = document.querySelector("#formular");
|
||
|
||
formular.addEventListener("submit", function (event) {
|
||
event.preventDefault();
|
||
|
||
const name = document.querySelector("#name").value;
|
||
|
||
if (name.trim() === "") {
|
||
console.log("Bitte Namen eingeben");
|
||
} else {
|
||
console.log("Hallo " + name);
|
||
}
|
||
});`
|
||
};
|
||
|
||
const codeSelect = document.getElementById("codeSelect");
|
||
const codeDisplay = document.getElementById("codeDisplay");
|
||
const copyCodeButton = document.getElementById("copyCodeButton");
|
||
const copyMessage = document.getElementById("copyMessage");
|
||
|
||
function displayCode() {
|
||
// Holt das ausgewählte Beispiel aus dem Objekt.
|
||
const selectedCode = codeSelect.value;
|
||
|
||
// Zeigt den passenden Code an.
|
||
codeDisplay.textContent = codeExamples[selectedCode];
|
||
|
||
copyMessage.textContent = "";
|
||
}
|
||
|
||
codeSelect.addEventListener("change", displayCode);
|
||
|
||
// Kopiert das ausgewählte Beispiel in die Zwischenablage.
|
||
copyCodeButton.addEventListener("click", async function () {
|
||
try {
|
||
await navigator.clipboard.writeText(codeDisplay.textContent);
|
||
|
||
copyMessage.textContent = "Code wurde kopiert!";
|
||
copyMessage.className = "message success-text";
|
||
|
||
showToast("Code kopiert.");
|
||
} catch (error) {
|
||
// Fallback, falls die Zwischenablage nicht verfügbar ist.
|
||
copyMessage.textContent =
|
||
"Kopieren nicht möglich. Bitte den Code markieren.";
|
||
|
||
copyMessage.className = "message error-text";
|
||
}
|
||
});
|
||
|
||
// Zeigt beim Start das erste Codebeispiel an.
|
||
displayCode();
|
||
|
||
|
||
// ==================================
|
||
// 12. STARTMELDUNG
|
||
// ==================================
|
||
|
||
console.log("Die Website wurde erfolgreich geladen.");
|
||
</script>
|
||
|
||
</body>
|
||
</html>
|