Project

General

Profile

1
import { isNumeric, isString, offsetTop, query } from '../util/index';
2

    
3
export default function (UIkit) {
4

    
5
    UIkit.component('height-viewport', {
6

    
7
        props: {
8
            expand: Boolean,
9
            offsetTop: Boolean,
10
            offsetBottom: Boolean
11
        },
12

    
13
        defaults: {
14
            expand: false,
15
            offsetTop: false,
16
            offsetBottom: false
17
        },
18

    
19
        connected() {
20
            this.$emitSync();
21
        },
22

    
23
        update: {
24

    
25
            write() {
26

    
27
                this.$el.css('boxSizing', 'border-box');
28

    
29
                var viewport = window.innerHeight, height, offset = 0;
30

    
31
                if (this.expand) {
32

    
33
                    this.$el.css({height: '', minHeight: ''});
34

    
35
                    var diff = viewport - document.documentElement.offsetHeight;
36

    
37
                    if (diff > 0) {
38
                        this.$el.css('min-height', height = this.$el.outerHeight() + diff)
39
                    }
40

    
41
                } else {
42

    
43
                    var top = offsetTop(this.$el);
44

    
45
                    if (top < viewport && this.offsetTop) {
46
                        offset += top;
47
                    }
48

    
49
                    if (this.offsetBottom === true) {
50

    
51
                        offset += this.$el.next().outerHeight() || 0;
52

    
53
                    } else if (isNumeric(this.offsetBottom)) {
54

    
55
                        offset += (viewport / 100) * this.offsetBottom;
56

    
57
                    } else if (this.offsetBottom && this.offsetBottom.substr(-2) === 'px') {
58

    
59
                        offset += parseFloat(this.offsetBottom);
60

    
61
                    } else if (isString(this.offsetBottom)) {
62

    
63
                        var el = query(this.offsetBottom, this.$el);
64
                        offset += el && el.outerHeight() || 0;
65

    
66
                    }
67

    
68
                    this.$el.css('min-height', height = offset ? `calc(100vh - ${offset}px)` : '100vh');
69

    
70
                }
71

    
72
                // IE 10-11 fix (min-height on a flex container won't apply to its flex items)
73
                this.$el.height('');
74
                if (height && viewport - offset >= this.$el.outerHeight()) {
75
                    this.$el.css('height', height);
76
                }
77

    
78
            },
79

    
80
            events: ['load', 'resize']
81

    
82
        }
83

    
84
    });
85

    
86
}
(10-10/28)