refactor position and new padding code.
This commit is contained in:
parent
78a3726f2f
commit
2e58aed1ea
|
@ -2332,8 +2332,9 @@ Element.prototype._getPos = function() {
|
|||
*/
|
||||
|
||||
Element.prototype._getWidth = function(get) {
|
||||
var parent = get ? this.parent._getPos() : this.parent;
|
||||
var width = this.position.width || 0;
|
||||
var parent = get ? this.parent._getPos() : this.parent
|
||||
, width = this.position.width || 0
|
||||
, left;
|
||||
|
||||
if (typeof width === 'string') {
|
||||
if (width === 'half') width = '50%';
|
||||
|
@ -2348,7 +2349,7 @@ Element.prototype._getWidth = function(get) {
|
|||
// decided by the width the element, so it needs to be
|
||||
// calculated here.
|
||||
if (!width) {
|
||||
var left = this.position.left || 0;
|
||||
left = this.position.left || 0;
|
||||
if (typeof left === 'string') {
|
||||
if (left === 'center') left = '50%';
|
||||
left = +left.slice(0, -1) / 100;
|
||||
|
@ -2356,9 +2357,14 @@ Element.prototype._getWidth = function(get) {
|
|||
}
|
||||
width = parent.width - (this.position.right || 0) - left;
|
||||
if (this.screen.autoPadding) {
|
||||
width -= ((this.position.left != null || this.position.right == null)
|
||||
&& this.position.left !== 'center' ? this.parent.ileft : 0);
|
||||
width -= (this.position.right != null ? this.parent.iright : 0);
|
||||
if ((this.position.left != null || this.position.right == null)
|
||||
&& this.position.left !== 'center') {
|
||||
width -= (this.position.left != null || this.position.right == null)
|
||||
&& this.position.left !== 'center' ? this.parent.ileft : 0;
|
||||
}
|
||||
if (this.position.right != null) {
|
||||
width -= this.position.right != null ? this.parent.iright : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2370,8 +2376,9 @@ Element.prototype.__defineGetter__('width', function() {
|
|||
});
|
||||
|
||||
Element.prototype._getHeight = function(get) {
|
||||
var parent = get ? this.parent._getPos() : this.parent;
|
||||
var height = this.position.height || 0;
|
||||
var parent = get ? this.parent._getPos() : this.parent
|
||||
, height = this.position.height || 0
|
||||
, top;
|
||||
|
||||
if (typeof height === 'string') {
|
||||
if (height === 'half') height = '50%';
|
||||
|
@ -2386,7 +2393,7 @@ Element.prototype._getHeight = function(get) {
|
|||
// decided by the width the element, so it needs to be
|
||||
// calculated here.
|
||||
if (!height) {
|
||||
var top = this.position.top || 0;
|
||||
top = this.position.top || 0;
|
||||
if (typeof top === 'string') {
|
||||
if (top === 'center') top = '50%';
|
||||
top = +top.slice(0, -1) / 100;
|
||||
|
@ -2394,9 +2401,14 @@ Element.prototype._getHeight = function(get) {
|
|||
}
|
||||
height = parent.height - (this.position.bottom || 0) - top;
|
||||
if (this.screen.autoPadding) {
|
||||
height -= ((this.position.top != null || this.position.bottom == null)
|
||||
&& this.position.top !== 'center' ? this.parent.itop : 0);
|
||||
height -= (this.position.bottom != null ? this.parent.ibottom : 0);
|
||||
if ((this.position.top != null
|
||||
|| this.position.bottom == null)
|
||||
&& this.position.top !== 'center') {
|
||||
height -= this.parent.itop;
|
||||
}
|
||||
if (this.position.bottom != null) {
|
||||
height -= this.parent.ibottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2408,8 +2420,8 @@ Element.prototype.__defineGetter__('height', function() {
|
|||
});
|
||||
|
||||
Element.prototype._getLeft = function(get) {
|
||||
var parent = get ? this.parent._getPos() : this.parent;
|
||||
var left = this.position.left || 0;
|
||||
var parent = get ? this.parent._getPos() : this.parent
|
||||
, left = this.position.left || 0;
|
||||
|
||||
if (typeof left === 'string') {
|
||||
if (left === 'center') left = '50%';
|
||||
|
@ -2425,7 +2437,8 @@ Element.prototype._getLeft = function(get) {
|
|||
}
|
||||
|
||||
if (this.screen.autoPadding) {
|
||||
if ((this.position.left != null || this.position.right == null)
|
||||
if ((this.position.left != null
|
||||
|| this.position.right == null)
|
||||
&& this.position.left !== 'center') {
|
||||
left += this.parent.ileft;
|
||||
}
|
||||
|
@ -2439,18 +2452,27 @@ Element.prototype.__defineGetter__('left', function() {
|
|||
});
|
||||
|
||||
Element.prototype._getRight = function(get) {
|
||||
var parent = get ? this.parent._getPos() : this.parent;
|
||||
var parent = get ? this.parent._getPos() : this.parent
|
||||
, right;
|
||||
|
||||
if (this.position.right == null && this.position.left != null) {
|
||||
var right = this.screen.cols - (this._getLeft(get) + this._getWidth(get));
|
||||
right = this.screen.cols - (this._getLeft(get) + this._getWidth(get));
|
||||
if (this.screen.autoPadding) {
|
||||
right += (this.position.right != null ? this.parent.iright : 0);
|
||||
if (this.position.right != null) {
|
||||
right += this.parent.iright;
|
||||
}
|
||||
}
|
||||
return right;
|
||||
}
|
||||
var right = (parent.right || 0) + (this.position.right || 0);
|
||||
|
||||
right = (parent.right || 0) + (this.position.right || 0);
|
||||
|
||||
if (this.screen.autoPadding) {
|
||||
right += (this.position.right != null ? this.parent.iright : 0);
|
||||
if (this.position.right != null) {
|
||||
right += this.parent.iright;
|
||||
}
|
||||
}
|
||||
|
||||
return right;
|
||||
};
|
||||
|
||||
|
@ -2459,8 +2481,8 @@ Element.prototype.__defineGetter__('right', function() {
|
|||
});
|
||||
|
||||
Element.prototype._getTop = function(get) {
|
||||
var parent = get ? this.parent._getPos() : this.parent;
|
||||
var top = this.position.top || 0;
|
||||
var parent = get ? this.parent._getPos() : this.parent
|
||||
, top = this.position.top || 0;
|
||||
|
||||
if (typeof top === 'string') {
|
||||
if (top === 'center') top = '50%';
|
||||
|
@ -2476,7 +2498,8 @@ Element.prototype._getTop = function(get) {
|
|||
}
|
||||
|
||||
if (this.screen.autoPadding) {
|
||||
if ((this.position.top != null || this.position.bottom == null)
|
||||
if ((this.position.top != null
|
||||
|| this.position.bottom == null)
|
||||
&& this.position.top !== 'center') {
|
||||
top += this.parent.itop;
|
||||
}
|
||||
|
@ -2490,18 +2513,27 @@ Element.prototype.__defineGetter__('top', function() {
|
|||
});
|
||||
|
||||
Element.prototype._getBottom = function(get) {
|
||||
var parent = get ? this.parent._getPos() : this.parent;
|
||||
var parent = get ? this.parent._getPos() : this.parent
|
||||
, bottom;
|
||||
|
||||
if (this.position.bottom == null && this.position.top != null) {
|
||||
var bottom = this.screen.rows - (this._getTop(get) + this._getHeight(get));
|
||||
bottom = this.screen.rows - (this._getTop(get) + this._getHeight(get));
|
||||
if (this.screen.autoPadding) {
|
||||
bottom += (this.position.bottom != null ? this.parent.ibottom : 0);
|
||||
if (this.position.bottom != null) {
|
||||
bottom += this.parent.ibottom;
|
||||
}
|
||||
}
|
||||
return bottom;
|
||||
}
|
||||
var bottom = (parent.bottom || 0) + (this.position.bottom || 0);
|
||||
|
||||
bottom = (parent.bottom || 0) + (this.position.bottom || 0);
|
||||
|
||||
if (this.screen.autoPadding) {
|
||||
bottom += (this.position.bottom != null ? this.parent.ibottom : 0);
|
||||
if (this.position.bottom != null) {
|
||||
bottom += this.parent.ibottom;
|
||||
}
|
||||
}
|
||||
|
||||
return bottom;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue