-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
100 lines (87 loc) · 2.59 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title></title>
<link rel="stylesheet" href="../corgi/css/corgi.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.11.0/themes/prism.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/CodeFlask.js/0.2.0/codeflask.min.css" />
<script src="./dist/toguro.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.11.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/CodeFlask.js/0.1.1/codeflask.min.js"></script>
<style type="text/css" media="screen">
#left-panel {
padding-top: 20px;
background: #eee;
border-right: 2px dashed gray;
}
#schema {
height: 100vh;
width: 100%;
position: relative;
background: #eee;
}
.CodeFlask__code { padding: 0px !important }
</style>
</head>
<body>
<div class="columns -unpadded">
<div id="left-panel" class="column">
<div id="schema"></div>
</div>
<div class="column">
<div id="form-mount" style="width: 600px; margin: 70px auto"></div>
</div>
</div>
<script charset="utf-8">
var schema = {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name",
},
"age": {
"type": "integer",
"title": "Age",
},
"remember_me": {
"type": "boolean",
"title": "Remember me",
},
"favorite_color": {
"type": "string",
"title": "Color",
"enum": [
"Red",
"Blue",
"Green"
]
}
},
"required": [
"name"
]
}
var el = document.getElementById('form-mount')
var schemaEl = document.querySelector('#schema')
schemaEl.innerHTML = JSON.stringify(schema, null, 2)
var flask = new CodeFlask;
flask.run('#schema', {language: 'json'});
flask.onUpdate(function(code) {
toguro.setSchema(JSON.parse(code))
toguro.renderTo(el)
});
// business stuff
var submitHandler = function(formData) {
alert(JSON.stringify(formData, undefined, 2))
}
var toguro = new Toguro({
schema: schema,
submit: submitHandler
});
toguro.renderTo(el)
</script>
</body>
</html>