forked from sony/nmos-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_visit.cpp
109 lines (105 loc) · 2.04 KB
/
json_visit.cpp
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
#include "cpprest/json_visit.h"
namespace web
{
namespace json
{
namespace experimental
{
// sample stylesheet for the HTML generated by html_visitor
const char* html_stylesheet = R"-stylesheet-(
.json
{
font-family: monospace
}
.json .number, .json .boolean, .json .null
{
color: blue
}
.json .string
{
color: brown
}
.json .object
{
color: grey
}
.json .array
{
color: grey
}
.json ul, .json ol
{
list-style: none;
border-left: 0.5px dotted rgba(0, 128, 0, 0.25);
}
.json ul:empty, .json ol:empty
{
display: none
}
.json .name
{
color: purple
}
/* folding support */
.json .elided
{
display: none
}
.json .toggle::before
{
position: relative;
left: -0.25em;
color: green;
user-select: none;
content: '\25bc'; /* '\25be' is smaller */
}
.json .open.toggle::before
{
content: '\25ba'; /* '\25b8' is smaller */
}
/* remove toggle for browsers that don't support user-select */
_:-ms-lang(x), .json .toggle::before
{
content: ''
}
_:-ms-lang(x), .json .open.toggle::before
{
content: ''
}
/* optional gutter toggles */
.json
{
position: relative
}
.json.gutter
{
padding-left: 1.5em
}
.json.gutter .toggle::before
{
position: absolute;
left: 0;
}
)-stylesheet-";
// sample script for the HTML generated by html_visitor
const char* html_script = R"-script-(
window.onload = function() {
var json = document.getElementsByClassName('json');
for (var i = 0; i < json.length; ++i) {
json[i].onclick = function(e) {
if (!e.target.classList.contains('toggle')) return;
var normal = e.target.parentElement.querySelector(':scope > .normal');
var elided = e.target.parentElement.querySelector(':scope > .elided');
// get state
var open = getComputedStyle(normal).display == 'inline';
// toggle state
open ? e.target.classList.add('open') : e.target.classList.remove('open');
normal.style.display = open ? 'none' : 'inline';
elided.style.display = open ? 'inline' : 'none';
}
}
}
)-script-";
}
}
}