From 191f6ecd8237435ed4f0a1f7f570cd17c6731862 Mon Sep 17 00:00:00 2001
From: Sascha Schulz <sschulz@dh-software.de>
Date: Di, 28 Feb 2023 14:03:30 +0100
Subject: [PATCH] fix JS basics <script> examples, add HTML parsing, splitting code in CSS and JS files and HTTP introduction
---
index.html | 188 ++++++++++++++++++++++++++++++++++++++++++-----
assets/images/osi-model.jpg | 0
assets/images/document.write.jpg | 0
3 files changed, 168 insertions(+), 20 deletions(-)
diff --git a/assets/images/document.write.jpg b/assets/images/document.write.jpg
new file mode 100644
index 0000000..95b5bf0
--- /dev/null
+++ b/assets/images/document.write.jpg
Binary files differ
diff --git a/assets/images/osi-model.jpg b/assets/images/osi-model.jpg
new file mode 100644
index 0000000..f15e38a
--- /dev/null
+++ b/assets/images/osi-model.jpg
Binary files differ
diff --git a/index.html b/index.html
index 4713b32..127ca19 100644
--- a/index.html
+++ b/index.html
@@ -498,29 +498,18 @@
</table>
</section>
<section>
- <pre>
- <code class="html" data-trim data-line-numbers>
- <script type="text/template">
- <!DOCTYPE html>
- <html lang="de">
- <head>
- <meta charset="UTF-8">
- </head>
- <body>
- <!-- code -->
- </body>
- </html>
- </script>
- </code>
- </pre>
- </section>
- <section>
<p>Code wird zwischen <code>script</code>-Tags geschrieben</p>
<pre>
<code class="html" data-trim data-line-numbers>
- <script>
- ...
- </script>
+ <!DOCTYPE html>
+ <html lang="de">
+ <head>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <script>// code</script>
+ </body>
+ </html>
</code>
</pre>
</section>
@@ -549,6 +538,165 @@
</pre>
</section>
</section>
+ <section>
+ <section>
+ <h2>Auslagern in verschiedene Dateien</h2>
+ </section>
+ <section>
+ <pre>
+ <code class="html" data-trim data-line-numbers>
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <!-- CSS -->
+ <link href="styles.css" rel="stylesheet">
+ </head>
+ <body>
+ <!-- JS -->
+ <script src="index.js"></script>
+ </body>
+ </html>
+ </code>
+ </pre>
+ </section>
+ <section>
+ <p>Parsen eines HTML-Dokuments</p>
+ <pre>
+ <code class="html" data-trim data-line-numbers="1|2|3|4|5|6|7|8|9|10">
+ <script type="text/template">
+ <!DOCTYPE html>
+ <html lang="de">
+ <head>
+ <meta charset="UTF-8">
+ <title>Coole Seite 😀</title>
+ </head>
+ <body>
+ <div>Ganz langer Text</div>
+ </body>
+ </html>
+ </script>
+ </code>
+ </pre>
+ </section>
+ <section>
+ <p>Verschiedene Varianten, JavaScript erst am Ende auszuführen</p>
+ <p>Damals mit jQuery:</p>
+ <pre>
+ <code class="html" data-trim data-line-numbers>
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <script>
+ $(document).ready((event) => {
+ const element = document.querySelector("#hello");
+ });
+ </script>
+ </head>
+ <body>
+ <div id="hello">Hello World!</div>
+ </body>
+ </html>
+ </code>
+ </pre>
+ </section>
+ <section>
+ <p><code>script</code>-Tag am Ende</p>
+ <pre>
+ <code class="html" data-trim data-line-numbers>
+ <!DOCTYPE html>
+ <html>
+ <head>
+ </head>
+ <body>
+ <div>Hello World!</div>
+ ...
+ <script src="index.js"></script>
+ </body>
+ </html>
+ </code>
+ </pre>
+ </section>
+ <section>
+ <p>Event-basiert, z.B. per DOMContentLoaded</p>
+ <pre>
+ <code class="html" data-trim data-line-numbers>
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <script>
+ document.addEventListener("DOMContentLoaded", (event) => {
+ // wird ausgeführt, sobald das Dokument geparst wurde
+ const element = document.querySelector("#hello");
+ });
+ </script>
+ </head>
+ <body>
+ <div id="hello">Hello World!</div>
+ </body>
+ </html>
+ </code>
+ </pre>
+ </section>
+ <section>
+ <p>Moderne Variante</p>
+ <pre>
+ <code class="html" data-trim data-line-numbers>
+ <script src="index.js" defer></script>
+ </code>
+ </pre>
+ </section>
+ <section>
+ <h2><code>document</code>-Operationen</h2>
+ <pre>
+ <code class="js" data-trim data-line-numbers>
+ document.open();
+ document.write("<div>Booo!</div>");
+ document.close();
+ </code>
+ </pre>
+ </section>
+ <section>
+ <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/write">
+ <img data-src="/assets/images/document.write.jpg">
+ </a>
+ </section>
+ <section>
+ <pre>
+ <code class="html" data-trim data-line-numbers>
+ <body>
+ <script>document.write("<p>Dies ist ein Text.</p>")</script>
+ <button>Dunkle Magie</button>
+ <script>
+ const button = document.querySelector("button");
+
+ button.addEventListener("click", () => {
+ document.write("Und pfutsch!");
+ });
+ </script>
+ </body>
+ </code>
+ </pre>
+ </section>
+ </section>
+ <section>
+ <section>
+ <h2>HTTP-Protokoll</h2>
+ </section>
+ <section>
+ <img data-src="/assets/images/osi-model.jpg">
+ </section>
+ <section>
+ <ul>
+ <li>Befindet sich auf den OSI-Schichten 5, 6 und 7</li>
+ <li>Basiert auf dem Anfrage-Antwort-Prinzip</li>
+ <li>Basiert auf reinem Text</li>
+ </ul>
+ </section>
+ <section>
+ <p><code>npm install http-server</code></p>
+ <p><code>npx http-server --port 3000</code></p>
+ </section>
+ </section>
</div>
</div>
--
Gitblit v1.9.3