-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (105 loc) · 4.34 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
<html>
<head>
<title>ORU.js</title>
<style type="text/css">
textarea { width: 90%; display: block; height: 100px; border: 1px solid #CCC;}
.indent { margin-left: 32px; }
.jsonp-input { border: 1px solid #CCC; }
.show-off { margin: 8px;
width: 45%;
overflow: auto;
vertical-align: top;
display: inline-block; }
.orimashita { margin: 8px;
font-family: courier;
font-size: 0.85em;
height: 400px;
overflow: auto; }
#jsonp-url { width: 50%; }
#json-path-input { width: 75%; border: 1px solid teal; }
#json-path-go { width: 20%; }
.oru-property { display: block; }
.oru-key { display: inline-block; margin-right: 8px; }
.oru-value { display: inline; }
.oru-bracket-content { padding-left: 24px; }
.oru-bracket-folded { color: #888; }
.oru-finger { cursor: pointer; }
.oru-key-text { font-weight: bold; }
.oru-key-quote { color: #888; }
.oru-key-colon { color: #444; }
.oru-bracket { color: #444; }
.oru-comma { color: #444; }
.oru-value-string { color: #008; }
.oru-value-number { color: #080; }
.oru-value-boolean { color: #800; }
.oru-value-null { font-style: italic; }
.oru-value-undefined { font-style: italic; }
.oru-highlight { background-color: #DDD; }
</style>
</head>
<body>
<h1>ORU.js</h1>
<p class="indent">
First, type some JSON or fetch from URL
<input id="jsonp-url" class="jsonp-input" value="http://api.stackoverflow.com/1.0/users/268619/?jsonp=oru_cb"/>
using jsonp.
<input type="button" id="jsonp-fetch" value="fetch"/>
</p>
<textarea id="demo-json" class="indent">
{
"key": "value", "foo": 123, "key2": [ "an", "array", null ], "link": "http://www.example.com",
"gupd": { "type": "awesome", "occupants": ["kwaazi","peso"], "breath": [true, false] }
}
</textarea>
<br/>
<div class="show-off">
<h2>ORU.js</h2>
<p>ORU.js is a JavaScript library for prettily printing JSON objects as HTML.
<br/><a href="http://github.com/mjg123/oru.js">How can I...</a></p>
<p>Edit the JSON above, then: <input type="button" id="orinasai" value="regenerate"/></p>
<div id="orimashita" class="orimashita"></div>
<p>BTW, "oru" is Japanese for "folding"</p>
</div>
<div id="json-path" class="show-off">
<h2>JSONPath</h2>
<p><a href="http://goessner.net/articles/JsonPath/">(reference)</a> - This page uses Goessner's library.</p>
<input id="json-path-input" value="$.gupd.occupants[?(@.length > 4)]"/>
<input type="button" id="json-path-go" value="json path"/>
<div id="json-path-result" class="orimashita"></div>
</div>
<script type="text/javascript" src="oru.js"></script>
<script type="text/javascript" src="http://jsonpath.googlecode.com/svn/tags/jsonpath-cs-0.5.1/src/js/jsonpath.js"></script>
<script type="text/javascript">
var fetchJson = function(){
var s = document.createElement("script");
s.src = document.getElementById("jsonp-url").value;
document.getElementsByTagName('head')[0].appendChild(s);
}
var oru_cb = function(data){
document.getElementById('demo-json').value = JSON.stringify( data );
doOru();
}
var doOru = function(){
try{
var newDiv = ORU.create( JSON.parse(document.getElementById("demo-json").value) ),
res = document.getElementById('orimashita');
res.innerHTML = "";
res.appendChild(newDiv);
} catch (err) {
console.log(err);
alert("error ;(");
}
doJsonPath();
};
var doJsonPath = function(){
var res = document.getElementById('json-path-result');
res.innerHTML = "";
res.appendChild( ORU.create( jsonPath( JSON.parse(document.getElementById("demo-json").value), document.getElementById('json-path-input').value)));
};
document.getElementById('jsonp-fetch').onclick = fetchJson;
document.getElementById('orinasai').onclick = doOru;
document.getElementById('json-path-go').onclick = doJsonPath;
doOru();
</script>
</body>
</html>