forked from lbovet/typson
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinteractive.html
81 lines (75 loc) · 1.89 KB
/
interactive.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
<!DOCTYPE html>
<html>
<head>
<script src="vendor/require.js"></script>
<title>Typson playground</title>
<style>
body, body * {
vertical-align: top;
}
#source {
font-family:monospace;
font-size:10pt;
display:inline-block;
width:40%;
height:600px;
tab-size:2;
}
#generate {
display:inline-block;
}
#schema {
tab-size:2;
font-family:monospace;
font-size:10pt;
white-space: pre-wrap;
display:inline-block;
width:40%;
height:600px;
border:1px solid #eee;
overflow:auto;
}
#line {
position:absolute;
top:0;
bottom:0;
height:100%;
left:0;
right:0;
width:100%;
z-index:1;
}
</style>
</head>
<body>
<textarea id="source">
interface Dimension {
/** Width in cm */
width: number;
/** Height in cm */
height: number;
/** Length in cm */
length: number;
}
</textarea>
<button id="generate">Run</button>
<div id="schema"></div>
<script>
require.config({ urlArgs: "bust=" + (new Date()).getTime() });
require(["lib/typson-schema"], function(typson) {
var srcElement = document.getElementById("source");
var tgtElement = document.getElementById("schema");
var button = document.getElementById("generate");
function generate() {
tgtElement.innerHTML = "";
var ts = srcElement.value.trim();
typson.definitions(ts).done(function(definitions) {
tgtElement.innerHTML = JSON.stringify(definitions, null, 2);
});
}
// Add click functionality
button.addEventListener('click', generate ,true);
});
</script>
</body>
</html>