Reply To: collapsibleBehavior: accordion BUT if link is only # (hash) open the child

Home Forums Latest release 1.1.x collapsibleBehavior: accordion BUT if link is only # (hash) open the child Reply To: collapsibleBehavior: accordion BUT if link is only # (hash) open the child

#3721
carasmo
Participant

That works great!

Here’s the final js to do the following:

-Keep open on current url
-If parent only an # toggle the children and close on click
-If link is a link go to the url

Also checked that the aria labels worked and they do!

You are amazing — thank you so much.




//__ SmartMenus.org args
var $primary_menu = $('.menu-secondary');

//__ keep open on current
$primary_menu.smartmenus( 'itemActivate', $primary_menu.find( 'a.current' ).eq( -1 ) );

/* 
 * if parent is a #, toggle children
 * if parent is a #, toggling the title closes children
 * if parent is a link, go to url on first click
*/
$primary_menu.smartmenus( {
    subMenusMinWidth:    '250px',
    showTimeout:         '300',
    markCurrentItem:     true,
    collapsibleBehavior: 'accordion-link',
    hideOnClick:         false
    
} ).on( 'select.smapi', function( e, item ) {
    
    var obj   = $(this).data( 'smartmenus' ),
        $item = $(item);
        
    if ( obj.isCollapsible() && $item.is('[href="#"]') ) {
        var $sub = $item.dataSM( 'sub' );
        if ( $sub && !$sub.is( ':visible') ) {
            obj.itemActivate( $item, true );
        }
        return false;
    }
} ).bind('click.smapi', function( e, item ) {

    var obj = $( this ).data( 'smartmenus' );
    
    if ( obj.isCollapsible() ) {
        var $sub = $( item ).dataSM( 'sub' );
        if ( $sub && $sub.is( ':visible' ) ) {
            obj.menuHide( $sub );
            return false;
        }
    }
} );

Register

You will be emailed a link to set your password.

Login

Lost password?