blob: 080c07d849c0c6b8cea59861173487a88ac6598f (
plain)
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
|
<!DOCTYPE html>
<!--
vim: shiftwidth=4 tabstop=4 noexpandtab
-->
<html>
<head>
<title>libweb</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/xengineering.css" type="text/css">
</head>
<body>
<nav>
<button id="menu-button" onclick=toggleMenu()>MENU</button>
<a class="menu-anchor" href="https://xengineering.eu">xengineering.eu</a>
</nav>
<main>
<h1>libweb</h1>
<p>A repository with reusable components for web development.</p>
<p>This is a link to <a href="https://example.com">example.com</a>.</p>
<p>Have a look at this beautiful code:</p>
<pre><code>#!/usr/bin/python3
print("This is just some example code!")
</code></pre>
<p>Sometimes it is quite nice to put things into cards:</p>
<div class="card">
<h3>This is a Card</h3>
<p>Cards are very good.</p>
</div>
<p>It is also possible to put cards into an anchor tag:</p>
<a href="https://xengineering.eu">
<div class="card">
<h3>This is a Card inside an Anchor</h3>
<p>It is a link!</p>
</div>
</a>
</main>
<script>
// define menu state
const MenuState = {
Desktop: "Desktop",
MobileCollapsed: "MobileCollapsed",
MobileExpanded: "MobileExpanded"
}
var state;
// init menu state and add mediaChange handler
var isMobile = window.matchMedia("(max-width: 767px)");
mediaChange(isMobile);
isMobile.addListener(mediaChange)
function mediaChange(isMobile) {
if (isMobile.matches) {
state = MenuState.MobileCollapsed;
handleState(state);
} else {
state = MenuState.Desktop;
handleState(state);
}
}
function toggleMenu() {
switch (state) {
case MenuState.MobileCollapsed:
state = MenuState.MobileExpanded;
handleState(state);
break;
case MenuState.MobileExpanded:
state = MenuState.MobileCollapsed;
handleState(state);
break;
}
}
function handleState(state) {
console.log("State is now " + state)
var items = document.getElementsByTagName("a");
for(var i=0; i<items.length; i++) {
if (items[i].parentNode.tagName == "NAV") {
if (state == MenuState.MobileCollapsed) {
items[i].style.display = "none";
} else {
items[i].style.display = "block";
}
}
}
}
</script>
</body>
</html>
|