forked from feather-components/vm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresize.js
More file actions
71 lines (56 loc) · 1.79 KB
/
resize.js
File metadata and controls
71 lines (56 loc) · 1.79 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
import _ from './helper';
module.exports = {
props: {
fillHeight: {
type: Boolean,
default: true
}
},
data(){
return {
fillSize: this.fillHeight
};
},
mounted: function(){
window.addEventListener('resize', () => {
this._resize_();
});
if(this.$el.style.height && (!this.style || !this.style.height)){
this._height = this.$el.style.height;
}
this.$el.$resize = this;
setTimeout(() => {
this._resize_();
}, 10);
},
methods: {
_resize_(){
if(this.style && this.style.height || this._height) return;
var element = this.$el, parent = element.parentNode;
var height, otherHeight = 0, selfTop = _.offset(element).top;
element.style.height = 'auto';
if(parent.style.height){
height = _.height(parent);
}else{
height = _.height(document.documentElement) - _.offset(parent).top;
}
if(_.css(parent, 'max-height')){
height = Math.min(height, parseFloat(parent.style.maxHeight));
}
if(!this.fillSize){
height = Math.min(_.height(element), height);
}else{
_.siblings(element).forEach((child) => _.offset(child).top != selfTop && (otherHeight += _.height(child)));
height -= otherHeight;
}
element.style.height = height + 'px';
this.$emit('resize');
}
}
}
module.exports.resize = (element) => {
element.$resize && element.$resize._resize_();
_.each(_.$$('*', element), (element) => {
element.$resize && element.$resize._resize_();
});
}