-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ratio.js
47 lines (46 loc) · 1.3 KB
/
Ratio.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
var compose = require('ksf/utils/compose')
var _Evented = require('ksf/base/_Evented')
var delegateGetSet = require('./utils/delegateGetSet');
var getSet = require('./utils/getSet')
var onOffEvent = require('./utils/onOffEvent')
module.exports = compose(_Evented, function(ratioWH, content) {
this._ratio = ratioWH
this._content = content
}, {
_applyWidth: function(width) {
this._content.width(width)
this._emit('width', width)
},
width: getSet(
function() {
return this._content.width()
},
function(width) {
this._applyWidth(width)
this._applyHeight(width / this._ratio)
}
),
_applyHeight: function(height) {
this._content.height(height)
this._emit('height', height)
},
height: getSet(
function() {
return this._content.height()
},
function(height) {
this._applyHeight(height)
this._applyWidth(height * this._ratio)
}
),
left: delegateGetSet('_content', 'left'),
top: delegateGetSet('_content', 'top'),
zIndex: delegateGetSet('_content', 'zIndex'),
depth: delegateGetSet('_content', 'depth'),
parentNode: delegateGetSet('_content', 'parentNode'),
containerVisible: delegateGetSet('_content', 'containerVisible'),
visible: delegateGetSet('_content', 'visible'),
},
onOffEvent('width'),
onOffEvent('height')
);