(function($) { var $body = $(document.body), $menuToggle = $('#menu-toggle'), $siteNav = $('#menu-container'); $(document).ready(function() { // Scroll to top $('#top-link').on('click', function(e) { $('html, body').animate({'scrollTop': 0}); e.preventDefault(); }); // Toggle header search $("#search-show, #search-hide").on("click", function(e) { e.preventDefault(); if ( $body.hasClass('search--opened') ) { $body.removeClass('search--opened').addClass('search--closing'); setTimeout(function() { $body.removeClass('search--closing'); }, 500); } else { $body.addClass('search--opening'); setTimeout(function() { $body.addClass('search--opened').removeClass('search--opening'); }, 500); $('#search-box').find('.search-field').focus(); } }); // Responsive video embeds $('.entry-content, .widget').fitVids(); // Run Fitvid on Infinite Scroll $(document.body).on('post-load', function () { $('.entry-content').fitVids(); }); // Add dropdown toggle that displays child menu items. var dropdownArrow = $(''); $siteNav.find( '.menu-item-has-children > a, .page_item_has_children > a' ).after(dropdownArrow); $siteNav.find('.dropdown-toggle').click( function(e) { var _this = $(this); e.preventDefault(); _this.toggleClass('toggled--on').attr('aria-expanded', _this.attr('aria-expanded') === 'false' ? 'true' : 'false'); _this.next('.children, .sub-menu').slideToggle(); } ); // Mobile menu $menuToggle.click(function(){ var _this = $(this); _this.toggleClass( 'toggled--on' ).attr('aria-expanded', _this.attr('aria-expanded') === 'false' ? 'true' : 'false'); $siteNav.slideToggle(); }); // Dropdown menu bloginn_menu_dropdown(); $(window).bind('resize orientationchange', function() { bloginn_menu_dropdown(); if ( $menuToggle.is(':hidden') ) { $menuToggle.removeClass('toggled--on').attr('aria-expanded', 'false'); $siteNav.removeAttr('style'); } }); }); function bloginn_menu_dropdown() { var $menuItem = $siteNav.find('li'); $siteNav.find('.sub-menu, .children').removeAttr('style'); $siteNav.find('.dropdown-toggle').removeClass( 'toggled--on' ).attr('aria-expanded', 'false'); if ( $menuToggle.is(':hidden') ) { $menuItem.hover(function(){ $(this).find('ul:first').stop(true, true).slideDown(100); },function(){ $(this).find('ul:first').stop(true, true).slideUp(100); }); } else { $menuItem.unbind('mouseenter mouseleave'); $siteNav.find( '.current-menu-ancestor > .dropdown-toggle, .current_page_ancestor > .dropdown-toggle' ).addClass( 'toggled--on' ).attr('aria-expanded', 'true'); } } })(jQuery);