Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created November 9, 2017 16:58
Show Gist options
  • Save hellofromtonya/1919653b1f6e1e39ed168c407e7a0e20 to your computer and use it in GitHub Desktop.
Save hellofromtonya/1919653b1f6e1e39ed168c407e7a0e20 to your computer and use it in GitHub Desktop.
Keep submenus open in Beans and UIKit v2
(function ( $ ) {
"use strict";
// Let's wait a little bit to let UIKit do its thang first.
setTimeout( function () {
$( '.tm-beans-keep-open' ).not('uikit-active').each(openSubmenu);
}, 100 );
/**
* Force open the submenu by targeting the submenu <div> container,
* removing the `uk-hidden` class, and then adjusting the CSS to
* show the <div> container.
*
* @returns {boolean}
*/
var openSubmenu = function () {
var $subMenu = $( this ).children( 'div' );
// Skip if there is no submenu.
if ( $subMenu.length == 0 ) {
return true;
}
$subMenu.removeClass( 'uk-hidden' );
$subMenu.css( {
overflow: 'hidden',
height: 'auto',
position: 'relative'
} );
}
})( jQuery );
@hellofromtonya
Copy link
Author

UIKit 2 hides submenus unless you are on the active parent page. Therefore, when on a child page, the submenu is closed. Hmm, that's not a great user experience. Right?

The above jQuery script forces the submenu to stay open. See this post in the Beans Community for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment