1
|
// Theme JavaScript
|
2
|
|
3
|
(function ($) {
|
4
|
|
5
|
UIkit.component('header', {
|
6
|
|
7
|
name: 'header',
|
8
|
|
9
|
connected: function () {
|
10
|
this.initialize();
|
11
|
},
|
12
|
|
13
|
ready: function () {
|
14
|
if (!this.section.length) {
|
15
|
this.initialize();
|
16
|
}
|
17
|
},
|
18
|
|
19
|
update: [
|
20
|
|
21
|
{
|
22
|
|
23
|
read: function () {
|
24
|
this.prevHeight = this.height;
|
25
|
this.height = this.$el[0].offsetHeight;
|
26
|
var sticky = this.modifier && UIkit.getComponent(this.sticky, 'sticky');
|
27
|
if (sticky) {
|
28
|
sticky.$props.top = this.section[0].offsetHeight <= window.innerHeight
|
29
|
? this.selector
|
30
|
: UIkit.util.offsetTop(this.section) + this.height;
|
31
|
}
|
32
|
},
|
33
|
|
34
|
write: function () {
|
35
|
if (this.placeholder && this.prevHeight !== this.height) {
|
36
|
this.placeholder.css({height: this.height});
|
37
|
}
|
38
|
},
|
39
|
|
40
|
events: ['load', 'resize']
|
41
|
|
42
|
}
|
43
|
|
44
|
],
|
45
|
|
46
|
methods: {
|
47
|
|
48
|
initialize: function () {
|
49
|
|
50
|
this.selector = '.tm-header + [class*="uk-section"]';
|
51
|
this.section = $(this.selector);
|
52
|
this.sticky = $('[uk-sticky]', this.$el);
|
53
|
this.modifier = this.section.attr('tm-header-transparent');
|
54
|
|
55
|
if (!this.modifier || !this.section.length) {
|
56
|
return;
|
57
|
}
|
58
|
|
59
|
this.$el.addClass('tm-header-transparent');
|
60
|
|
61
|
this.placeholder = $('<div class="tm-header-placeholder uk-margin-remove-adjacent" style="height: ' + this.$el[0].offsetHeight + 'px"></div>').insertBefore($('[uk-grid]', this.section).first());
|
62
|
|
63
|
var container = $('.uk-navbar-container', this.$el),
|
64
|
cls = 'uk-navbar-transparent uk-' + this.modifier;
|
65
|
|
66
|
$('.tm-headerbar-top, .tm-headerbar-bottom').addClass('uk-' + this.modifier);
|
67
|
|
68
|
if (!this.sticky.length) {
|
69
|
container.addClass(cls);
|
70
|
} else {
|
71
|
this.sticky.attr({
|
72
|
animation: 'uk-animation-slide-top',
|
73
|
top: this.selector,
|
74
|
'cls-inactive': cls
|
75
|
});
|
76
|
}
|
77
|
}
|
78
|
|
79
|
}
|
80
|
|
81
|
});
|
82
|
|
83
|
})(jQuery);
|
84
|
|
85
|
if (UIkit.util.isRtl) {
|
86
|
|
87
|
var mixin = {
|
88
|
|
89
|
init: function () {
|
90
|
this.$props.pos = UIkit.util.swap(this.$props.pos, 'left', 'right');
|
91
|
}
|
92
|
|
93
|
};
|
94
|
|
95
|
UIkit.mixin(mixin, 'drop');
|
96
|
UIkit.mixin(mixin, 'tooltip');
|
97
|
|
98
|
}
|