120 lines
3.5 KiB
JavaScript
Executable File
120 lines
3.5 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');
|
|
}
|
|
}
|
|
}
|
|
function sitemenuFix () {
|
|
var item$ = $('.sitemenu-item.level-1');
|
|
itemLen = item$.length;
|
|
list$ = item$.find('.sitemenu-list.level-2');
|
|
|
|
for( var i=0; i<itemLen; i++ ) {
|
|
if( list$.eq(i).find('li').length ) {
|
|
list$
|
|
.eq(i)
|
|
.addClass('dropdown');
|
|
}
|
|
}
|
|
}
|
|
function sitemenuFix1 () {
|
|
var item$ = $('.sitemenu-item.level-1.active');
|
|
itemLen = item$.length;
|
|
list$ = item$.find('.sitemenu-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();
|
|
sitemenuFix();
|
|
sitemenuFix1();
|
|
}
|
|
}
|
|
|
|
$(document).ready(function($) {
|
|
init();
|
|
});
|
|
|
|
}(jQuery));
|
|
|
|
|
|
|