Repository navigation
Expand file tree
/
Copy pathsplit.js
More file actions
56 lines (43 loc) · 1.63 KB
/
Copy pathsplit.js
File metadata and controls
56 lines (43 loc) · 1.63 KB
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
const $ = window.jQuery = require('./jquery-2.2.3.min.js');
const editor = ace.edit("editor");
const widthLimit = 100;
$(document).ready(() => {
$(".split").each(function() {
var $split = $(this);
var $left = $split.prev();
var $right = $split.next();
var $parent = $split.parent();
var $grip = $split.append(`<div class="grip"></div>`);
var isDragging = false;
$grip.mousedown(function() {
isDragging = true;
event.preventDefault();
});
$(document).mousemove(function(event) {
if( isDragging ) {
var x0 = $parent.offset().left;
var x = event.pageX - x0;
var width = $parent.width();
if( x < widthLimit )
x = widthLimit;
if( x > width-widthLimit )
x = width-widthLimit;
var percent = 100 * (x / width);
var fromLeft = percent + "%";
var fromRight = (100-percent) + "%";
$left.css({"right": fromRight, "width": fromLeft});
$right.css({"left": fromLeft, "width": fromRight});
$split.css("left", fromLeft);
// Hack... not sure of a better way to do this
// (always resize editor since both the centre split
// and the sidebar split will affect it)
editor.resize();
event.preventDefault();
}
});
$(document).mouseup(function() {
isDragging = false;
event.preventDefault();
});
});
});