-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay-view-mixin.js
66 lines (64 loc) · 2.33 KB
/
display-view-mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
////
/// W.DisplayViewMixin
// @author Ross Cairns
// @notes Not suitable for heavy usage (i.e. particles) as produces
// many object with in turn will cause big
// garbage collections delays
var displayViewMixin = {
setPosition : function (x, y) { // or setXY(array) or setXY({x:y:})
if (Object.prototype.toString.call( x ) === '[object Array]') {
this.x(x[0]);
this.y(y[1]);
} else if (typeof x === "number") {
this.x(x);
this.y(y);
} else {
this.x(x.x);
this.y(x.y);
}
return this;
},
setSize : function (width, height) { // or setSize(Array) or setSize({width:height}) or setSize(DOMElement)
if (!!width.tagName && typeof jQuery === 'function') {
this.width(jQuery(width).width());
this.height(jQuery(width).height());
} else if (!!width.tagName) {
this.width = width.width;
this.height = width.height;
} else if (typeof width === "number") {
this.width(width);
this.height(height);
} else if (Object.prototype.toString.call( width ) === '[object Array]') {
this.width(width[0]);
this.height(width[1]);
} else if (typeof(width) == 'function') {
this.width(width());
this.height(height());
} else {
var obj = width;
this.width(typeof(obj.width) == 'function' ? obj.width() : obj.width);
this.height(typeof(obj.height) == 'function' ? obj.height() : obj.height);
}
return this;
},
x : function (x) {
if (arguments.length > 0) { this._x = x; }
if (typeof this._x === "undefined") { this._x = 0; }
return this._x;
},
y : function (y) {
if (arguments.length > 0) { this._y = y; }
if (typeof this._y === "undefined") { this._y = 0; }
return this._y;
},
width : function (width) {
if (arguments.length > 0) { this._width = width; }
if (typeof this._width === "undefined") { this._width = 0; }
return this._width;
},
height : function (height) {
if (arguments.length > 0) { this._height = height; }
if (typeof this._height === "undefined") { this._height = 0; }
return this._height;
}
};