( function($) { var khmerScript = { initAll: function() { this.focusMenuWithChildren(); this.menuShowHide(); this.loadingBar(); this.stickyHeader(); }, /** * Tab Focus Child Menu * * @return void */ focusMenuWithChildren: function() { // Get all the link elements within the primary menu. var links, i, len, menu = document.querySelector( '#primary-site-navigation' ); if ( ! menu ) { return false; } links = menu.getElementsByTagName( 'a' ); // Each time a menu link is focused or blurred, toggle focus. for ( i = 0, len = links.length; i < len; i++ ) { links[i].addEventListener( 'focus', toggleFocus, true ); links[i].addEventListener( 'blur', toggleFocus, true ); } //Sets or removes the .focus class on an element. function toggleFocus() { var self = this; // Move up through the ancestors of the current link until we hit .primary-menu. while ( -1 === self.className.indexOf( 'pmenu' ) ) { // On li elements toggle the class .focus. if ( 'li' === self.tagName.toLowerCase() ) { if ( -1 !== self.className.indexOf( 'focus' ) ) { self.className = self.className.replace( ' focus', '' ); } else { self.className += ' focus'; } } self = self.parentElement; } } }, /** * 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') ) { $('#smobile-menu').addClass('show').removeClass('hide'); $('body').toggleClass('mobile-menu-active'); } else { khmerScript.callFunctionHideMenu(); } $(this).blur(); $('#smobile-menu .icon-toggle').focus(); }); $('#menu-close, #menu-close .icon-close, #mobile-menu-overlay').click(function(e) { e.preventDefault(); e.stopPropagation(); if ( $('body').hasClass('mobile-menu-active') ) { khmerScript.callFunctionHideMenu(); } $('.menu-toggle').focus(); }); $('').insertAfter($('.menu-item-has-children > a')); $('.menu-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('i').removeClass('fa-angle-up').addClass('fa-angle-down'); $(this).next('ul.sub-menu, ul.children').removeClass('active').slideUp(); } else { $(this).addClass('sub-menu-open'); $(this).find('i').removeClass('fa-angle-down').addClass('fa-angle-up'); $(this).next('ul.sub-menu, ul.children').addClass('active').slideDown(); } }); }, /** * Loading Bar * * @return void */ loadingBar: function() { $(window).scroll(function() { var s = $(window).scrollTop(); var d = $(document).height(); var c = $(window).height(); var scrollPercent = (s / (d-c)) * 100; var position = scrollPercent; $('.progressing').css('width', position + '%'); }); }, /** * 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'); $('#smobile-menu').removeClass('show').addClass('hide'); jQuery('#mobile-menu-overlay').fadeOut(); jQuery('html').removeClass('noscroll'); } }; $( document ).ready(function(e) { khmerScript.initAll(); }).on('click', function( event ) { //khmerScript.callFunctionHideMenu(); }); })(jQuery);