| 9 |
lars |
1 |
/**
|
|
|
2 |
Core script to handle the entire theme and core functions
|
|
|
3 |
**/
|
|
|
4 |
var Layout = function() {
|
|
|
5 |
|
|
|
6 |
var layoutImgPath = 'layouts/layout5/img/';
|
|
|
7 |
|
|
|
8 |
var layoutCssPath = 'layouts/layout5/css/';
|
|
|
9 |
|
|
|
10 |
var resBreakpointMd = App.getResponsiveBreakpoint('md');
|
|
|
11 |
|
|
|
12 |
// handle on page scroll
|
|
|
13 |
var handleHeaderOnScroll = function() {
|
|
|
14 |
if ($(window).scrollTop() > 60) {
|
|
|
15 |
$("body").addClass("page-on-scroll");
|
|
|
16 |
} else {
|
|
|
17 |
$("body").removeClass("page-on-scroll");
|
|
|
18 |
}
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
// Handles active menu to avoid closing click to content
|
|
|
22 |
|
|
|
23 |
// handle go to top button
|
|
|
24 |
var handleGo2Top = function () {
|
|
|
25 |
var Go2TopOperation = function(){
|
|
|
26 |
var CurrentWindowPosition = $(window).scrollTop();// current vertical position
|
|
|
27 |
if (CurrentWindowPosition > 100) {
|
|
|
28 |
$(".go2top").show();
|
|
|
29 |
} else {
|
|
|
30 |
$(".go2top").hide();
|
|
|
31 |
}
|
|
|
32 |
};
|
|
|
33 |
|
|
|
34 |
Go2TopOperation();// call headerFix() when the page was loaded
|
|
|
35 |
if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {
|
|
|
36 |
$(window).bind("touchend touchcancel touchleave", function(e){
|
|
|
37 |
Go2TopOperation();
|
|
|
38 |
});
|
|
|
39 |
} else {
|
|
|
40 |
$(window).scroll(function() {
|
|
|
41 |
Go2TopOperation();
|
|
|
42 |
});
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
$(".go2top").click(function(e) {
|
|
|
46 |
e.preventDefault();
|
|
|
47 |
$("html, body").animate({ scrollTop: 0 }, 600);
|
|
|
48 |
});
|
|
|
49 |
};
|
|
|
50 |
|
|
|
51 |
var handleHeaderMenu = function() {
|
|
|
52 |
$('.page-header .navbar-nav > .dropdown-fw, .page-header .navbar-nav > .more-dropdown, .page-header .navbar-nav > .dropdown > .dropdown-menu > .dropdown').click(function(e) {
|
|
|
53 |
|
|
|
54 |
if (App.getViewPort().width > resBreakpointMd) {
|
|
|
55 |
if ($(this).hasClass('more-dropdown') || $(this).hasClass('more-dropdown-sub')) {
|
|
|
56 |
return;
|
|
|
57 |
} else {
|
|
|
58 |
e.stopPropagation();
|
|
|
59 |
}
|
|
|
60 |
} else {
|
|
|
61 |
e.stopPropagation();
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
var links = $(this).parent().find('> .dropdown');
|
|
|
65 |
|
|
|
66 |
if (App.getViewPort().width < resBreakpointMd) {
|
|
|
67 |
if ($(this).hasClass('open')) {
|
|
|
68 |
links.removeClass('open');
|
|
|
69 |
} else {
|
|
|
70 |
links.removeClass('open');
|
|
|
71 |
$(this).addClass('open');
|
|
|
72 |
App.scrollTo($(this));
|
|
|
73 |
}
|
|
|
74 |
} else {
|
|
|
75 |
if ($(this).hasClass('more-dropdown')) {
|
|
|
76 |
return;
|
|
|
77 |
}
|
|
|
78 |
links.removeClass('open');
|
|
|
79 |
$(this).addClass('open');
|
|
|
80 |
App.scrollTo($(this));
|
|
|
81 |
}
|
|
|
82 |
});
|
|
|
83 |
|
|
|
84 |
$('.page-header .navbar-nav .more-dropdown-sub .dropdown-menu, .page-header .navbar-nav .dropdown-sub .dropdown-menu').click(function(){
|
|
|
85 |
|
|
|
86 |
});
|
|
|
87 |
};
|
|
|
88 |
|
|
|
89 |
// Handles main menu on window resize
|
|
|
90 |
var handleMainMenuOnResize = function() {
|
|
|
91 |
// handle hover dropdown menu for desktop devices only
|
|
|
92 |
var width = App.getViewPort().width;
|
|
|
93 |
var menu = $(".page-header .navbar-nav");
|
|
|
94 |
if (width >= resBreakpointMd && menu.data('breakpoint') !== 'desktop') {
|
|
|
95 |
menu.data('breakpoint', 'desktop');
|
|
|
96 |
$('[data-hover="extended-dropdown"]', menu).not('.hover-initialized').each(function() {
|
|
|
97 |
$(this).dropdownHover();
|
|
|
98 |
$(this).addClass('hover-initialized');
|
|
|
99 |
});
|
|
|
100 |
} else if (width < resBreakpointMd && menu.data('breakpoint') !== 'mobile') {
|
|
|
101 |
menu.data('breakpoint', 'mobile');
|
|
|
102 |
// disable hover bootstrap dropdowns plugin
|
|
|
103 |
$('[data-hover="extended-dropdown"].hover-initialized', menu).each(function() {
|
|
|
104 |
$(this).unbind('hover');
|
|
|
105 |
$(this).parent().unbind('hover').find('.dropdown-submenu').each(function() {
|
|
|
106 |
$(this).unbind('hover');
|
|
|
107 |
});
|
|
|
108 |
$(this).removeClass('hover-initialized');
|
|
|
109 |
});
|
|
|
110 |
}
|
|
|
111 |
};
|
|
|
112 |
|
|
|
113 |
return {
|
|
|
114 |
|
|
|
115 |
// Main init methods to initialize the layout
|
|
|
116 |
// IMPORTANT!!!: Do not modify the core handlers call order.
|
|
|
117 |
|
|
|
118 |
init: function () {
|
|
|
119 |
handleGo2Top();
|
|
|
120 |
handleHeaderOnScroll();
|
|
|
121 |
handleHeaderMenu();
|
|
|
122 |
handleMainMenuOnResize();
|
|
|
123 |
App.addResizeHandler(handleMainMenuOnResize); // handle main menu on window resize
|
|
|
124 |
|
|
|
125 |
// handle minimized header on page scroll
|
|
|
126 |
$(window).scroll(function() {
|
|
|
127 |
handleHeaderOnScroll();
|
|
|
128 |
});
|
|
|
129 |
},
|
|
|
130 |
|
|
|
131 |
getLayoutImgPath: function() {
|
|
|
132 |
return App.getAssetsPath() + layoutImgPath;
|
|
|
133 |
},
|
|
|
134 |
|
|
|
135 |
getLayoutCssPath: function() {
|
|
|
136 |
return App.getAssetsPath() + layoutCssPath;
|
|
|
137 |
}
|
|
|
138 |
};
|
|
|
139 |
|
|
|
140 |
}();
|
|
|
141 |
|
|
|
142 |
jQuery(document).ready(function() {
|
|
|
143 |
Layout.init(); // init metronic core componets
|
|
|
144 |
});
|