Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/webroot/rsrc/js/phuix/PHUIXFormationColumnView.js
12241 views
1
/**
2
* @provides phuix-formation-column-view
3
* @requires javelin-install
4
* javelin-dom
5
*/
6
7
JX.install('PHUIXFormationColumnView', {
8
9
construct: function(node) {
10
this._node = node;
11
},
12
13
properties: {
14
isRightAligned: false,
15
isVisible: true,
16
expanderNode: null,
17
resizerItem: null,
18
resizerControl: null,
19
width: null,
20
widthSettingKey: null,
21
visibleSettingKey: null,
22
minimumWidth: null,
23
maximumWidth: null,
24
flank: null
25
},
26
27
members: {
28
_node: null,
29
_resizingWidth: null,
30
_resizingBarPosition: null,
31
_dragging: null,
32
33
start: function() {
34
var onshow = JX.bind(this, this._setVisibility, true);
35
var onhide = JX.bind(this, this._setVisibility, false);
36
37
JX.DOM.listen(this._node, 'click', 'phui-flank-header-hide', onhide);
38
39
var expander = this.getExpanderNode();
40
if (expander) {
41
JX.DOM.listen(expander, 'click', null, onshow);
42
}
43
44
var resizer = this.getResizerItem();
45
if (resizer) {
46
var ondown = JX.bind(this, this._onresizestart);
47
JX.DOM.listen(resizer, 'mousedown', null, ondown);
48
49
var onmove = JX.bind(this, this._onresizemove);
50
JX.Stratcom.listen('mousemove', null, onmove);
51
52
var onup = JX.bind(this, this._onresizeend);
53
JX.Stratcom.listen('mouseup', null, onup);
54
}
55
56
this.repaint();
57
},
58
59
_onresizestart: function(e) {
60
if (!e.isNormalMouseEvent()) {
61
return;
62
}
63
64
this._dragging = JX.$V(e);
65
this._resizingWidth = this.getWidth();
66
this._resizingBarPosition = JX.$V(this.getResizerControl());
67
68
// Show the "col-resize" cursor on the whole document while we're
69
// dragging, since the mouse will slip off the actual bar fairly often
70
// and we don't want it to flicker.
71
JX.DOM.alterClass(document.body, 'jx-drag-col', true);
72
73
e.kill();
74
},
75
76
_onresizemove: function(e) {
77
if (!this._dragging) {
78
return;
79
}
80
81
var dx = (JX.$V(e).x - this._dragging.x);
82
83
var width;
84
if (this.getIsRightAligned()) {
85
width = this.getWidth() - dx;
86
} else {
87
width = this.getWidth() + dx;
88
}
89
90
var min_width = this.getMinimumWidth();
91
if (min_width) {
92
width = Math.max(width, min_width);
93
}
94
95
var max_width = this.getMaximumWidth();
96
if (max_width) {
97
width = Math.min(width, max_width);
98
}
99
100
this._resizingWidth = width;
101
102
this._node.style.width = this._resizingWidth + 'px';
103
104
var adjust_x = (this._resizingWidth - this.getWidth());
105
if (this.getIsRightAligned()) {
106
adjust_x = -adjust_x;
107
}
108
109
this.getResizerControl().style.left =
110
(this._resizingBarPosition.x + adjust_x) + 'px';
111
112
var flank = this.getFlank();
113
if (flank) {
114
flank
115
.setWidth(this._resizingWidth)
116
.repaint();
117
}
118
},
119
120
_onresizeend: function(e) {
121
if (!this._dragging) {
122
return;
123
}
124
125
this.setWidth(this._resizingWidth);
126
127
JX.DOM.alterClass(document.body, 'jx-drag-col', false);
128
this._dragging = null;
129
130
var width_key = this.getWidthSettingKey();
131
if (width_key) {
132
this._adjustSetting(width_key, this.getWidth());
133
}
134
},
135
136
_setVisibility: function(visible, e) {
137
e.kill();
138
this.setVisibility(visible);
139
},
140
141
toggleVisibility: function() {
142
return this.setVisibility(!this.getIsVisible());
143
},
144
145
setVisibility: function(visible) {
146
this.setIsVisible(visible);
147
this.repaint();
148
149
var visible_key = this.getVisibleSettingKey();
150
if (visible_key) {
151
this._adjustSetting(visible_key, visible ? 1 : 0);
152
}
153
154
return this;
155
},
156
157
_adjustSetting: function(key, value) {
158
new JX.Request('/settings/adjust/', JX.bag)
159
.setData(
160
{
161
key: key,
162
value: value
163
})
164
.send();
165
},
166
167
repaint: function() {
168
var resizer = this.getResizerItem();
169
var expander = this.getExpanderNode();
170
171
if (this.getIsVisible()) {
172
JX.DOM.show(this._node);
173
if (resizer) {
174
JX.DOM.show(resizer);
175
}
176
if (expander) {
177
JX.DOM.hide(expander);
178
}
179
} else {
180
JX.DOM.hide(this._node);
181
if (resizer) {
182
JX.DOM.hide(resizer);
183
}
184
if (expander) {
185
JX.DOM.show(expander);
186
}
187
}
188
189
if (this.getFlank()) {
190
this.getFlank().repaint();
191
}
192
193
},
194
195
196
}
197
198
});
199
200