( function($) {
var khmerScript = {
initAll: function() {
this.menuShowHide();
this.stickyHeader();
this.menuClick();
},
/**
* Show Hide Mobile Menu
*
* @return void
*/
menuClick: function() {
},
/**
* Show Hide Mobile Menu
*
* @return void
*/
menuShowHide: function() {
var $primary_menu = $('#primary-menu');
var $secondary_menu = $('#primary-menu');
var $first_menu = '';
var $second_menu = '';
if ( $primary_menu.length == 0 && $secondary_menu.length == 0 ) {
return;
} else {
if ( $primary_menu.length ) {
$first_menu = $primary_menu;
}
}
var menu_wrapper = $first_menu.clone().appendTo('#smobile-menu');
if ( $secondary_menu.length ) {
var $second_menu = $secondary_menu.clone().appendTo('#smobile-menu .menu-main-menu-container');
}
$('.icon-toggle').on( 'click', function( e ) {
e.preventDefault();
e.stopPropagation();
if ( ! $('body').hasClass('mobile-menu-active') ) {
$('#primary-site-navigation').addClass('show').removeClass('hide');
$('body').toggleClass('mobile-menu-active');
} else {
khmerScript.callFunctionHideMenu();
}
});
$('#menu-toggle, #menu-close .icon-close').click(function(e) {
e.preventDefault();
e.stopPropagation();
if ( $('body').hasClass('mobile-menu-active') ) {
khmerScript.callFunctionHideMenu();
}
$('.menu-toggle').focus();
});
$('.menu-item-has-children > a, .page_item_has_children > a').wrap('').parent().append('');
$('.menu-item-has-children .sub-arrow, .page_item_has_children .sub-arrow').click(function(e) {
e.preventDefault();
e.stopPropagation();
var subMenuOpen = $(this).hasClass('sub-menu-open');
if ( subMenuOpen ) {
$(this).removeClass('sub-menu-open');
$(this).find('.arrow').removeClass('up').addClass('down');
$(this).parent().next('ul.sub-menu, ul.children').removeClass('active').slideUp();
} else {
$(this).addClass('sub-menu-open');
$(this).find('.arrow').removeClass('down').addClass('up');
$(this).parent().next('ul.sub-menu, ul.children').addClass('active').slideDown();
}
});
},
/**
* Sticky Header
*
* @return void
*/
stickyHeader: function() {
var stickyMenu = $('.sticky-menu');
if( stickyMenu.length ) {
$(window).scroll(function() {
var headerTop = ( $('.bottom-heading').length + 8 ) ? $('.bottom-heading').height() : 0;
if( $(window).scrollTop() > 0 ) {
stickyMenu.addClass('active-sticky');
} else {
stickyMenu.removeClass('active-sticky');
}
});
}
},
callFunctionHideMenu: function() {
jQuery('body').removeClass('mobile-menu-active');
$('#primary-site-navigation').removeClass('show').addClass('hide');
jQuery('html').removeClass('noscroll');
}
};
$( document ).ready(function(e) {
khmerScript.initAll();
});
})(jQuery);