optimize setters.

This commit is contained in:
Christopher Jeffrey 2013-06-12 14:31:48 -05:00
parent 843736d5b1
commit 9963df5343
1 changed files with 30 additions and 4 deletions

View File

@ -784,11 +784,13 @@ Element.prototype.__defineSetter__('left', function(val) {
val = +val.slice(0, -1) / 100;
val = this.screen.width * val | 0;
}
val -= this.parent.left;
if (this.position.left === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
this.top, this.top + this.height);
return this.options.left = this.position.left = val - this.parent.left;
return this.options.left = this.position.left = val;
});
Element.prototype.__defineSetter__('right', function(val) {
@ -797,11 +799,16 @@ Element.prototype.__defineSetter__('right', function(val) {
val = +val.slice(0, -1) / 100;
val = this.screen.width * val | 0;
}
val -= this.parent.right;
if (this.position.right === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
this.top, this.top + this.height);
return this.options.right = this.position.right = val - this.parent.right;
//if (this.options.right == null) {
// return this.options.left = this.position.left = this.screen.width - 1 - val;
//}
return this.options.right = this.position.right = val;
});
Element.prototype.__defineSetter__('top', function(val) {
@ -810,11 +817,13 @@ Element.prototype.__defineSetter__('top', function(val) {
val = +val.slice(0, -1) / 100;
val = this.screen.height * val | 0;
}
val -= this.parent.top;
if (this.position.top === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
this.top, this.top + this.height);
return this.options.top = this.position.top = val - this.parent.top;
return this.options.top = this.position.top = val;
});
Element.prototype.__defineSetter__('bottom', function(val) {
@ -823,14 +832,20 @@ Element.prototype.__defineSetter__('bottom', function(val) {
val = +val.slice(0, -1) / 100;
val = this.screen.height * val | 0;
}
val -= this.parent.bottom;
if (this.position.bottom === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
this.top, this.top + this.height);
return this.options.bottom = this.position.bottom = val - this.parent.bottom;
//if (this.options.bottom == null) {
// return this.options.top = this.position.top = this.screen.height - 1 - val;
//}
return this.options.bottom = this.position.bottom = val;
});
Element.prototype.__defineSetter__('width', function(val) {
if (this.position.width === val) return;
this.emit('resize');
this.screen.clearRegion(
this.left, this.left + this.width,
@ -839,6 +854,7 @@ Element.prototype.__defineSetter__('width', function(val) {
});
Element.prototype.__defineSetter__('height', function(val) {
if (this.position.height === val) return;
this.emit('resize');
this.screen.clearRegion(
this.left, this.left + this.width,
@ -847,6 +863,7 @@ Element.prototype.__defineSetter__('height', function(val) {
});
Element.prototype.__defineSetter__('rleft', function(val) {
if (this.position.left === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
@ -855,14 +872,19 @@ Element.prototype.__defineSetter__('rleft', function(val) {
});
Element.prototype.__defineSetter__('rright', function(val) {
if (this.position.right === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
this.top, this.top + this.height);
//if (this.options.right == null) {
// return this.options.left = this.position.left = this.parent.width - 1 - val;
//}
return this.options.right = this.position.right = val;
});
Element.prototype.__defineSetter__('rtop', function(val) {
if (this.position.top === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
@ -871,10 +893,14 @@ Element.prototype.__defineSetter__('rtop', function(val) {
});
Element.prototype.__defineSetter__('rbottom', function(val) {
if (this.position.bottom === val) return;
this.emit('move');
this.screen.clearRegion(
this.left, this.left + this.width,
this.top, this.top + this.height);
//if (this.options.bottom == null) {
// return this.options.top = this.position.top = this.parent.height - 1 - val;
//}
return this.options.bottom = this.position.bottom = val;
});