1
function DIALOG_DRAGGER(dialog) {
4
this.resizeCornerSize = 16;
5
/* If set to small, we will hide scrollbars of content window and
6
resizing will not be operable any more */
7
this.minimumWidth = 60;
8
this.minimumHeight = 15;
10
this.MouseMoveBind = this.MouseMove.bindAsEventListener( this );
11
this.MouseOutBind = this.MouseOut.bindAsEventListener( this );
12
this.MaximizeBind = this.Maximize.bindAsEventListener( this );
13
this.ResizeBind = this.Resize.bindAsEventListener( this );
14
this.MoveBind = this.Move.bindAsEventListener( this );
16
this.TrackBind = this.Track.bindAsEventListener( this );
17
this.DoneBind = this.Done.bindAsEventListener( this );
19
this.label_displayed = true;
21
this.in_resize = false;
23
this.maximized = false;
25
this.is_moved = false;
26
this.is_resized = false;
30
DIALOG_DRAGGER.prototype.Setup = function() {
31
// IE7 :) needs it to adjust widths of sub-divs
32
domSetWidth(this.dialog.node, this.dialog.node.offsetWidth);
34
// IE6 :) fixing size for iframes
35
if (this.dialog.iframe) {
36
this.SaveDimenssions();
41
Event.observe(this.dialog.maximize_node, 'click', this.MaximizeBind );
42
Event.observe(this.dialog.node, 'mousemove', this.MouseMoveBind );
43
Event.observe(this.dialog.node, 'mouseout', this.MouseOutBind );
44
Event.observe(this.dialog.node, 'mousedown', this.ResizeBind );
45
Event.observe(this.dialog.titlebar, 'mousedown', this.MoveBind );
51
DIALOG_DRAGGER.prototype.Clean = function() {
52
Event.stopObserving(this.dialog.maximize_node, 'click', this.MaximizeBind );
53
Event.stopObserving(this.dialog.node, 'mousemove', this.MouseMoveBind );
54
Event.stopObserving(this.dialog.node, 'mouseout', this.MouseOutBind );
55
Event.stopObserving(this.dialog.node, 'mousedown', this.ResizeBind );
56
Event.stopObserving(this.dialog.titlebar, 'mousedown', this.MoveBind );
59
DIALOG_DRAGGER.prototype.MouseMove = function(ev) {
60
if ((this.in_resize)||(this.in_move)) return;
62
var target = domGetEventTarget(ev);
63
if (target != this.dialog.node) {
64
this.resizeDirection = "";
65
this.dialog.node.style.cursor = "";
69
var width = this.dialog.node.offsetWidth;
70
var height = this.dialog.node.offsetHeight;
72
var offset = domGetEventLayerOffset(ev);
76
var resizeDirection = ""
77
if (yOff < this.resizeCornerSize)
78
resizeDirection += "n";
79
else if (yOff > (height - this.resizeCornerSize))
80
resizeDirection += "s";
81
if (xOff < this.resizeCornerSize)
82
resizeDirection += "w";
83
else if (xOff > (width - this.resizeCornerSize))
84
resizeDirection += "e";
86
if (resizeDirection) {
87
this.resizeDirection = resizeDirection;
88
this.dialog.node.style.cursor = resizeDirection + "-resize";
90
this.resizeDirection = "";
91
this.dialog.node.style.cursor = "";
95
DIALOG_DRAGGER.prototype.MouseOut = function(ev) {
96
/* Causes problems in Opera
97
this.dialog.node.style.cursor = "";
102
DIALOG_DRAGGER.prototype.Move = function(ev) {
103
var target = domGetEventTarget(ev);
104
if ((target != this.dialog.titlebar)&&(target != this.dialog.label)) return;
106
Event.observe(document, 'mousemove', this.TrackBind );
107
Event.observe(document, 'mouseup', this.DoneBind );
109
var node = this.dialog.node;
110
var offset = domGetEventPageOffset(ev);
111
this.xOffset = parseInt(domGetStyleProp(node, node.style.left, "left") ,10) - offset[0];
112
this.yOffset = parseInt(domGetStyleProp(node, node.style.top, "top"), 10) - offset[1];
118
DIALOG_DRAGGER.prototype.SaveDimenssions = function() {
119
var node = this.dialog.node;
120
var mnode = this.dialog.content;
122
this.oldLeft = parseInt(domGetStyleProp(node, node.style.left, "left") ,10);
123
this.oldTop = parseInt(domGetStyleProp(node, node.style.top, "top"), 10);
125
// Obtaining original window size
126
var size = domGetNodeSize(node);
127
node.style.width = size[0] + "px";
128
node.style.height = size[1] + "px";
130
var csize = domGetNodeSize(node);
131
this.corr_x = csize[0] - size[0];
132
this.corr_y = csize[1] - size[1];
135
this.oldWidth = size[0] - this.corr_x;//parseInt(domGetStyleProp(node, node.style.width, "width"), 10);
136
this.oldHeight = size[1] - this.corr_y;//parseInt(domGetStyleProp(node, node.style.height, "height"), 10);
138
node.style.width = this.oldWidth + "px";
139
node.style.height = this.oldHeight + "px";
141
// Obtaining content element size
142
size = domGetNodeSize(mnode);
144
// mnode.style.width = size[0] + "px";
145
mnode.style.height = size[1] + "px";
147
var csize = domGetNodeSize(mnode);
148
// this.corr_cx = csize[0] - size[0];
149
this.corr_cy = csize[1] - size[1];
151
// this.cWidth = size[0] - this.corr_cx;
152
this.cHeight = size[1] - this.corr_cy;
154
// mnode.style.width = this.cWidth + "px";
155
mnode.style.height = this.cHeight + "px";
158
DIALOG_DRAGGER.prototype.Resize = function(ev) {
159
var target = domGetEventTarget(ev);
160
if (target != this.dialog.node) return;
162
var node = this.dialog.node;
163
var lnode = this.dialog.titlebar;
165
Event.observe(document, 'mousemove', this.TrackBind );
166
Event.observe(document, 'mouseup', this.DoneBind );
168
this.in_resize = true;
170
// If max-height not supported set titlebar height
171
var tb = this.dialog.titlebar;
172
var mh = parseInt(domGetStyleProp(tb, tb.style.maxHeight, "max-height"),10);
173
if ((!mh)||((tb.offsetHeight - mh)>10)) {
174
domSetWidth(node, node.offsetWidth);
175
if (mh>0) domSetHeight(tb, mh);
176
else domSetHeight(tb, 21);
179
if (!this.label_width) {
180
this.label_width = this.dialog.label.offsetWidth + this.dialog.label.offsetLeft;
183
var offset = domGetEventPageOffset(ev);
184
this.xPosition = offset[0];
185
this.yPosition = offset[1];
187
this.SaveDimenssions();
189
// Obtaining titlebar size (no correction, since preciese size is not important
190
var size = domGetNodeSize(lnode);
191
size[1] += this.corr_y;
192
if ((size[1] + 10) > this.minimumHeight) this.minimumHeight = size[1] + 10;
195
DIALOG_DRAGGER.prototype.Restore = function(ev) {
196
var node = this.dialog.node;
197
var mnode = this.dialog.content;
199
node.style.left = this.oldLeft + "px";
200
node.style.top = this.oldTop + "px";
201
node.style.width = this.oldWidth + "px";
202
node.style.height = this.oldHeight + "px";
203
mnode.style.height = this.cHeight + "px";
205
cssSetClass(this.dialog.maximize_node, "maximize");
206
this.maximized = false;
209
DIALOG_DRAGGER.prototype.Maximize = function(ev) {
210
var node = this.dialog.node;
211
var mnode = this.dialog.content;
213
if (this.maximized) {
216
this.SaveDimenssions();
221
var ww = windowGetWidth();
222
var wh = windowGetHeight();
224
node.style.width = (ww - this.corr_x) + "px";
226
if ((wh - this.corr_y) > this.oldHeight) {
227
node.style.height = (wh - this.corr_y) + "px";
228
mnode.style.height = (this.cHeight + (wh - this.corr_y - this.oldHeight)) + "px";
231
cssSetClass(this.dialog.maximize_node, "restore");
232
this.maximized = true;
236
DIALOG_DRAGGER.prototype.Track = function(ev) {
237
var node = this.dialog.node;
238
var mnode = this.dialog.content;
240
if (this.in_resize) {
246
if (this.resizeDirection.charAt(0) == "n") north = true;
247
if (this.resizeDirection.charAt(0) == "s") south = true;
248
if (this.resizeDirection.charAt(0) == "e" || this.resizeDirection.charAt(1) == "e") east = true;
249
if (this.resizeDirection.charAt(0) == "w" || this.resizeDirection.charAt(1) == "w") west = true;
251
var offset = domGetEventPageOffset(ev);
252
var dx = offset[0] - this.xPosition;
253
var dy = offset[1] - this.yPosition;
258
var w = this.oldWidth + dx;
259
var h = this.oldHeight + dy;
261
if (w < this.minimumWidth) {
262
w = this.minimumWidth;
263
dx = w - this.oldWidth;
266
if (h < this.minimumHeight) {
267
h = this.minimumHeight;
268
dy = h - this.oldHeight;
272
if (w < this.label_width) {
273
if (this.label_displayed) {
274
this.dialog.titlebar.removeChild(this.dialog.label);
275
this.label_displayed = false;
278
if (!this.label_displayed) {
279
this.dialog.titlebar.appendChild(this.dialog.label);
280
this.label_displayed = true;
284
node.style.width = w + "px";
285
if (west) node.style.left = (this.oldLeft - dx) + "px";
288
if (north || south) {
289
node.style.height = h + "px";
290
if ((this.cHeight + dy) < 0) mnode.style.height = 0 + "px";
291
else mnode.style.height = (this.cHeight + dy) + "px";
293
var size = domGetNodeSize(mnode);
294
var rdy = size[1] - this.corr_cy - this.cHeight;
296
node.style.height = (this.oldHeight + rdy) + "px";
300
if (north) node.style.top = (this.oldTop - dy) + "px";
303
this.is_resized = true;
304
} else if (this.in_move) {
305
var offset = domGetEventPageOffset(ev);
306
node.style.left = (offset[0] + this.xOffset) + "px";
307
node.style.top = (offset[1] + this.yOffset) + "px";
309
this.is_moved = true;
315
DIALOG_DRAGGER.prototype.Done = function(ev) {
316
if (this.in_resize) {
317
this.in_resize = false;
321
this.in_move = false;
324
Event.stopObserving(document, 'mousemove', this.TrackBind );
325
Event.stopObserving(document, 'mouseup', this.DoneBind );