89 lines
2.6 KiB
JavaScript
Executable File
89 lines
2.6 KiB
JavaScript
Executable File
;(function($) {
|
|
|
|
// Init functions
|
|
function init () {
|
|
|
|
utils = {
|
|
|
|
}
|
|
|
|
// Adding class to submenu that has dropdown items
|
|
function submenuFix () {
|
|
var item$ = $('.submenu__item.level-1');
|
|
itemLen = item$.length;
|
|
list$ = item$.find('.submenu__list.level-2');
|
|
|
|
for( var i=0; i<itemLen; i++ ) {
|
|
if( list$.eq(i).find('li').length ) {
|
|
list$
|
|
.eq(i)
|
|
.addClass('dropdown');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Main navigation dropdown
|
|
function dropdown () {
|
|
var navItemLevel1$ = $('.main-nav-item.level-1');
|
|
var dropdownMenu$ = $('.dropdown-menu.level-2');
|
|
|
|
// Adding class if nav item has dropdown
|
|
$(navItemLevel1$)
|
|
.has('.dropdown-menu')
|
|
.children('a')
|
|
.addClass('has-dropdown-menu');
|
|
|
|
// Hide all dropdowns when click on any HTML elements
|
|
$(document).on('click', function() {
|
|
$('.dropdown-menu.level-2')
|
|
.addClass('hide')
|
|
.removeClass('show');
|
|
})
|
|
|
|
// Hide all dropdown after page load
|
|
dropdownMenu$
|
|
.addClass('hide')
|
|
.removeClass('show');
|
|
|
|
|
|
$('.has-dropdown-menu').on('click', function () {
|
|
if( $(this).hasClass('has-dropdown-menu') ) {
|
|
if( $(this).next('.dropdown-menu').hasClass('show') ) {
|
|
dropdownMenu$.addClass('hide');
|
|
$(this)
|
|
.next('.dropdown-menu')
|
|
.removeClass('show')
|
|
.addClass('hide')
|
|
|
|
} else if ( $(this).next('.dropdown-menu').hasClass('hide') ) {
|
|
dropdownMenu$.addClass('hide');
|
|
dropdownMenu$.removeClass('show');
|
|
dropdownMenu$.addClass('hide');
|
|
$(this)
|
|
.next('.dropdown-menu')
|
|
.removeClass('hide')
|
|
.addClass('show')
|
|
}
|
|
}
|
|
|
|
return false;
|
|
})
|
|
}
|
|
|
|
// Targeting Home page
|
|
if( $('body').attr('class') === 'page-main' ) {
|
|
dropdown();
|
|
|
|
// Internal page
|
|
} else {
|
|
submenuFix();
|
|
dropdown();
|
|
}
|
|
}
|
|
|
|
$(document).ready(function($) {
|
|
init();
|
|
});
|
|
|
|
}(jQuery));
|