-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
189 lines (179 loc) · 5.03 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Floater</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify-html.js"></script>
<link
href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700"
rel="stylesheet"
/>
<script>
window.onload = () => {
const menuEntries = Array.from(
document.querySelectorAll(".nav > .nav-entry")
);
const iframe = document.querySelector(".demo-frame");
const descTitle = document.querySelector(".desc > h1");
const desc = document.querySelector(".desc > p");
const jsCode = document.querySelector(".js-code");
const htmlCode = document.querySelector(".html-code");
let activeEntry;
menuEntries.forEach(entry =>
entry.addEventListener("click", ev => loadDemo(ev.target))
);
loadDemo(menuEntries[0]);
function loadDemo(target) {
if (activeEntry) {
activeEntry.classList.toggle("active", false);
}
target.classList.toggle("active", true);
activeEntry = target;
const name = target.dataset.demo;
iframe.src = `./demos/${name}/demo.html`;
const parser = new DOMParser();
fetch(`./demos/${name}/demo.html`)
.then(res => res.text())
.then(
txt => parser.parseFromString(txt, "text/html").body.innerHTML
)
.then(html => (htmlCode.value = html_beautify(html)));
fetch(`./demos/${name}/demo.js`)
.then(res => res.text())
.then(txt => (jsCode.value = js_beautify(txt)));
fetch(`./demos/${name}/desc.json`)
.then(res => res.json())
.then(data => {
descTitle.innerHTML = data.title;
desc.innerHTML = data.description;
});
}
};
</script>
<style>
body {
font-family: "Open Sans", sans-serif;
margin: 0;
padding: 0;
}
.demos {
position: absolute;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
display: flex;
flex-direction: row;
}
.nav {
flex: 0 0 220px;
margin-right: 8px;
}
.nav > .nav-entry {
height: 42px;
line-height: 42px;
padding: 0 16px;
cursor: pointer;
font-size: 14px;
margin-bottom: 4px;
font-weight: 600;
}
.nav > .nav-entry.active {
font-weight: 700;
/* background-color: rgba(73, 72, 82, 0.2); */
}
.logo {
margin: 24px 0 16px;
padding: 0 16px;
font-size: 20px;
color: rgb(0, 7, 73);
}
.title {
padding: 0 16px;
font-size: 14px;
line-height: 24px;
height: 24px;
color: rgba(0, 0, 0, 0.6);
text-align: right;
}
.desc {
padding: 16px;
background: #fff;
}
.desc p {
margin: 0;
padding: 0;
line-height: 24px;
font-size: 14px;
color: rgba(0, 0, 0, 0.6);
}
.desc h1 {
font-size: 24px;
margin: 0 0 16px;
}
.code {
display: flex;
flex-direction: column;
flex: 1 1;
}
textarea {
outline: none;
border: none;
background-color: transparent;
box-sizing: border-box;
padding: 16px;
resize: none;
background: rgba(0, 0, 0, 0.04);
border-radius: 4px;
}
.js-code {
flex: 1 1;
margin-bottom: 16px;
/* border-bottom: 1px solid rgba(0, 0, 0, 0.1); */
}
.html-code {
flex: 1 1;
}
.demo-preview {
flex: 1 1;
/* border-left: 1px solid rgba(0, 0, 0, 0.1); */
}
.demo-preview {
overflow: hidden;
}
.demo-frame {
height: 100%;
width: 100%;
overflow: auto;
}
</style>
</head>
<body>
<div class="demos">
<div class="nav">
<div class="logo">float.js</div>
<div class="nav-entry" data-demo="ufo">Ufo</div>
<div class="nav-entry" data-demo="dynamic-position">
Dynamic Position
</div>
</div>
<div class="code">
<div class="desc">
<h1></h1>
<p></p>
</div>
<div class="title">JavaScript</div>
<textarea readonly class="js-code"></textarea>
<div class="title">HTML</div>
<textarea readonly class="html-code"></textarea>
</div>
<div class="demo-preview">
<iframe class="demo-frame" frameborder="0"></iframe>
</div>
</div>
</body>
</html>