-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
190 lines (167 loc) · 5.46 KB
/
index.html
File metadata and controls
190 lines (167 loc) · 5.46 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC&display=swap" rel="stylesheet">
<title>Stack Visualiser</title>
<style>
:root {
--stack-border-style: 2.5px solid black;
--stack-border-radius: .5em;
--item-border-style: 2px solid black;
}
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
font-family: Noto Sans TC, sans-serif;
}
main {
height: 100%;
padding: 50px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
.container {
overflow-y: auto;
}
.stack {
display: flex;
flex-direction: column;
justify-content: flex-end;
margin: auto;
min-height: 100%;
max-width: 600px;
border: var(--stack-border-style);
border-radius: 0 0 var(--stack-border-radius) var(--stack-border-radius);
}
:not(.reversed).stack {
border-top: none;
}
.reversed.stack {
flex-direction: column-reverse;
border-radius: var(--stack-border-radius) var(--stack-border-radius) 0 0;
border-bottom: none;
}
.stack .item {
padding: 10px 30px;
width: 100%;
text-align: center;
}
:not(.reversed).stack .item {
border-top: var(--item-border-style);
}
.reversed.stack .item {
border-bottom: var(--item-border-style);
}
.control {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.control > :not(:first-child) {
margin-top: 10px;
}
.control .field :not(:first-child) {
margin-left: 5px;
}
.control .field input {
margin: 0;
}
button {
font-family : inherit;
font-size: .75em;
}
@media screen and (max-width: 640px) {
main {
grid-template-columns: 1fr;
grid-template-rows: 1fr min-content;
padding: 25px;
}
.control {
flex-wrap: wrap;
}
.control .field :not(:first-child) {
margin-left: 5px;
}
}
@media screen and (max-width: 320px) {
main {
padding: 15px;
}
}
</style>
</head>
<body>
<main>
<div class="container">
<div id="stack" class="stack"></div>
</div>
<div class="control">
<div class="field">
<input id="reverse" name="reverse" type="checkbox" autocomplete="off">
<label for="reverse">Reverse</label>
</div>
<div class="field">
<input id="input" name="input" type="text" placeholder="content..." autocomplete="off" autofocus spellcheck="false">
<button id="add">+</button>
<button id="pop">pop</button>
<button id="empty">empty</button>
</div>
<a href="https://github.com/stoneapptech/stack-visualiser">GitHub</a>
</div>
</main>
<script>
const dqs = (selector, ctx=document) => ctx.querySelector(selector);
HTMLElement.prototype.on = function(type, callback, options={}) {
this.addEventListener(type, callback, options);
return this;
}
function createElement(tagName, content="", classList=[], props={}) {
let el = document.createElement(tagName);
if (content) el.innerText = content;
classList.forEach(name => el.classList.add(name));
Object.entries(props).forEach(([key, value]) => el[key] = value);
return el;
}
function push() {
if (dqs("#input").value == "") return;
let el = createElement("div", dqs("#input").value, ["item"], { contentEditable: true, spellcheck: false });
dqs("#stack").insertAdjacentElement("afterbegin", el);
}
function pop() {
let stack = dqs("#stack");
if (!stack.children.length) return;
stack.removeChild(stack.children[0]);
}
function empty() {
dqs("#stack").innerHTML = "";
}
function reverseLayout(mode) {
dqs("#stack").classList.toggle("reversed", mode);
}
dqs("#add").on("click", push);
dqs("#input").on("keydown", (ev) => {
if (ev.key == "Enter") push();
});
dqs("#pop").on("click", pop);
window.addEventListener("keydown", (ev) => {
if (ev.key == "Escape") pop();
});
dqs("#empty").on("click", empty);
dqs("#reverse").on("change", (ev) => {
reverseLayout(ev.target.checked);
});
</script>
</body>
</html>