This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
forked from jsonary-js/jsonary-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
193 lines (175 loc) · 4.45 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
190
191
192
193
<!DOCTYPE HTML>
<html>
<head>
<title>JSON browser</title>
<style>
body {
background-color: #F8F8F0;
padding-bottom: 160px;
font-family: Verdana, sans-serif;
font-size: 0.9em;
}
#url-bar, #go, #edit-extras {
display: block;
position: fixed;
top: 0;
left: 60px;
right: 50px;
height: 1.5em;
margin: 0;
padding: 0;
width: 100%;
}
#url-bar {
padding-left: 0.5em;
padding-right: -0.5em;
}
#go {
top: 0px;
left: 0px;
right: auto;
width: 60px;
}
#edit-extras {
top: 0px;
right: 0px;
left: auto;
width: 50px;
}
#edit-extras-box {
position: absolute;
top: 30px;
bottom: 5px;
left: 5px;
right: 5px;
overflow: auto;
border: 3px solid black;
border-radius: 10px;
background-color: #CDE;
box-shadow: 0px 0px 50px #024;
padding: 1em;
}
#main {
position: fixed;
top: 1.5em;
left: 0;
right: 0;
bottom: 0;
overflow: auto;
margin-top: 3px;
padding: 1em;
}
td {
vertical-align: top;
}
</style>
</head>
<body class="jsonary">
<script src="super-bundle/jsonary-super-bundle.js"></script>
<input id="url-bar" value="home.json"/>
<div id="go" class="button">Go</div>
<div id="edit-extras" class="button action">extras</div>
<div id="main"></div>
<div id="edit-extras-box"></div>
<script>
var urlBar = document.getElementById('url-bar');
var goButton = document.getElementById('go');
Jsonary.baseUri = window.location.href.split('#')[0].split('?')[0].replace(/\/[^\/]*$/, '/');
var baseRegex = /^http(s)?:\/\/[^\/]+\//;
if (baseRegex.test(Jsonary.baseUri)) {
Jsonary.baseUri = Jsonary.baseUri.match(baseRegex)[0];
}
// Navigation using the URL bar
urlBar.onkeydown = function (e) {
if (e.keyCode == 13) {
navigateGo();
}
};
goButton.onclick = navigateGo;
function navigateGo() {
Jsonary.location.addHistoryPoint();
var url = urlBar.value;
navigateTo(url);
}
// Catch changes in the query/hash
var locationListener = Jsonary.location.onChange(function (location, query) {
navigateTo(query.get('/url'));
}, false);
// Follow links
Jsonary.addLinkHandler(function(link, data, request) {
Jsonary.location.addHistoryPoint();
navigateTo(link.href, request);
return true;
});
function navigateTo(url, request) {
if (!request) {
request = Jsonary.getData(url);
}
url = request.url.replace(/#$/, "");
var shortUrl = url;
var urlBase = Jsonary.baseUri;
if (url.substring(0, urlBase.length) == urlBase) {
shortUrl = url.substring(urlBase.length) || "./";
}
urlBar.value = url;
locationListener.ignore(function () {
Jsonary.location.query.set('', {url: shortUrl});
});
Jsonary.render('main', request);
}
// Extra parameter dialog
var extrasBox = document.getElementById('edit-extras-box');
var extrasButton = document.getElementById('edit-extras');
extrasBox.style.display = 'none';
extrasButton.onclick = function () {
extrasBox.style.display = {
'none': 'block',
'block': 'none'
}[extrasBox.style.display] || 'block';
};
// Extra parameter editing/insertion
var extraParams = {
headers: {}
};
try {
if (typeof localStorage !== 'undefined') {
extraParams.headers = JSON.parse(localStorage.jsonBrowserExtraHeaders);
}
} catch (e) {
// do nothing
}
Jsonary.renderValue(extrasBox, extraParams, {
"title": "Extra parameters",
"type": "object",
"properties": {
"headers": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"required": ["headers"],
"additionalProperties": false
}, function (value) {
if (typeof localStorage !== 'undefined') {
localStorage.jsonBrowserExtraHeaders = JSON.stringify(value.headers);
}
extraParams = value;
console.log(value);
});
Jsonary.beforeAjax(function (params) {
for (var key in extraParams.headers) {
var headerKey = key.toLowerCase();
params.headers[headerKey] = params.headers[headerKey] || []
if (!Array.isArray(params.headers[key])) {
params.headers[headerKey] = [params.headers[headerKey]];
}
params.headers[headerKey].push(extraParams.headers[key]);
}
});
// First render
navigateTo(Jsonary.location.query.get('/url') || urlBar.value);
</script>
</body>
</html>