-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (53 loc) · 1.22 KB
/
Copy pathindex.js
File metadata and controls
56 lines (53 loc) · 1.22 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
var query = require('query'),
css = require('css'),
windowSize = require('window-size');
exports = module.exports = function (el, offset, min) {
var listen,
width,
height;
el = el || document;
if (typeof el === 'string')
el = query(el);
listen = function (method) {
return function () {
window.onresize = function () {
exports(el, offset, min)[method](el);
}
}
};
size = function (dir) {
var o = offset || 0,
m = min || 0,
ws = windowSize()[dir],
i = dir === 'height';
if (o instanceof Array)
o = o[i] || 0;
if (m instanceof Array)
m = m[i] || 0;
return (ws - o < m ? m : ws - o);
};
return {
both: function () {
css(el, {
minWidth: size('width'),
minHeight: size('height'),
display: 'block'
});
return { listen: listen('both') };
},
height: function () {
css(el, {
minHeight: size('height'),
display: 'block'
});
return { listen: listen('height') };
},
width: function () {
css(el, {
minWidth: size('width'),
display: 'block'
});
return { listen: listen('width') };
}
};
};