blob: a07737795b8eb0e89a2842613e3ae4a0cc9d3139 (
plain)
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
|
// generic layout specific responsive stuff goes here
function openFlyout() {
$('html').addClass('flyout-is-active');
$('#main').on('click', function(e){
e.preventDefault();
e.stopPropagation();
closeFlyout();
});
}
function closeFlyout() {
$('html').removeClass('flyout-is-active');
$('#wrapper').off('click');
}
function isMobile() {
return $('.js-flyout-menu-toggle-button').is(":visible");
}
function setupFlyout() {
var mobileInit = false,
desktopInit = false;
/* click handler for mobile menu toggle */
$('.js-flyout-menu-toggle-button').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
if($('html').hasClass('flyout-is-active')) {
closeFlyout();
} else {
openFlyout();
}
});
/* bind resize handler */
$(window).resize(function() {
initMenu();
})
/* menu init function for dom detaching and appending on mobile / desktop view */
function initMenu() {
var _initMobileMenu = function() {
/* only init mobile menu, if it hasn't been done yet */
if(!mobileInit) {
$('#main-menu > ul').detach().appendTo('.js-project-menu');
$('#top-menu > ul').detach().appendTo('.js-general-menu');
$('#sidebar > *').detach().appendTo('.js-sidebar');
$('#account > ul').detach().appendTo('.js-profile-menu');
mobileInit = true;
desktopInit = false;
}
}
var _initDesktopMenu = function() {
if(!desktopInit) {
$('.js-project-menu > ul').detach().appendTo('#main-menu');
$('.js-general-menu > ul').detach().appendTo('#top-menu');
$('.js-sidebar > *').detach().appendTo('#sidebar');
$('.js-profile-menu > ul').detach().appendTo('#account');
desktopInit = true;
mobileInit = false;
}
}
if(isMobile()) {
_initMobileMenu();
} else {
_initDesktopMenu();
}
}
// init menu on page load
initMenu();
}
$(document).ready(setupFlyout);
|