-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
190 lines (166 loc) · 5.86 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* IE Check
* @returns {Number}
*/
function isIE () {
var myNav = navigator.userAgent.toLowerCase();
return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
}
jQuery(function() {
/**
* initialize scroll settings
* - sticky header
* - scroll up btn
*/
var initTylerScroll = function() {
var header = jQuery('header'),
scrollTop = jQuery(document).scrollTop(),
documentHeight = jQuery(document).height(),
windowHeight = jQuery(window).height(),
windowWidth = jQuery(window).width(),
limit = documentHeight - header.height() < windowHeight
? header.height()
: 1;
// only for "medium" devices
// if(windowWidth<992) {
// jQuery('#scroll-up').fadeOut();
// header.removeClass('sticky');
// jQuery(document.body).removeClass('header-sticky');
// return;
// }
// show "scroll up" btn
if(windowWidth > 1024 && scrollTop >= windowHeight/2) {
jQuery('#scroll-up').fadeIn();
}
else {
jQuery('#scroll-up').fadeOut();
}
// sticky header
if (scrollTop >= limit) {
header.addClass('sticky');
jQuery(document.body).addClass('header-sticky');
} else if (scrollTop <= limit) {
header.removeClass('sticky');
jQuery(document.body).removeClass('header-sticky');
}
}
jQuery(window).ready(initTylerScroll);
jQuery(window).scroll(initTylerScroll);
jQuery(window).resize(initTylerScroll);
// mobile menu expanded
jQuery('#tyler-navigation')
.on('show.bs.collapse', function () {
jQuery(document.body)
.addClass('header-menu-open')
.attr('data-scroll', jQuery(document).scrollTop());
window.scrollTo(0,0);
})
.on('hide.bs.collapse', function() {
jQuery(document.body).removeClass('header-menu-open');
window.scrollTo(0, jQuery(document.body).attr('data-scroll'));
});
/**
* change element text size to fit it's dimension
* @param el
* @param rel
*/
var textFit = function(el, rel) {
rel = Math.min(1, rel || 1);
el = jQuery(el);
var elInner = el.find('.text-fit-inner')[0] ||
el.wrapInner("<span class='text-fit-inner' style='display:block'></span>").find('.text-fit-inner')[0];
elInner = jQuery(elInner);
var maxW = Math.min(el.innerWidth(), parseInt(el.css('max-width'))),
maxH = Math.min(el.innerHeight(), parseInt(el.css('max-height')));
if(elInner.outerWidth() > maxW || elInner.outerHeight() > maxH) {
rel *= 0.95;
elInner.css('font-size', rel+'em');
textFit(el, rel);
}
}
if(!isIE() || isIE()>7) {
var initTextFit = function() {
jQuery('.text-fit').each(function(i, el) {
textFit(el);
});
}
initTextFit();
jQuery(window).on('resize', initTextFit);
}
//Add Hover effect to menus
if(jQuery(window).width()>=922) {
jQuery('header #menu-primary .menu-item-has-children')
.hover(function() {
var ul = jQuery(this).find('>ul');
ul.stop(true, true).delay(200).fadeIn({
start: function() {
if(jQuery(this).parents('ul.sub-menu').length!=0 && ul.offset().left > jQuery(window).width() - ul.width() - 100) {
ul.css({
'left':'auto',
'right':'100%'
});
}
}
});
}, function() {
jQuery(this).find('>ul').stop(true, true).delay(200).fadeOut();
});
}
// expand menu on click
jQuery('header #menu-primary .menu-item-has-children')
.click(function(event) {
if(jQuery('.navbar-toggle').is(':visible')){
if ( jQuery(this).hasClass('menu-item-has-children') ) {
event.preventDefault();
// make responsive submenu elemts clickable
jQuery( '#menu-primary .sub-menu li a' ).on( 'click', function(e) {
e.preventDefault();
window.location.href = jQuery(this).attr('href');
});
}
jQuery(this).toggleClass('expand');
}
});
// Fix Mobile menu when click on register button
jQuery('.menu-item.register').click(function(event){
jQuery('#tyler-navigation').addClass('collapse').css('height', '0px');
jQuery('#backdrop').hide();
});
// expand footer menu on click
jQuery('footer .col h4')
.click(function(event) {
event.preventDefault();
jQuery(this).parents('.col').toggleClass('expand');
});
// init scrollbars
jQuery('.scrollable').jScrollPane();
/**
* placeholder fix
* @see https://gist.github.com/hagenburger/379601
*/
jQuery('[placeholder]').focus(function() {
var input = jQuery(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = jQuery(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
jQuery(this).find('[placeholder]').each(function() {
var input = jQuery(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
// scroll button up
jQuery('#scroll-up').click(function(){
window.scrollTo(0, 0);
return false;
});
});