-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch.js
More file actions
89 lines (87 loc) · 2.35 KB
/
Copy pathSwitch.js
File metadata and controls
89 lines (87 loc) · 2.35 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var compose = require('ksf/utils/compose');
var _Destroyable = require('ksf/base/_Destroyable');
var _Evented = require('ksf/base/_Evented');
var defaults = require('lodash/object/defaults')
var onOffEvent = require('./utils/onOffEvent')
function contentGetSet (prop) {
return function(value) {
if (arguments.length) {
this._props[prop] = value;
this._content && this._content[prop](value);
return this;
} else {
return this._props[prop];
}
};
}
module.exports = compose(_Destroyable, _Evented, function(opts) {
this._opts = defaults({}, opts, { autoHeight: false, autoWidth: false })
this._props = {};
}, {
content: function(content) {
if (this._content && this._props.parentNode) {
this._content.parentNode(null);
this._destroy('contentHeight')
this._destroy('contentWidth')
}
this._content = content;
if (content) {
for (var prop in this._props) {
this._content[prop](this._props[prop]);
}
if (this._opts.autoHeight && this._opts.autoHeight !== 'init') {
this._own(this._content.onHeight(function(height) {
this._emit('height', height)
}.bind(this)), 'contentHeight')
}
if (this._opts.autoWidth && this._opts.autoWidth !== 'init') {
this._own(this._content.onWidth(function(width) {
this._emit('width', width)
}.bind(this)), 'contentWidth')
}
}
if (this._opts.autoHeight) {
this._emit('height', this.height())
}
if (this._opts.autoWidth) {
this._emit('width', this.width())
}
return this;
},
width: function(value) {
if (arguments.length) {
this._props.width = value;
this._content && this._content.width(value);
return this;
} else {
if (this._opts.autoWidth) {
return this._content ? this._content.width() : 0
} else {
return this._props.width;
}
}
},
height: function(value) {
if (arguments.length) {
this._props.height = value;
this._content && this._content.height(value);
return this;
} else {
if (this._opts.autoHeight) {
return this._content ? this._content.height() : 0
} else {
return this._props.height;
}
}
},
depth: contentGetSet('depth'),
left: contentGetSet('left'),
top: contentGetSet('top'),
zIndex: contentGetSet('zIndex'),
parentNode: contentGetSet('parentNode'),
visible: contentGetSet('visible'),
containerVisible: contentGetSet('containerVisible'),
},
onOffEvent('height'),
onOffEvent('width')
);