-
Notifications
You must be signed in to change notification settings - Fork 2
/
splitter-noclick.js
137 lines (132 loc) · 4.94 KB
/
splitter-noclick.js
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
// Generated by CoffeeScript 1.6.3
(function() {
var app;
window.computedStyle = function(e, p, g) {
g = window.getComputedStyle;
return (g ? g(e) : e.currentStyle)[p.replace(/-(\w)/gi, function(w, l) {
return l.toUpperCase();
})];
};
app = angular.module('splitter', []);
app.directive('splitter', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var $, clientXProp, domElement, drag, draggingHandler, elementHeight, elementLeft, elementRight, elementTop, elementWidth, handler, handlers, heightProp, i, jqPane, jqPanes, left, leftProp, length, maxWidthProp, minWidthProp, pane, panes, topProp, vertical, verticalClass, widthProp, _fn, _i, _ref;
panes = element.children();
length = panes.length;
if (length < 2) {
return;
}
domElement = element[0];
element.css('position', 'absolute');
$ = angular.element;
vertical = attrs.vertical;
if (vertical) {
widthProp = 'height';
heightProp = 'width';
minWidthProp = 'min-height';
maxWidthProp = 'max-height';
leftProp = 'top';
topProp = 'left';
clientXProp = 'clientY';
verticalClass = 'vertical';
} else {
widthProp = 'width';
heightProp = 'height';
minWidthProp = 'min-width';
maxWidthProp = 'max-width';
leftProp = 'left';
topProp = 'top';
clientXProp = 'clientX';
verticalClass = 'horizontal';
}
elementHeight = computedStyle(domElement, heightProp);
elementTop = computedStyle(domElement, topProp);
elementLeft = parseInt(computedStyle(domElement, leftProp));
elementWidth = parseInt(computedStyle(domElement, widthProp));
elementRight = elementLeft + elementWidth;
drag = draggingHandler = null;
jqPanes = (function() {
var _i, _results;
_results = [];
for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
_results.push($(panes[i]));
}
return _results;
})();
handlers = [];
pane = panes[length - 1];
jqPane = jqPanes[length - 1];
jqPane.css('position', 'absolute');
pane.minWidth = parseInt(computedStyle(pane, minWidthProp) || '0');
pane.width = parseInt(computedStyle(pane, widthProp) || jqPane.css(widthProp, '100px') && '100');
_fn = function(handler, pane, i) {
return handler.bind('mousedown', function(ev) {
ev.preventDefault();
drag = true;
return draggingHandler = handler;
});
};
for (i = _i = 0, _ref = length - 1; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
pane = panes[i];
jqPane = jqPanes[i];
jqPane.css('position', 'absolute');
pane.minWidth = parseInt(computedStyle(pane, minWidthProp) || '0');
pane.width = parseInt(computedStyle(pane, widthProp) || jqPane.css(widthProp, '100px') && '100');
handler = angular.element('<div class="' + verticalClass + ' split-handler" style="position:absolute;"></div>');
left = left + jqPane.width;
handler.index = i;
handler.css(leftProp, computedStyle(panes[i + 1], leftProp));
handler.css(heightProp, elementHeight);
handler.css(topProp, elementTop);
jqPane.after(handler);
handlers.push(handler);
_fn(handler, pane, i);
}
element.bind('mousemove', function(ev) {
var leftPane, leftPaneWidth, pos, pos_left, right, rightPane, right_pos;
if (!drag) {
return;
}
i = draggingHandler.index;
if (i < length - 2) {
handlers[i + 1].clicked = false;
}
leftPane = panes[i];
rightPane = panes[i + 1];
if (i === 0) {
left = elementLeft;
} else {
left = parseInt(handlers[i - 1].css(leftProp));
}
if (i === length - 2) {
right = elementRight;
} else {
right = parseInt(handlers[i + 1].css(leftProp));
}
pos = ev[clientXProp];
pos_left = pos - left;
leftPaneWidth = pos - left;
if (pos_left < leftPane.minWidth) {
return;
}
right_pos = right - pos;
if (right_pos < rightPane.minWidth) {
return;
}
jqPanes[i].css(widthProp, leftPaneWidth + 'px');
draggingHandler.css(leftProp, pos + 'px');
jqPanes[i + 1].css(leftProp, pos + 'px');
return jqPanes[i + 1].css(widthProp, right_pos + 'px');
});
return angular.element(document).bind('mouseup', function(ev) {
return drag = false;
});
}
};
});
}).call(this);
/*
//@ sourceMappingURL=splitter-noclick.map
*/