2008-08-28 16:48:45 +02:00
|
|
|
/* -*- Mode: java; tab-width: 2; c-tab-always-indent: t; indent-tabs-mode: t; c-basic-offset: 2 -*- */
|
|
|
|
|
2006-11-09 20:47:10 +01:00
|
|
|
var SOGoDragHandlesInterface = {
|
2008-08-28 16:48:45 +02:00
|
|
|
leftMargin: 180,
|
|
|
|
topMargin: 120,
|
|
|
|
dhType: null,
|
2008-09-17 23:39:36 +02:00
|
|
|
dhLimit: null,
|
2008-08-28 16:48:45 +02:00
|
|
|
origX: -1,
|
|
|
|
origLeft: -1,
|
|
|
|
origRight: -1,
|
|
|
|
origY: -1,
|
|
|
|
origUpper: -1,
|
|
|
|
origLower: -1,
|
|
|
|
delta: -1,
|
|
|
|
leftBlock: null,
|
|
|
|
rightBlock: null,
|
|
|
|
upperBlock: null,
|
|
|
|
lowerBlock: null,
|
|
|
|
startHandleDraggingBound: null,
|
|
|
|
stopHandleDraggingBound: null,
|
|
|
|
moveBound: null,
|
|
|
|
bind: function () {
|
2007-05-25 17:40:05 +02:00
|
|
|
this.startHandleDraggingBound = this.startHandleDragging.bindAsEventListener(this);
|
2008-04-15 22:12:51 +02:00
|
|
|
this.observe("mousedown", this.startHandleDraggingBound, false);
|
2006-11-09 20:47:10 +01:00
|
|
|
},
|
2008-08-28 16:48:45 +02:00
|
|
|
_determineType: function () {
|
2008-09-17 23:39:36 +02:00
|
|
|
if (this.leftBlock && this.rightBlock) {
|
2006-11-09 20:47:10 +01:00
|
|
|
this.dhType = 'horizontal';
|
2008-09-17 23:39:36 +02:00
|
|
|
this.dhLimit = window.width() - 10;
|
|
|
|
}
|
|
|
|
else if (this.upperBlock && this.lowerBlock) {
|
2006-11-09 20:47:10 +01:00
|
|
|
this.dhType = 'vertical';
|
2008-09-17 23:39:36 +02:00
|
|
|
this.dhLimit = window.height() - 10;
|
|
|
|
}
|
2006-11-09 20:47:10 +01:00
|
|
|
},
|
2008-09-17 23:39:36 +02:00
|
|
|
startHandleDragging: function (event) { log("startHandleDragging");
|
2006-11-09 20:47:10 +01:00
|
|
|
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;
|
2008-08-28 16:48:45 +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;
|
2008-08-28 16:48:45 +02:00
|
|
|
var pointY = Event.pointerY(event);
|
|
|
|
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);
|
2008-04-15 22:12:51 +02:00
|
|
|
document.body.observe("mouseup", this.stopHandleDraggingBound, true);
|
2007-05-25 17:40:05 +02:00
|
|
|
this.moveBound = this.move.bindAsEventListener(this);
|
2008-04-15 22:12:51 +02:00
|
|
|
document.body.observe("mousemove", this.moveBound, true);
|
2006-11-09 20:47:10 +01:00
|
|
|
this.move(event);
|
|
|
|
event.cancelBubble = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2008-08-28 16:48:45 +02:00
|
|
|
stopHandleDragging: function (event) {
|
2006-11-09 20:47:10 +01:00
|
|
|
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-08-28 16:48:45 +02: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-08-28 16:48:45 +02: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-08-28 16:48:45 +02: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', '');
|
2008-09-05 13:43:32 +02:00
|
|
|
document.body.setStyle({ cursor: "default" });
|
|
|
|
|
2007-08-15 21:51:16 +02:00
|
|
|
Event.stop(event);
|
2006-11-09 20:47:10 +01:00
|
|
|
},
|
2008-08-28 16:48:45 +02:00
|
|
|
move: function (event) {
|
2006-11-09 20:47:10 +01:00
|
|
|
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)
|
2008-08-28 16:48:45 +02:00
|
|
|
hX = this.leftMargin + Math.floor(width / 2);
|
2008-09-17 23:39:36 +02:00
|
|
|
else if (hX > this.dhLimit)
|
|
|
|
log ("limit");
|
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)
|
2008-08-28 16:48:45 +02:00
|
|
|
hY = this.topMargin + Math.floor(height / 2);
|
2008-09-17 23:39:36 +02:00
|
|
|
else if (hY > this.dhLimit)
|
|
|
|
log ("limit");
|
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
|
|
|
},
|
2008-08-28 16:48:45 +02:00
|
|
|
doubleClick: function (event) {
|
2006-11-09 20:47:10 +01:00
|
|
|
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
|
|
|
},
|
2008-08-28 16:48:45 +02:00
|
|
|
saveDragHandleState: function (type, position) {
|
2008-09-09 21:01:38 +02:00
|
|
|
if (!$(document.body).hasClassName("popup")) {
|
|
|
|
var urlstr = ApplicationBaseURL + "saveDragHandleState"
|
|
|
|
+ "?" + type + "=" + position;
|
|
|
|
triggerAjaxRequest(urlstr, this.saveDragHandleStateCallback);
|
|
|
|
}
|
2008-02-04 23:22:14 +01:00
|
|
|
},
|
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
saveDragHandleStateCallback: function (http) {
|
2008-02-04 23:22:14 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|