forked from nathancahill/split
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
388 lines (357 loc) · 12.4 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE html>
<html lang="en">
<head>
<title>Split.js</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/styles/github.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/highlight.min.js"></script>
<style>
td {
padding: 8px 10px;
}
td:first-child {
font-family: monospace;
}
h3 {
margin-top: 100px;
}
h5 {
margin-bottom: 0;
}
hr {
margin-top: 2px;
}
.example-1 {
height: 600px;
border: 1px solid #ddd;
border-radius: 4px;
}
.example-2, .example-3, .example-4, .example-5, .example-6 {
height: 250px;
border: 1px solid #ddd;
border-radius: 4px;
}
.example-flex {
height: 200px;
border: 1px solid #ddd;
border-radius: 4px;
display: flex;
flex-direction: row;
}
.example-flex-reverse {
flex-direction: row-reverse;
}
#one, #two {
padding: 20px;
}
#one p {
padding: 0;
}
.example-4, .example-5 {
height: 400px;
}
.split p, .split-flex p {
padding: 20px;
}
.split, .split-flex {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
overflow-y: auto;
overflow-x: hidden;
}
.gutter {
background-color: #eee;
background-repeat: no-repeat;
background-position: 50%;
}
.gutter.gutter-horizontal {
background-image: url('grips/vertical.png');
cursor: ew-resize;
}
.gutter.gutter-vertical {
background-image: url('grips/horizontal.png');
cursor: ns-resize;
}
.split.split-horizontal, .gutter.gutter-horizontal {
height: 100%;
float: left;
}
</style>
</head>
<body>
<a href="https://github.com/nathancahill/Split.js"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"></a>
<div class="container">
<h3>Split.js</h3>
<div class="row example-1">
<div id="one" class="split split-horizontal">
<p>Split.js is a lightweight, unopinionated utility for creating adjustable split views or panes.</p>
<p>
No dependencies or markup required, just two or more elements with a common parent.
</p>
<p>
Views can be split horizontally or vertically, with draggable gutters inserted between every two elements.
</p>
</div>
<div id="two" class="split split-horizontal">
<h5>Documentation</h5>
<hr>
<pre><code>Split(<HTMLElement|selector[]> elements, <options> options?)</code></pre>
<table class="u-full-width">
<thead>
<tr>
<th>Options</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>sizes</td>
<td>Array of numbers</td>
<td></td>
<td>Initial sizes of each element in percents.</td>
</tr>
<tr>
<td>minSize</td>
<td>Number or array</td>
<td>100</td>
<td>Minimum size of each element.</td>
</tr>
<tr>
<td>gutterSize</td>
<td>Number</td>
<td>10</td>
<td>Gutter size in pixels.</td>
</tr>
<tr>
<td>snapOffset</td>
<td>Number</td>
<td>30</td>
<td>Snap to minimum size offset.</td>
</tr>
<tr>
<td>direction</td>
<td>String</td>
<td>'horizontal'</td>
<td>Direction to split: horizontal or vertical.</td>
</tr>
<tr>
<td>cursor</td>
<td>String</td>
<td>'grabbing'</td>
<td>Cursor to display while dragging.</td>
</tr>
<tr>
<td>onDrag</td>
<td>Function</td>
<td></td>
<td>Callback on drag.</td>
</tr>
<tr>
<td>onDragStart</td>
<td>Function</td>
<td></td>
<td>Callback on drag start.</td>
</tr>
<tr>
<td>onDragEnd</td>
<td>Function</td>
<td></td>
<td>Callback on drag end.</td>
</tr>
</tbody>
</table>
</div>
</div>
<br><br>
<div class="row">
<h5>Usage Examples</h5>
<hr>
<p>A split with two elements, starting at 25% and 75% wide with 200px minimum width.</p>
<pre><code>Split(['#one', '#two'], {
sizes: [25, 75],
minSize: 200
});</code></pre>
<div class="example-2">
<div id="three" class="split split-horizontal">
<p>#three</p>
</div>
<div id="four" class="split split-horizontal">
<p>#four</p>
</div>
</div>
<br>
<p>A split with three elements, starting with even widths with 100px, 100px and 300px minimum widths, respectively.</p>
<pre><code>Split(['#one', '#two', '#three'], {
minSize: [100, 100, 300]
});</code></pre>
<div class="example-3">
<div id="five" class="split split-horizontal">
<p>#five, minSize: 100px</p>
</div>
<div id="six" class="split split-horizontal">
<p>#six, minSize: 100px</p>
</div>
<div id="seven" class="split split-horizontal">
<p>#seven, minSize: 300px</p>
</div>
</div>
<br>
<p>A vertical split with two elements, starting with even heights.</p>
<pre><code>Split(['#eight', '#nine'], {
direction: 'vertical'
});</code></pre>
<div class="example-4">
<div id="eight" class="split split-vertical">
<p>#eight</p>
</div>
<div id="nine" class="split split-vertical">
<p>#nine</p>
</div>
</div>
<br>
<p>Nested splits, horizontal and vertical.</p>
<pre><code>Split(['#ten', '#eleven']);
Split(['#twelve', '#thirteen'], {
direction: 'vertical'
});</code></pre>
<div class="example-5">
<div id="ten" class="split split-horizontal">
<div id="twelve" class="split split-vertical">
<p>#twelve</p>
</div>
<div id="thirteen" class="split split-vertical">
<p>#thirteen</p>
</div>
</div>
<div id="eleven" class="split split-horizontal">
<p>#eleven</p>
</div>
</div>
<br><br>
<p>The actual size calculation falls back from calc() to support IE8, or can be configured to use flexbox.</p>
<pre><code>Split(['#flex-1', '#flex-2'], {
elementStyle: function (dimension, size, gutterSize) {
return { 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' }
},
gutterStyle: function (dimension, gutterSize) {
return { 'flex-basis': gutterSize + 'px' }
}
});</code></pre>
<div class="example-flex" dir="ltr">
<div id="flex-1" class="split-flex split-horizontal-flex">
<p>#flex-1</p>
</div>
<div id="flex-2" class="split-flex split-horizontal-flex">
<p>#flex-2</p>
</div>
</div>
<br><br>
<p>And with flexbox reverse:</p>
<pre><code>Split(['#flex-3', '#flex-4'], {
elementStyle: function (dimension, size, gutterSize) {
return { 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' }
},
gutterStyle: function (dimension, gutterSize) {
return { 'flex-basis': gutterSize + 'px' }
}
});</code></pre>
<div class="example-flex example-flex-reverse" dir="ltr">
<div id="flex-3" class="split-flex">
<p>#flex-3</p>
</div>
<div id="flex-4" class="split-flex">
<p>#flex-4</p>
</div>
<div id="flex-5" class="split-flex">
<p>#flex-5</p>
</div>
</div>
<br><br>
<h5>API</h5>
<hr>
<p>Use the returned instance to access two methods that control the split: <b>setSizes</b> and <b>collapse</b>, a method for getting the current sizes: <b>getSizes</b> and a method for destroying the split: <b>destroy</b>.</p>
<pre><code>var instance = Split(['#fourteen', '#fifteen', '#sixteen'], {
sizes: [50, 25, 25]
});
instance.setSizes([33.3, 33.3, 33.3]); // Set Sizes 33%
instance.collapse(0); // Collapse First
instance.collapse(1); // Collapse Second
instance.collapse(2); // Collapse Third
instance.getSizes(); // Get Sizes
instance.setSizes([50, 25, 25]); // Reset
instance.destroy(); // Destroy</code></pre>
<div class="example-6">
<div id="fourteen" class="split split-horizontal">
<p>#fourteen</p>
</div>
<div id="fifteen" class="split split-horizontal">
<p>#fifteen</p>
</div>
<div id="sixteen" class="split split-horizontal">
<p>#sixteen</p>
</div>
</div>
<br><br>
<div>
<button onclick="instance.setSizes([100 / 3, 100 / 3, 100 / 3])">Set Sizes 33%</button>
<button onclick="instance.collapse(0)">Collapse First</button>
<button onclick="instance.collapse(1)">Collapse Second</button>
<button onclick="instance.collapse(2)">Collapse Third</button>
<button onclick="console.log(instance.getSizes())">Get Sizes</button>
<button onclick="instance.setSizes([50, 25, 25])">Reset</button>
<button onclick="instance.destroy()">Destroy</button>
<button onclick="instance = Split(['#fourteen', '#fifteen', '#sixteen'], {sizes: [50, 25, 25]});">Create</button>
</div>
<br>
<p>JSFiddle style is also possible: <a href="examples/jsfiddle.html">Demo</a>.
<br>
<br><br>
</div>
</div>
</body>
<script>hljs.initHighlightingOnLoad();</script>
<script src="split.js"></script>
<script>
Split(['#one', '#two'], {
sizes: [29, 71],
minSize: 200
});
Split(['#three', '#four'], {
sizes: [25, 75],
minSize: 200
});
Split(['#five', '#six', '#seven'], {
minSize: [100, 100, 300]
});
Split(['#eight', '#nine'], {
direction: 'vertical'
});
Split(['#ten', '#eleven']);
Split(['#twelve', '#thirteen'], {
direction: 'vertical'
});
Split(['#flex-1', '#flex-2'], {
elementStyle: function (dimension, size, gutterSize) {
return { 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' }
},
gutterStyle: function (dimension, gutterSize) {
return { 'flex-basis': gutterSize + 'px' }
}
});
Split(['#flex-3', '#flex-4', '#flex-5'], {
elementStyle: function (dimension, size, gutterSize) {
return { 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' }
},
gutterStyle: function (dimension, gutterSize) {
return { 'flex-basis': gutterSize + 'px' }
}
});
var instance = Split(['#fourteen', '#fifteen', '#sixteen'], {
sizes: [50, 25, 25]
});
</script>
</html>