///////////////////////////////////////////////////////////////////////////////
Type.registerNamespace('apX.Ext');
///////////////////////////////////////////////////////////////////////////////
// apX.Ext.ResizableAreaBehavior
apX.Ext.ResizableAreaBehavior = function(element) {
apX.Ext.ResizableAreaBehavior.initializeBase(this, [element]);
this._leftEl = null;
this._rightEl = null;
this._splitterEl = null;
this._collapsed = false;
this._collapsedCookieName = 'raCollapsed';
this._widthCookieName = 'raWidth';
this._cookiePath = null;
this._width = 0;
this._minWidth = 30;
this._triggerHandler = null;
this._resizeStartHandler = null;
this._resizeStopHandler = null;
this._resizingHandler = null;
this._bodyMiscHandler = null;
}
apX.Ext.ResizableAreaBehavior.prototype = {
initialize : function() {
apX.Ext.ResizableAreaBehavior.callBaseMethod(this, 'initialize');
this._splitterWidth = this._splitterEl.getWidth();
this._helfSplitterWidth = parseInt(this._splitterWidth/2);
var collapsed = apX.Ext.getCookie(this._collapsedCookieName);
if (collapsed != null)
this._collapsed = Boolean.parse(collapsed);
if (this._collapsed)
this.collapse(true);
this._triggerHandler = Function.createDelegate(this, this.onSplitterDblClick);
this._splitterEl.addHandler('dblclick', this._triggerHandler);
this._resizeStartHandler = Function.createDelegate(this, this.onSplitterMouseDown);
this._resizeStopHandler = Function.createDelegate(this, this.onDocumentMouseUp);
this._resizingHandler = Function.createDelegate(this, this.onDocumentMouseMove);
this._bodyMiscHandler = Function.createDelegate(this, this.onBodyMisc);
this._splitterEl.addHandler('mousedown', this._resizeStartHandler);
},
dispose : function() {
this._splitterEl.removeHandler('dblclick', this._triggerHandler);
this._triggerHandler = null;
this._splitterEl.removeHandler('mousedown', this._resizeStartHandler);
if (this._dragging) {
$removeHandler(document, 'mousemove', this._resizingHandler);
$removeHandler(document, 'mouseup', this._resizeStopHandler);
$removeHandler(document.body, 'drag', this._bodyMiscHandler);
$removeHandler(document.body, 'selectstart', this._bodyMiscHandler);
this._dragging = false;
}
this._resizeStartHandler = null;
this._resizeStopHandler = null;
this._resizingHandler = null;
apX.Ext.ResizableAreaBehavior.callBaseMethod(this, 'dispose');
},
setWidth: function(value, setCookie) {
this._leftEl.setWidth(value+this._splitterWidth);
this._splitterEl.setLeft(value);
this._width = value;
if (setCookie)
apX.Ext.setCookie(this._widthCookieName, value, 365, this._cookiePath);
},
collapse : function(value) {
if (value) {
this._leftEl.setVisible(false);
this._collapsed = true;
this._splitterEl.setLeft(0);
apX.Ext.setCookie(this._collapsedCookieName, true, 365, this._cookiePath);
}
else {
this._leftEl.setVisible(true);
this._collapsed = false;
this._splitterEl.setLeft(this._leftEl.getWidth());
apX.Ext.deleteCookie(this._collapsedCookieName, this._cookiePath);
}
},
get_leftEl : function() {
return this._leftEl;
},
set_leftEl : function(value) {
this._leftEl = apX.El(value);
},
get_rightEl : function() {
return this._rightEl;
},
set_rightEl : function(value) {
this._rightEl = apX.El(value);
},
get_splitterEl : function() {
return this._splitterEl;
},
set_splitterEl : function(value) {
this._splitterEl = apX.El(value);
},
get_collapsedCookieName : function() {
return this._collapsedCookieName;
},
set_collapsedCookieName : function(value) {
this._collapsedCookieName = value;
},
get_widthCookieName : function() {
return this._widthCookieName;
},
set_widthCookieName : function(value) {
this._widthCookieName = value;
},
get_cookiePath : function() {
return this._cookiePath;
},
set_cookiePath : function(value) {
this._cookiePath = value;
},
get_minWidth : function() {
return this._minWidth;
},
set_minWidth : function(value) {
this._minWidth = value;
},
onSplitterDblClick : function(e) {
this.collapse(!this._collapsed);
e.preventDefault();
return false;
},
onSplitterMouseDown : function(e) {
this._dragging = true;
$addHandler(document, 'mousemove', this._resizingHandler);
$addHandler(document, 'mouseup', this._resizeStopHandler);
$addHandler(document.body, 'drag', this._bodyMiscHandler);
$addHandler(document.body, 'selectstart', this._bodyMiscHandler);
return false;
},
onDocumentMouseMove : function(e) {
var x = e.clientX-this._splitterWidth+2;
this._splitterEl.setLeft(x);
return false;
},
onDocumentMouseUp : function(e) {
var x = e.clientX-this._splitterWidth+2;
if (x < this._minWidth) {
this.collapse(true);
}
else {
if (this._collapsed)
this.collapse(false);
this.setWidth(x, true);
}
$removeHandler(document, 'mousemove', this._resizingHandler);
$removeHandler(document, 'mouseup', this._resizeStopHandler);
$removeHandler(document.body, 'drag', this._bodyMiscHandler);
$removeHandler(document.body, 'selectstart', this._bodyMiscHandler);
this._dragging = false;
return false;
},
onBodyMisc : function(e) {
return !this._dragging;
},
over : true
}
apX.Ext.ResizableAreaBehavior.registerClass('apX.Ext.ResizableAreaBehavior', apX.Behavior);