-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathdemo.html
84 lines (83 loc) · 3.71 KB
/
demo.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>json格式化及高亮</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<meta name="description" content="json,格式化,高亮"/>
<meta name="keywords" content="json,格式化,高亮"/>
<script src="jsonFormater.js" type="text/javascript"></script>
<link href="jsonFormater.css" type="text/css" rel="stylesheet"/>
<link href="demo.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div class="HeadersRow">
<div id="HeaderTitle">JSON formatted and highlighted by <a targe='_blank' href="http://leo108.com/">leo108</a> core code reference <a target="_blank" href='http://tmxk.org/c/json/'>maverick studio</a></div>
<h3 id="HeaderSubTitle">JSON formatting and highlighting:</h3>
<textarea id="RawJson">[{"link": "https://www.google.com.pk", "count": [14000, 15000 ], "description": {"sensitive": false, "text": "This contains some awesome text."}, "title": "apples"} ]</textarea>
</div>
<div id="ControlsRow">
<input type="Button" value="Format Code" id='format'/>
<span id="TabSizeHolder">
Indentation
<select id="TabSize">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</span>
<input type="checkbox" id="QuoteKeys" checked='checked' />
<label for="QuoteKeys">
Quotation marks
</label>
<input type="checkbox" id="CollapsibleView" checked='checked' />
<label for="CollapsibleView">
The display control
</label>
<span id="CollapsibleViewDetail">
<a href="javascript:void(0);" id="expandAll">展开</a>
<a href="javascript:void(0);" id="collapseAll">叠起</a>
<a href="javascript:void(0);" class="expand" data-level="3">2级</a>
<a href="javascript:void(0);" class="expand" data-level="4">3级</a>
<a href="javascript:void(0);" class="expand" data-level="5">4级</a>
<a href="javascript:void(0);" class="expand" data-level="6">5级</a>
<a href="javascript:void(0);" class="expand" data-level="7">6级</a>
<a href="javascript:void(0);" class="expand" data-level="8">7级</a>
<a href="javascript:void(0);" class="expand" data-level="9">8级</a>
</span>
</div>
<div id="Canvas" class="Canvas"></div>
<script type="application/javascript">
(function () {
var format = function () {
var options = {
dom: document.getElementById('Canvas'),
isCollapsible: document.getElementById('CollapsibleView').checked,
quoteKeys: document.getElementById('QuoteKeys').checked,
tabSize: document.getElementById('TabSize').value
};
window.jf = new JsonFormatter(options);
jf.doFormat(document.getElementById('RawJson').value);
};
document.getElementById('format').addEventListener('click', function() {
format();
});
document.getElementById('expandAll').addEventListener('click', function() {
window.jf.expandAll();
});
document.getElementById('collapseAll').addEventListener('click', function() {
window.jf.collapseAll();
});
var x = document.querySelectorAll('#TabSize, #CollapsibleView, #QuoteKeys');
Array.prototype.forEach.call(x, function(el, i) {
el.addEventListener('change', function () {
format();
});
});
})();
</script>
</body>
</html>