Skip to content

Commit e0f30c8

Browse files
author
Justin Martin
committed
add resizable panes closes #29
1 parent aa794a3 commit e0f30c8

File tree

2 files changed

+108
-3
lines changed

2 files changed

+108
-3
lines changed

css/main.css

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,82 @@ textarea {
1414
resize: none;
1515
}
1616
.json-diff-input {
17-
width: 50%;
1817
height: 100%;
1918
box-sizing: border-box;
2019
display: inline-block;
2120
float: left;
21+
position: relative;
2222
}
2323

2424
.json-diff-input .CodeMirror {
2525
height: 100%;
2626
}
2727

28+
.json-diff-input:hover .input-buttons {
29+
opacity: 1;
30+
}
31+
32+
.json-diff-input.collapse .input-buttons {
33+
display: none;
34+
}
35+
36+
.input-buttons a:hover {
37+
opacity: .7;
38+
}
39+
40+
.json-diff-input .input-buttons {
41+
transition: opacity .2s;
42+
opacity: 0;
43+
position: absolute;
44+
right: 8px;
45+
top: 0;
46+
z-index: 4;
47+
}
48+
49+
.json-diff-input .input-buttons a {
50+
color: white;
51+
text-decoration: none;
52+
font-size: 26px;
53+
}
54+
55+
.lighttheme .json-diff-input .input-buttons a {
56+
color: #1D1F21;
57+
}
58+
59+
.json-diff-input .input-buttons a.input-split {
60+
font-size: 33px;
61+
position: relative;
62+
top: 5px;
63+
}
64+
65+
.json-diff-input {
66+
transition: width .3s;
67+
}
68+
69+
.json-diff-input.split {
70+
width: 50%;
71+
}
72+
73+
.json-diff-input.collapse {
74+
width: 0%;
75+
}
76+
77+
.json-diff-input.expand {
78+
width: 100%;
79+
}
80+
81+
.json-diff-input.split .input-split {
82+
display: none;
83+
}
84+
85+
.json-diff-input.collapse .input-collapse {
86+
display: none;
87+
}
88+
89+
.json-diff-input.expand .input-expand {
90+
display: none;
91+
}
92+
2893
#header {
2994
height: 48px;
3095
background-color: #181A1B;

index.html

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,21 @@ <h2 class="left">Online JSON Compare</h2>
5353
</div>
5454
</div>
5555
<div class="diff-inputs">
56-
<div class="json-diff-input">
56+
<div id="left-input" class="json-diff-input split">
5757
<textarea id="json-diff-left"></textarea>
58+
<span class="input-buttons">
59+
<a class="input-collapse" href="#"></a>
60+
<a class="input-split" href="#"></a>
61+
<a class="input-expand" href="#"></a>
62+
</span>
5863
</div>
59-
<div class="json-diff-input">
64+
<div id="right-input" class="json-diff-input split">
6065
<textarea id="json-diff-right"></textarea>
66+
<span class="input-buttons">
67+
<a class="input-collapse" href="#"></a>
68+
<a class="input-split" href="#"></a>
69+
<a class="input-expand" href="#"></a>
70+
</span>
6171
</div>
6272
</div>
6373
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
@@ -104,6 +114,8 @@ <h2 class="left">Online JSON Compare</h2>
104114
});
105115

106116
$('#download-diff-button').on('click', onClickDownloadDiff);
117+
$('#left-input').on('click', '.input-collapse,.input-split,.input-expand', onPaneResizeLeftClick);
118+
$('#right-input').on('click', '.input-collapse,.input-split,.input-expand', onPaneResizeRightClick);
107119

108120
function toggleLightTheme() {
109121
var isLightTheme = localStorage.getItem('lighttheme');
@@ -149,6 +161,34 @@ <h2 class="left">Online JSON Compare</h2>
149161

150162
document.body.removeChild(element);
151163
}
164+
165+
function onPaneResizeLeftClick(e) {
166+
onResize(e, 'left');
167+
}
168+
169+
function onPaneResizeRightClick(e) {
170+
onResize(e, 'right');
171+
}
172+
173+
function onResize(e, side) {
174+
e.preventDefault();
175+
var otherSide = side === 'left' ? 'right' : 'left';
176+
var clickClass = e.currentTarget.className;
177+
$('.json-diff-input').removeClass('split');
178+
$('.json-diff-input').removeClass('expand');
179+
$('.json-diff-input').removeClass('collapse');
180+
var sideClass = 'split';
181+
var otherSideClass = 'split';
182+
if (clickClass === 'input-collapse') {
183+
sideClass = 'collapse';
184+
otherSideClass = 'expand';
185+
} else if (clickClass === 'input-expand') {
186+
sideClass = 'expand';
187+
otherSideClass = 'collapse';
188+
}
189+
$('#' + side + '-input').addClass(sideClass);
190+
$('#' + otherSide + '-input').addClass(otherSideClass);
191+
}
152192
</script>
153193
</body>
154194
</html>

0 commit comments

Comments
 (0)