2006-11-09 20:47:10 +01:00
|
|
|
var SOGoDragHandlesInterface = {
|
2007-08-17 04:19:06 +02:00
|
|
|
leftMargin: 180,
|
|
|
|
topMargin: 120,
|
2006-11-09 20:47:10 +01:00
|
|
|
dhType: null,
|
|
|
|
origX: -1,
|
|
|
|
origLeft: -1,
|
|
|
|
origRight: -1,
|
|
|
|
origY: -1,
|
|
|
|
origUpper: -1,
|
|
|
|
origLower: -1,
|
|
|
|
delta: -1,
|
|
|
|
leftBlock: null,
|
|
|
|
rightBlock: null,
|
|
|
|
upperBlock: null,
|
|
|
|
lowerBlock: null,
|
2007-08-15 21:51:16 +02:00
|
|
|
startHandleDraggingBound: null,
|
|
|
|
stopHandleDraggingBound: null,
|
|
|
|
moveBound: null,
|
2006-11-09 20:47:10 +01:00
|
|
|
bind: function () {
|
2007-05-25 17:40:05 +02:00
|
|
|
this.startHandleDraggingBound = this.startHandleDragging.bindAsEventListener(this);
|
|
|
|
Event.observe(this, "mousedown", this.startHandleDraggingBound, false);
|
2006-11-09 20:47:10 +01:00
|
|
|
},
|
|
|
|
_determineType: function () {
|
|
|
|
if (this.leftBlock && this.rightBlock)
|
|
|
|
this.dhType = 'horizontal';
|
|
|
|
else if (this.upperBlock && this.lowerBlock)
|
|
|
|
this.dhType = 'vertical';
|
|
|
|
},
|
|
|
|
startHandleDragging: function (event) {
|
|
|
|
if (!this.dhType)
|
|
|
|
this._determineType();
|
2007-08-15 21:51:16 +02:00
|
|
|
var targ = getTarget(event);
|
2007-05-09 23:27:55 +02:00
|
|
|
if (targ.nodeType == 1) {
|
2006-11-09 20:47:10 +01:00
|
|
|
if (this.dhType == 'horizontal') {
|
|
|
|
this.origX = this.offsetLeft;
|
|
|
|
this.origLeft = this.leftBlock.offsetWidth;
|
2007-08-15 21:51:16 +02:00
|
|
|
delta = 0;
|
2006-11-09 20:47:10 +01:00
|
|
|
this.origRight = this.rightBlock.offsetLeft - 5;
|
2007-06-12 20:20:16 +02:00
|
|
|
document.body.setStyle({ cursor: "e-resize" });
|
2006-11-09 20:47:10 +01:00
|
|
|
} else if (this.dhType == 'vertical') {
|
|
|
|
this.origY = this.offsetTop;
|
|
|
|
this.origUpper = this.upperBlock.offsetHeight;
|
2007-08-15 21:51:16 +02:00
|
|
|
var pointY = Event.pointerY(event);
|
2007-08-17 04:19:06 +02:00
|
|
|
if (pointY <= this.topMargin) delta = this.topMargin;
|
2007-08-15 21:51:16 +02:00
|
|
|
else delta = pointY - this.offsetTop - 5;
|
2006-11-09 20:47:10 +01:00
|
|
|
this.origLower = this.lowerBlock.offsetTop - 5;
|
2007-06-12 20:20:16 +02:00
|
|
|
document.body.setStyle({ cursor: "n-resize" });
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
2007-05-25 17:40:05 +02:00
|
|
|
this.stopHandleDraggingBound = this.stopHandleDragging.bindAsEventListener(this);
|
|
|
|
Event.observe(document.body, "mouseup", this.stopHandleDraggingBound, true);
|
|
|
|
this.moveBound = this.move.bindAsEventListener(this);
|
|
|
|
Event.observe(document.body, "mousemove", this.moveBound, true);
|
2006-11-09 20:47:10 +01:00
|
|
|
this.move(event);
|
|
|
|
event.cancelBubble = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
stopHandleDragging: function (event) {
|
|
|
|
if (!this.dhType)
|
|
|
|
this._determineType();
|
|
|
|
if (this.dhType == 'horizontal') {
|
2007-08-15 21:51:16 +02:00
|
|
|
var pointerX = Event.pointerX(event);
|
2007-08-17 04:19:06 +02:00
|
|
|
if (pointerX <= this.leftMargin) {
|
2008-03-25 20:59:13 +01:00
|
|
|
this.rightBlock.setStyle({ left: (this.leftMargin) + 'px' });
|
|
|
|
this.leftBlock.setStyle({ width: (this.leftMargin) + 'px' });
|
2007-08-15 21:51:16 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-03-25 20:59:13 +01:00
|
|
|
var deltaX = Math.floor(pointerX - this.origX - (this.offsetWidth / 2));
|
|
|
|
this.rightBlock.setStyle({ left: (this.origRight + deltaX) + 'px' });
|
|
|
|
this.leftBlock.setStyle({ width: (this.origLeft + deltaX) + 'px' });
|
2007-08-15 21:51:16 +02:00
|
|
|
}
|
2008-03-25 20:59:13 +01:00
|
|
|
this.saveDragHandleState(this.dhType, parseInt(this.leftBlock.getStyle("width")));
|
2008-02-04 23:22:14 +01:00
|
|
|
}
|
|
|
|
else if (this.dhType == 'vertical') {
|
2008-03-25 20:59:13 +01:00
|
|
|
var pointerY = Event.pointerY(event);
|
|
|
|
if (pointerY <= this.topMargin) {
|
|
|
|
this.lowerBlock.setStyle({ top: (this.topMargin - delta) + 'px' });
|
|
|
|
this.upperBlock.setStyle({ height: (this.topMargin - delta) + 'px' });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var deltaY = Math.floor(pointerY - this.origY - (this.offsetHeight / 2));
|
|
|
|
this.lowerBlock.setStyle({ top: (this.origLower + deltaY - delta) + 'px' });
|
|
|
|
this.upperBlock.setStyle({ height: (this.origUpper + deltaY - delta) + 'px' });
|
|
|
|
}
|
|
|
|
this.saveDragHandleState(this.dhType, parseInt(this.lowerBlock.getStyle("top")));
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
2007-05-25 17:40:05 +02:00
|
|
|
Event.stopObserving(document.body, "mouseup", this.stopHandleDraggingBound, true);
|
|
|
|
Event.stopObserving(document.body, "mousemove", this.moveBound, true);
|
2007-05-25 16:29:44 +02:00
|
|
|
|
2006-11-09 20:47:10 +01:00
|
|
|
document.body.setAttribute('style', '');
|
2007-05-25 16:29:44 +02:00
|
|
|
|
2007-08-15 21:51:16 +02:00
|
|
|
Event.stop(event);
|
2006-11-09 20:47:10 +01:00
|
|
|
},
|
|
|
|
move: function (event) {
|
|
|
|
if (!this.dhType)
|
|
|
|
this._determineType();
|
|
|
|
if (this.dhType == 'horizontal') {
|
2007-08-15 21:51:16 +02:00
|
|
|
var hX = Event.pointerX(event);
|
2006-11-09 20:47:10 +01:00
|
|
|
var width = this.offsetWidth;
|
2007-08-17 04:19:06 +02:00
|
|
|
if (hX < this.leftMargin)
|
|
|
|
hX = this.leftMargin + Math.floor(width / 2);
|
2007-08-15 21:51:16 +02:00
|
|
|
var newLeft = Math.floor(hX - (width / 2));
|
|
|
|
this.setStyle({ left: newLeft + 'px' });
|
2006-11-09 20:47:10 +01:00
|
|
|
} else if (this.dhType == 'vertical') {
|
|
|
|
var height = this.offsetHeight;
|
2007-08-15 21:51:16 +02:00
|
|
|
var hY = Event.pointerY(event);
|
2007-08-17 04:19:06 +02:00
|
|
|
if (hY < this.topMargin)
|
|
|
|
hY = this.topMargin + Math.floor(height / 2);
|
2007-08-15 21:51:16 +02:00
|
|
|
var newTop = Math.floor(hY - (height / 2)) - delta;
|
|
|
|
this.setStyle({ top: newTop + 'px' });
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
2007-08-15 21:51:16 +02:00
|
|
|
Event.stop(event);
|
2006-11-09 20:47:10 +01:00
|
|
|
},
|
|
|
|
doubleClick: function (event) {
|
|
|
|
if (!this.dhType)
|
|
|
|
this._determineType();
|
|
|
|
if (this.dhType == 'horizontal') {
|
|
|
|
var lLeft = this.leftBlock.offsetLeft;
|
|
|
|
|
|
|
|
if (this.offsetLeft > lLeft) {
|
|
|
|
var leftdelta = this.rightBlock.offsetLeft - this.offsetLeft;
|
|
|
|
|
2007-06-12 20:20:16 +02:00
|
|
|
this.setStyle({ left: lLeft + 'px' });
|
|
|
|
this.leftBlock.setStyle({ width: '0px' });
|
|
|
|
this.rightBlock.setStyle({ left: (lLeft + leftdelta) + 'px' });
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
|
|
|
} else if (this.dhType == 'vertical') {
|
|
|
|
var uTop = this.upperBlock.offsetTop;
|
|
|
|
|
|
|
|
if (this.offsetTop > uTop) {
|
|
|
|
var topdelta = this.lowerBlock.offsetTop - this.offsetTop;
|
|
|
|
|
2007-06-12 20:20:16 +02:00
|
|
|
this.setStyle({ top: uTop + 'px' });
|
|
|
|
this.upperBlock.setStyle({ width: '0px' });
|
|
|
|
this.lowerBlock.setStyle({ top: (uTop + topdelta) + 'px' });
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
|
|
|
}
|
2008-02-04 23:22:14 +01:00
|
|
|
},
|
|
|
|
saveDragHandleState: function (type, position) {
|
|
|
|
var urlstr = ApplicationBaseURL + "saveDragHandleState"
|
|
|
|
+ "?" + type + "=" + position;
|
|
|
|
triggerAjaxRequest(urlstr, this.saveDragHandleStateCallback);
|
|
|
|
},
|
|
|
|
|
|
|
|
saveDragHandleStateCallback: function (http) {
|
|
|
|
if (isHttpStatus204(http.status)) {
|
|
|
|
log ("drag handle state saved");
|
|
|
|
}
|
|
|
|
else if (http.readyState == 4) {
|
|
|
|
log ("can't save handle state");
|
|
|
|
}
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
|
|
|
};
|