Use click to toggle for desktop dropdown menus
Still fall back to hover for nojs. Bug: T211357 Change-Id: I9636a0e3c127173ffb7881c8760d39b715ae475fisekai
parent
a4900353b1
commit
54997f2dfb
@ -1,10 +1,50 @@
|
||||
/**
|
||||
* Timeless-specific scripts
|
||||
* Focus on search box when 'Tab' key is pressed once
|
||||
*/
|
||||
$( function () {
|
||||
$( '#searchInput' ).attr( 'tabindex', $( document ).lastTabIndex() + 1 );
|
||||
} );
|
||||
|
||||
/**
|
||||
* Desktop menu click-toggling
|
||||
*/
|
||||
$( function () {
|
||||
// sidebar-chunk only applies to desktop-small, but the toggles are hidden at
|
||||
// other resolutions regardless and the css overrides any visible effects. So
|
||||
// whatever.
|
||||
var dropdowns = '#personal, #p-variants-desktop, .sidebar-chunk';
|
||||
|
||||
/**
|
||||
* Focus on search box when 'Tab' key is pressed once
|
||||
* Close all dropdowns
|
||||
*/
|
||||
$( '#searchInput' ).attr( 'tabindex', $( document ).lastTabIndex() + 1 );
|
||||
function closeOpen() {
|
||||
$( dropdowns ).each( function () {
|
||||
if ( $( this ).hasClass( 'dropdown-active' ) ) {
|
||||
$( this ).removeClass( 'dropdown-active' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Click behaviour
|
||||
*/
|
||||
$( dropdowns ).on( 'click', function ( e ) {
|
||||
var wasOpen = false;
|
||||
// Check if it's already open so we don't open it again
|
||||
if ( $( this ).hasClass( 'dropdown-active' ) ) {
|
||||
wasOpen = true;
|
||||
}
|
||||
closeOpen();
|
||||
e.stopPropagation(); // stop hiding it!
|
||||
if ( !wasOpen ) {
|
||||
$( this ).addClass( 'dropdown-active' );
|
||||
}
|
||||
} );
|
||||
$( document ).click( function ( e ) {
|
||||
if ( $( e.target ).closest( dropdowns ).length > 0 ) {
|
||||
// Clicked inside an open menu; don't close anything
|
||||
} else {
|
||||
closeOpen();
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
Loading…
Reference in New Issue