-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
133 lines (103 loc) · 3.22 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
function responsiveMobileMenu() {
$('.nav').each(function() {
// $(this).children('ul').addClass('nav-menu'); // mark main menu list
var $style = $(this).attr('nav-menu-style'); // get menu style
if (typeof $style == 'undefined' || $style == false) {
$(this).addClass('yoga'); // set yoga style if style is not defined
} else {
$(this).addClass($style);
}
/* width of menu list (non-toggled) */
var $width = 0;
$(this).find('ul li').each(function() {
$width += $(this).outerWidth();
});
// if modern browser
if ($.support.leadingWhitespace) {
// $(this).css('max-width', $width * 1.2 + 'px');
}
//
else {
$(this).css('width', $width * 1.2 + 'px');
}
});
}
function getMobileMenu() {
/* build toggled dropdown menu list */
$('.nav').each(function() {
var menutitle = $(this).attr("nav-menu-title");
if (menutitle == "") {
menutitle = "";
} else if (menutitle == undefined) {
menutitle = "";
}
var $menulist = $(this).children('.nav-menu').html();
var $menucontrols = "<div class='nav-toggled-controls'><div class='nav-toggled-title'>" + menutitle + "</div><div class='nav-button'><span> </span><span> </span><span> </span></div></div>";
$(this).prepend("<div class='nav-toggled nav-closed'>" + $menucontrols + "<ul>" + $menulist + "</ul></div>");
});
}
function adaptMenu() {
/* toggle menu on resize */
$('.nav').each(function() {
// var $width = $(this).css('max-width');
// $width = $width.replace('px', '');
var $width = 768;
if ($(this).parent().width() < $width * 1.05) {
$(this).children('.nav-menu').hide(0);
$(this).children('.nav-toggled').show(0);
} else {
$(this).children('.nav-menu').show(0);
$(this).children('.nav-toggled').hide(0);
}
});
}
$(function() {
responsiveMobileMenu();
getMobileMenu();
adaptMenu();
/* slide down mobile menu on click */
$('.nav-toggled, .nav-toggled .nav-button').click(function() {
if ($(this).is(".nav-closed")) {
$(this).find('> ul').stop().show(300);
$(this).removeClass("nav-closed");
} else {
$(this).find(' > ul').stop().hide(300);
$(this).addClass("nav-closed");
}
});
});
/* hide mobile menu on resize */
$(window).resize(function() {
adaptMenu();
});
$(document).ready(function() {
//test for touch events support and if not supported, attach .no-touch class to the HTML tag.
if (!("ontouchstart" in document.documentElement)) {
document.documentElement.className += " no-touch";
} else {
document.documentElement.className += " touch";
}
var $submenus = $('.nav.yoga .nav-menu li > ul');
$submenus.hide();
if ($('html').hasClass('no-touch')) {
$submenus.parent().hover(function() {
$(this).find('> ul').slideToggle('fast');
});
} else {
$submenus.parent().click(function(e) {
$(this).find('> ul').slideToggle('fast');
e.preventDefault();
e.stopPropagation();
});
}
$submenus.parent().addClass('has-children');
var $submenusSm = $('.nav.yoga .nav-toggled li > ul');
$submenusSm.hide();
$submenusSm.parent().children('a').addClass('toggle-sm');
$submenusSm.parent().on('click', function(e) {
e.preventDefault();
e.stopPropagation();
$(this).find('> ul').slideToggle();
$(this).children('a').toggleClass('open');
});
});