forked from jiggzson/nerdamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
157 lines (151 loc) · 4.86 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
<!DOCTYPE html>
<html>
<head>
<title>Nerdamer Tree Visualizer</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./nerdamer.core.js"></script>
<style>
/* source: https://codepen.io/philippkuehn/pen/QbrOaN */
body {
font-family: sans-serif;
font-size: 15px;
}
.tree ul {
position: relative;
padding: 1em 0;
white-space: nowrap;
margin: 0 auto;
text-align: center;
}
.tree ul::after {
content: '';
display: table;
clear: both;
}
.tree li {
display: inline-block;
vertical-align: top;
text-align: center;
list-style-type: none;
position: relative;
padding: 1em .5em 0 .5em;
}
.tree li::before, .tree li::after {
content: '';
position: absolute;
top: 0;
right: 50%;
border-top: 1px solid #ABABAB;
width: 50%;
height: 1em;
}
.tree li::after {
right: auto;
left: 50%;
border-left: 1px solid #ABABAB;
}
.tree li:only-child::after, .tree li:only-child::before {
display: none;
}
.tree li:only-child {
padding-top: 0;
}
.tree li:first-child::before, .tree li:last-child::after {
border: 0 none;
}
.tree li:last-child::before {
border-right: 1px solid #ABABAB;
border-radius: 0 5px 0 0;
}
.tree li:first-child::after {
border-radius: 5px 0 0 0;
}
.tree ul ul::before {
content: '';
position: absolute;
top: 0;
left: 50%;
border-left: 1px solid #ABABAB;
width: 0;
height: 1em;
}
.tree li div {
border: 1px solid #ABABAB;
padding: .5em .75em;
text-decoration: none;
display: inline-block;
border-radius: 5px;
color: #333;
position: relative;
top: 1px;
}
.tree li div:hover,
.tree li div:hover + ul li div {
background: #90C4F4;
color: #fff;
border: 1px solid #ABABAB;
}
.tree li div:hover + ul li::after,
.tree li div:hover + ul li::before,
.tree li div:hover + ul::before,
.tree li div:hover + ul ul::before {
border-color: #90C4F4;
}
.tree div span {
display: inline-block;
min-width: 30px;
}
.operator {
background: #ECF7FC;
}
.function {
background: #05346A;
color: #FFF !important;
}
#input {
border: 2px solid #ABABAB;
border-radius: 3px;
padding: 5px;
color: #707070;
font-size: 18px;
width: 80%;
margin-bottom: 4px;
}
#generate {
padding: 0;
border: none;
font: inherit;
color: inherit;
cursor: pointer;
background: #CCC;
padding: 7px;
vertical-align: top;
font-size: 18px;
color: #707070;
border-radius: 3px;
margin-left: 2px;
</style>
</head>
<body>
<input type="text" id="input" onKeyPress="keypress(event)"><button id="generate" onclick="generate()">Generate</button>
<div id="output"></div>
<script>
var output = document.getElementById('output');
var input = document.getElementById('input');
function keypress(e) {
var code = Number(e.keyCode ? e.keyCode : e.which);
if (code === 13) { //Enter keycode
generate();
}
}
function generate() {
try {
output.innerHTML = nerdamer.htmlTree(input.value);
} catch (e) {
alert(e.message);
}
}
</script>
</body>
</html>