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,
|
2008-09-18 20:03:59 +02:00
|
|
|
topMargin: 140,
|
2008-08-28 16:48:45 +02:00
|
|
|
dhType: null,
|
2008-09-18 20:03:59 +02:00
|
|
|
dhLimit: -1,
|
2008-08-28 16:48:45 +02:00
|
|
|
origX: -1,
|
|
|
|
origLeft: -1,
|
|
|
|
origRight: -1,
|
|
|
|
origY: -1,
|
|
|
|
origUpper: -1,
|
|
|
|
origLower: -1,
|
|
|
|
delta: -1,
|
2009-03-17 20:46:46 +01:00
|
|
|
btn: null,
|
2008-08-28 16:48:45 +02:00
|
|
|
leftBlock: null,
|
|
|
|
rightBlock: null,
|
|
|
|
upperBlock: null,
|
|
|
|
lowerBlock: null,
|
|
|
|
startHandleDraggingBound: null,
|
|
|
|
stopHandleDraggingBound: null,
|
|
|
|
moveBound: null,
|
2008-09-18 20:03:59 +02:00
|
|
|
delayedSave: null,
|
2008-08-28 16:48:45 +02:00
|
|
|
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-09-18 20:03:59 +02:00
|
|
|
adjust: function () {
|
|
|
|
if (!this.dhType)
|
|
|
|
this._determineType();
|
|
|
|
if (this.dhType == 'horizontal') {
|
|
|
|
this.dhLimit = window.width() - 20;
|
|
|
|
if (parseInt(this.getStyle("left")) > this.dhLimit) {
|
|
|
|
this.setStyle({ left: this.dhLimit + "px" });
|
|
|
|
this.rightBlock.setStyle({ left: (this.dhLimit) + 'px' });
|
|
|
|
this.leftBlock.setStyle({ width: (this.dhLimit) + 'px' });
|
|
|
|
if (this.delayedSave) window.clearTimeout(this.delayedSave);
|
|
|
|
this.delayedSave = this.saveDragHandleState.delay(3, this.dhType, this.dhLimit, this.saveDragHandleStateCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.dhType == 'vertical') {
|
|
|
|
this.dhLimit = window.height() - 20 - this.upperBlock.cumulativeOffset()[1] + this.upperBlock.offsetTop;
|
|
|
|
if (parseInt(this.getStyle("top")) > this.dhLimit) {
|
|
|
|
this.setStyle({ top: this.dhLimit + 'px' });
|
|
|
|
this.lowerBlock.setStyle({ top: this.dhLimit + 'px' });
|
|
|
|
this.upperBlock.setStyle({ height: (this.dhLimit - this.upperBlock.offsetTop) + 'px' });
|
|
|
|
if (this.delayedSave) window.clearTimeout(this.delayedSave);
|
|
|
|
this.delayedSave = this.saveDragHandleState.delay(3, this.dhType, this.dhLimit, this.saveDragHandleStateCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2008-08-28 16:48:45 +02:00
|
|
|
_determineType: function () {
|
2008-09-18 20:03:59 +02:00
|
|
|
if (this.leftBlock && this.rightBlock)
|
2006-11-09 20:47:10 +01:00
|
|
|
this.dhType = 'horizontal';
|
2008-09-18 20:03:59 +02:00
|
|
|
else if (this.upperBlock && this.lowerBlock)
|
2006-11-09 20:47:10 +01:00
|
|
|
this.dhType = 'vertical';
|
|
|
|
},
|
2008-09-18 20:03:59 +02:00
|
|
|
startHandleDragging: function (event) {
|
2009-03-17 20:46:46 +01:00
|
|
|
this.btn = event.button;
|
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') {
|
2008-09-18 20:03:59 +02:00
|
|
|
this.dhLimit = window.width() - 20;
|
2006-11-09 20:47:10 +01:00
|
|
|
this.origX = this.offsetLeft;
|
|
|
|
this.origLeft = this.leftBlock.offsetWidth;
|
2008-09-18 20:03:59 +02:00
|
|
|
this.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') {
|
2008-09-18 20:03:59 +02:00
|
|
|
this.dhLimit = window.height() - 20;
|
2006-11-09 20:47:10 +01:00
|
|
|
this.origY = this.offsetTop;
|
|
|
|
this.origUpper = this.upperBlock.offsetHeight;
|
2008-08-28 16:48:45 +02:00
|
|
|
var pointY = Event.pointerY(event);
|
2009-03-17 20:46:46 +01:00
|
|
|
this.delta = pointY - this.offsetTop - 5;
|
2006-11-09 20:47:10 +01:00
|
|
|
this.origLower = this.lowerBlock.offsetTop - 5;
|
2009-03-17 20:46:46 +01: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);
|
2009-03-17 20:46:46 +01:00
|
|
|
if (Prototype.Browser.IE)
|
|
|
|
Event.observe(document.body, "mouseup", this.stopHandleDraggingBound);
|
|
|
|
else
|
|
|
|
Event.observe(window, "mouseup", this.stopHandleDraggingBound);
|
|
|
|
this.moveBound = this.move.bindAsEventListener(this);
|
|
|
|
Event.observe(document.body, "mousemove", this.moveBound);
|
2006-11-09 20:47:10 +01:00
|
|
|
this.move(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2008-09-18 20:03:59 +02:00
|
|
|
else if (pointerX >= this.dhLimit) {
|
|
|
|
this.rightBlock.setStyle({ left: (this.dhLimit) + 'px' });
|
|
|
|
this.leftBlock.setStyle({ width: (this.dhLimit) + '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);
|
2008-09-18 20:03:59 +02:00
|
|
|
var deltaY;
|
|
|
|
if (pointerY <= this.topMargin)
|
|
|
|
deltaY = Math.floor(this.topMargin - this.origY - (this.offsetHeight / 2));
|
|
|
|
else if (pointerY >= this.dhLimit)
|
|
|
|
deltaY = Math.floor(this.dhLimit - this.origY - (this.offsetHeight / 2));
|
|
|
|
else
|
|
|
|
deltaY = Math.floor(pointerY - this.origY - (this.offsetHeight / 2));
|
|
|
|
this.lowerBlock.setStyle({ top: (this.origLower + deltaY - this.delta) + 'px' });
|
|
|
|
this.upperBlock.setStyle({ height: (this.origUpper + deltaY - this.delta) + 'px' });
|
|
|
|
|
2008-08-28 16:48:45 +02:00
|
|
|
this.saveDragHandleState(this.dhType, parseInt(this.lowerBlock.getStyle("top")));
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
2009-03-17 20:46:46 +01:00
|
|
|
if (Prototype.Browser.IE)
|
|
|
|
Event.stopObserving(document.body, "mouseup", this.stopHandleDraggingBound);
|
|
|
|
else
|
|
|
|
Event.stopObserving(window, "mouseup", this.stopHandleDraggingBound);
|
|
|
|
Event.stopObserving(document.body, "mousemove", this.moveBound);
|
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;
|
2009-03-17 20:46:46 +01:00
|
|
|
if (hX < this.leftMargin)
|
2008-08-28 16:48:45 +02:00
|
|
|
hX = this.leftMargin + Math.floor(width / 2);
|
2009-03-17 20:46:46 +01:00
|
|
|
else if (hX > this.dhLimit)
|
2008-09-18 20:03:59 +02:00
|
|
|
hX = this.dhLimit + Math.floor(width / 2);
|
2009-03-17 20:46:46 +01:00
|
|
|
var newLeft = Math.floor(hX - (width / 2));
|
2007-08-15 21:51:16 +02:00
|
|
|
this.setStyle({ left: newLeft + 'px' });
|
2006-11-09 20:47:10 +01:00
|
|
|
} else if (this.dhType == 'vertical') {
|
2007-08-15 21:51:16 +02:00
|
|
|
var hY = Event.pointerY(event);
|
2008-09-18 20:03:59 +02:00
|
|
|
var height = this.offsetHeight;
|
2007-08-17 04:19:06 +02:00
|
|
|
if (hY < this.topMargin)
|
2008-09-18 20:03:59 +02:00
|
|
|
hY = this.topMargin;
|
2009-03-17 20:46:46 +01:00
|
|
|
else if (hY > this.dhLimit)
|
2008-09-18 20:03:59 +02:00
|
|
|
hY = this.dhLimit;
|
2009-03-17 20:46:46 +01:00
|
|
|
|
2008-09-18 20:03:59 +02:00
|
|
|
var newTop = Math.floor(hY - (height / 2)) - this.delta;
|
2007-08-15 21:51:16 +02:00
|
|
|
this.setStyle({ top: newTop + 'px' });
|
2006-11-09 20:47:10 +01:00
|
|
|
}
|
2007-08-15 21:51:16 +02:00
|
|
|
Event.stop(event);
|
2009-03-17 20:46:46 +01:00
|
|
|
if (Prototype.Browser.IE && event.button != this.btn)
|
|
|
|
this.stopHandleDragging(event);
|
|
|
|
},
|
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-09-18 20:03:59 +02:00
|
|
|
saveDragHandleState: function (type, position, fcn) {
|
2008-09-09 21:01:38 +02:00
|
|
|
if (!$(document.body).hasClassName("popup")) {
|
|
|
|
var urlstr = ApplicationBaseURL + "saveDragHandleState"
|
|
|
|
+ "?" + type + "=" + position;
|
2008-09-18 20:03:59 +02:00
|
|
|
var callbackFunction = fcn || this.saveDragHandleStateCallback;
|
|
|
|
triggerAjaxRequest(urlstr, callbackFunction);
|
2008-09-09 21:01:38 +02:00
|
|
|
}
|
2008-09-18 20:03:59 +02: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
|
|
|
}
|
|
|
|
};
|