Skip to content

Commit 6aa3a19

Browse files
committed
set expose collapse/expand symbols via css
1 parent ba82d1c commit 6aa3a19

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

jsontree.css

+23-11
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ li.jstItem {
88
padding-left: 0px;
99
list-style: none;
1010
}
11-
.jstCollapse {
12-
margin-left: -15px;
13-
position: absolute;
14-
-webkit-user-select: none;
15-
user-select: none;
16-
}
17-
18-
.jstCollapse a {
19-
text-decoration: none;
20-
color: inherit;
21-
}
2211

2312
.jstTree {
2413
font-size: 12px;
@@ -53,8 +42,31 @@ li.jstItem {
5342
}
5443

5544
.jstCollapse {
45+
margin-left: -15px;
46+
position: absolute;
47+
-webkit-user-select: none;
48+
user-select: none;
5649
text-decoration: none;
5750
color: inherit;
51+
cursor: pointer;
52+
}
53+
54+
.jstExpand {
55+
margin-left: -15px;
56+
position: absolute;
57+
-webkit-user-select: none;
58+
user-select: none;
59+
text-decoration: none;
60+
color: inherit;
61+
cursor: pointer;
62+
}
63+
64+
.jstCollapse::before {
65+
content: '-';
66+
}
67+
68+
.jstExpand::before {
69+
content: '+'
5870
}
5971

6072
.jstBracket {

jsontree.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ var JSONTree = (function() { // eslint-disable-line no-unused-vars
1717
};
1818

1919
this.click = function(elem) {
20-
var symbol = elem.innerHTML;
21-
if (symbol === '-') {
22-
var block = findNextWithClass(elem.parentElement, 'jstBracket');
20+
if (elem.nextElementSibling.className !== 'jstHiddenBlock') {
21+
var block = findNextWithClass(elem, 'jstBracket');
2322
var siblings = _nextUntil(block, block.id + '_end');
24-
_hide(elem.parentElement, siblings);
25-
elem.innerHTML = '+';
23+
_hide(elem, siblings);
24+
elem.className = 'jstExpand';
2625
} else {
27-
var block = findNextWithClass(elem.parentElement, 'jstBracket');
28-
var hiddenElements = findNextWithClass(elem.parentElement, 'jstHiddenBlock');
26+
var block = findNextWithClass(elem, 'jstBracket');
27+
var hiddenElements = findNextWithClass(elem, 'jstHiddenBlock');
2928
var children = hiddenElements.children;
3029
for (var i = children.length; i > 0; i--) {
3130
var child = children[i - 1];
3231
block.after(child);
3332
}
3433
hiddenElements.remove();
35-
elem.innerHTML = '-';
34+
elem.className = 'jstCollapse';
3635
}
3736
};
3837

@@ -98,9 +97,8 @@ var JSONTree = (function() { // eslint-disable-line no-unused-vars
9897
};
9998

10099
var _collapseElem = function() {
101-
var onClick = 'onclick="JSONTree.click(this); return false;';
102-
var a = '<a href="#" ' + onClick + '">-</a>';
103-
return '<span class="jstCollapse">' + a + '</span>';
100+
var onClick = 'onclick="JSONTree.click(this); return false;"';
101+
return '<span class="jstCollapse" ' + onClick + '></span>';
104102
};
105103

106104
var _canCollapse = function(data) {

tests/jsontree.tests.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)