Change Size constructor to reflect logic in Point constructor.

This commit is contained in:
Jürg Lehni 2011-02-14 10:32:42 +00:00
parent 91e8a3b652
commit 1d0321bc69
2 changed files with 27 additions and 25 deletions
src/basic

View file

@ -4,18 +4,20 @@ var Size = Base.extend({
this.width = arguments[0];
this.height = arguments[1];
} else if (arguments.length == 1) {
var first = arguments[0];
if (first.width !== undefined || first.height !== undefined) {
this.width = first.width ? first.width : 0;
this.height = first.height ? first.height : 0;
} else if (first.x !== undefined || first.y !== undefined) {
this.width = first.x ? first.x : 0;
this.height = first.y ? first.y : 0;
} else if (first.length !== undefined) {
this.width = first[0];
this.height = first.length > 1 ? first[1] : first[0];
} else if (typeof first === 'number') {
this.width = this.height = first;
var arg = arguments[0];
if (arg == null) {
this.width = this.height = 0;
} else if (arg.width !== undefined) {
this.width = arg.width;
this.height = arg.height;
} else if (arg.x !== undefined) {
this.width = arg.x;
this.height = arg.y;
} else if (arg.length !== undefined) { // TODO: Array check
this.width = arg[0];
this.height = arg.length > 1 ? arg[1] : arg[0];
} else if (typeof arg === 'number') {
this.width = this.height = arg;
} else {
this.width = this.height = 0;
}