Skip to content

Commit

Permalink
Now ignoring keystrokes modifed by the control, alt and meta keys
Browse files Browse the repository at this point in the history
  • Loading branch information
pjackson28 committed Mar 18, 2014
1 parent 9101955 commit b8f4223
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 260 deletions.
301 changes: 152 additions & 149 deletions src/plugins/menu/menu.js
Expand Up @@ -574,181 +574,184 @@ $document.on( "keydown", selector + " [role=menuitem]", function( event ) {
$menuLink, $parentMenu, $parent, $subMenu, result,
menuitemSelector, isOpen, menuItemOffsetTop, menuContainer;

// Tab key = Hide all sub-menus
if ( which === 9 ) {
menuClose( $( selector + " .active" ), true );

// Menu item is within a menu bar
} else if ( inMenuBar ) {

// Left / right arrow = Previous / next menu item
if ( which === 37 || which === 39 ) {
event.preventDefault();
menuIncrement(
$menu.find( "> li > a" ),
$menuItem,
which === 37 ? -1 : 1
);

// Enter sub-menu
} else if ( hasPopup && ( which === 13 || which === 38 || which === 40 ) ) {
event.preventDefault();
$parent = $menuItem.parent();
$subMenu = $parent.find( ".sm" );

// Open the submenu if it is not already open
if ( !$subMenu.hasClass( "open" ) ) {
menuDisplay( $menu.closest( selector ), $parent );
}
if ( !( event.ctrlKey || event.altKey || event.metaKey ) ) {

// Set focus on the first submenu item
$subMenu.find( "a:first" ).trigger( focusEvent );

// Hide sub-menus and set focus
} else if ( which === 27 ) {
event.preventDefault();
menuClose( $menu.closest( selector ).find( ".active" ), false );

// Letters only
} else if ( which > 64 && which < 91 ) {
event.preventDefault();
selectByLetter(
which,
$menuItem.parent().find( "> ul > li > a" ).get()
);
}
// Tab key = Hide all sub-menus
if ( which === 9 ) {
menuClose( $( selector + " .active" ), true );

// Menu item is not within a menu bar
} else {
menuitemSelector = "> a, > details > summary";

// Up / down arrow = Previous / next menu item
if ( which === 38 || which === 40 ) {
event.preventDefault();
menuIncrement(
$menu.children( "li" ).find( menuitemSelector ),
$menuItem,
which === 38 ? -1 : 1
);

// Enter or right arrow with a submenu
} else if ( hasPopup && ( which === 13 || which === 39 ) ) {
$parent = $menuItem.parent();

if ( which === 39 ) {
// Menu item is within a menu bar
} else if ( inMenuBar ) {

// Left / right arrow = Previous / next menu item
if ( which === 37 || which === 39 ) {
event.preventDefault();
}
menuIncrement(
$menu.find( "> li > a" ),
$menuItem,
which === 37 ? -1 : 1
);

// If the menu item is a summary element
if ( menuItem.nodeName.toLowerCase( "summary" ) ) {
isOpen = !!$parent.attr( "open" );

// Close any other open menus
if ( !isOpen ) {
$( parent )
.closest( "[role^='menu']" )
.find( "[aria-hidden=false]" )
.parent()
.find( "[aria-haspopup=true]" )
.not( menuItem )
.trigger( "click" );

// Ensure the opened menu is in view if in a mobile panel
menuContainer = document.getElementById( "mb-pnl" );
menuItemOffsetTop = menuItem.offsetTop;
if ( $.contains( menuContainer, menuItem ) &&
menuItemOffsetTop < menuContainer.scrollTop ) {

menuContainer.scrollTop = menuItemOffsetTop;
}
}
// Enter sub-menu
} else if ( hasPopup && ( which === 13 || which === 38 || which === 40 ) ) {
event.preventDefault();
$parent = $menuItem.parent();
$subMenu = $parent.find( ".sm" );

// Ensure the menu is opened or stays open
if ( ( !isOpen && which === 39 ) || ( isOpen && which === 13 ) ) {
$menuItem.trigger( "click" );
// Open the submenu if it is not already open
if ( !$subMenu.hasClass( "open" ) ) {
menuDisplay( $menu.closest( selector ), $parent );
}

// Update the WAI-ARIA states and move focus to
// the first submenu item
$parent.children( "ul" )
.attr({
"aria-expanded": "true",
"aria-hidden": "false"
})
.find( "[role=menuitem]:first" )
.trigger( "setfocus.wb" );
}
// Set focus on the first submenu item
$subMenu.find( "a:first" ).trigger( focusEvent );

// Escape, left / right arrow without a submenu
} else if ( which === 27 || which === 37 || which === 39 ) {
$parent = $menu.parent();
$parentMenu = $parent.closest( "[role^='menu']" );
if ( which === 37 || which === 39 ) {
// Hide sub-menus and set focus
} else if ( which === 27 ) {
event.preventDefault();
menuClose( $menu.closest( selector ).find( ".active" ), false );

// Letters only
} else if ( which > 64 && which < 91 ) {
event.preventDefault();
selectByLetter(
which,
$menuItem.parent().find( "> ul > li > a" ).get()
);
}

// If the parent menu is a menubar
if ( $parentMenu.attr( "role" ) === "menubar" ) {
$menuLink = $parent.children( "[href=#" + $menu.attr( "id" ) + "]" );
// Menu item is not within a menu bar
} else {
menuitemSelector = "> a, > details > summary";

// Up / down arrow = Previous / next menu item
if ( which === 38 || which === 40 ) {
event.preventDefault();
menuIncrement(
$menu.children( "li" ).find( menuitemSelector ),
$menuItem,
which === 38 ? -1 : 1
);

// Enter or right arrow with a submenu
} else if ( hasPopup && ( which === 13 || which === 39 ) ) {
$parent = $menuItem.parent();

// Escape key = Close menu and return to menu bar item
if ( which === 27 ) {
if ( which === 39 ) {
event.preventDefault();
$menuLink.trigger( focusEvent );

// Close the menu but keep the referring link active
setTimeout(function() {
menuClose( $menuLink.parent(), false );
}, 1 );

// Left / right key = Next / previous menu bar item
} else if ( $parentMenu.attr( "role" ) === "menubar" ) {
menuIncrement(
$parentMenu.find( "> li > a" ),
$menuLink,
which === 37 ? -1 : 1
);
}

// Escape or left arrow: Go up a level if there is a higher-level
// menu or close the current submenu if there isn't
} else if ( which !== 39 ) {
$subMenu = $parentMenu.length !== 0 ? $menu : $menuItem;
// If the menu item is a summary element
if ( menuItem.nodeName.toLowerCase( "summary" ) ) {
isOpen = !!$parent.attr( "open" );

// Close any other open menus
if ( !isOpen ) {
$( parent )
.closest( "[role^='menu']" )
.find( "[aria-hidden=false]" )
.parent()
.find( "[aria-haspopup=true]" )
.not( menuItem )
.trigger( "click" );

// Ensure the opened menu is in view if in a mobile panel
menuContainer = document.getElementById( "mb-pnl" );
menuItemOffsetTop = menuItem.offsetTop;
if ( $.contains( menuContainer, menuItem ) &&
menuItemOffsetTop < menuContainer.scrollTop ) {

menuContainer.scrollTop = menuItemOffsetTop;
}
}

// There is a higher-level menu
if ( $parentMenu.length !== 0 ) {
event.preventDefault();
$menu.closest( "li" )
.find( menuitemSelector )
.trigger( "click" )
// Ensure the menu is opened or stays open
if ( ( !isOpen && which === 39 ) || ( isOpen && which === 13 ) ) {
$menuItem.trigger( "click" );
}

// Update the WAI-ARIA states and move focus to
// the first submenu item
$parent.children( "ul" )
.attr({
"aria-expanded": "true",
"aria-hidden": "false"
})
.find( "[role=menuitem]:first" )
.trigger( "setfocus.wb" );
}

// No higher-level menu but the current submenu is open
} else if ( $menuItem.parent().children( "ul" ).attr( "aria-hidden" ) === "false" ) {
// Escape, left / right arrow without a submenu
} else if ( which === 27 || which === 37 || which === 39 ) {
$parent = $menu.parent();
$parentMenu = $parent.closest( "[role^='menu']" );
if ( which === 37 || which === 39 ) {
event.preventDefault();
$menuItem
.trigger( "click" )
.trigger( "setfocus.wb" );
}
}

// Select a menu item in the current menu by the first letter
} else if ( which > 64 && which < 91 ) {
event.preventDefault();
$parent = $menuItem.closest( "li" );
// If the parent menu is a menubar
if ( $parentMenu.attr( "role" ) === "menubar" ) {
$menuLink = $parent.children( "[href=#" + $menu.attr( "id" ) + "]" );

// Escape key = Close menu and return to menu bar item
if ( which === 27 ) {
event.preventDefault();
$menuLink.trigger( focusEvent );

// Close the menu but keep the referring link active
setTimeout(function() {
menuClose( $menuLink.parent(), false );
}, 1 );

// Left / right key = Next / previous menu bar item
} else if ( $parentMenu.attr( "role" ) === "menubar" ) {
menuIncrement(
$parentMenu.find( "> li > a" ),
$menuLink,
which === 37 ? -1 : 1
);
}

// Escape or left arrow: Go up a level if there is a higher-level
// menu or close the current submenu if there isn't
} else if ( which !== 39 ) {
$subMenu = $parentMenu.length !== 0 ? $menu : $menuItem;

// There is a higher-level menu
if ( $parentMenu.length !== 0 ) {
event.preventDefault();
$menu.closest( "li" )
.find( menuitemSelector )
.trigger( "click" )
.trigger( "setfocus.wb" );

// No higher-level menu but the current submenu is open
} else if ( $menuItem.parent().children( "ul" ).attr( "aria-hidden" ) === "false" ) {
event.preventDefault();
$menuItem
.trigger( "click" )
.trigger( "setfocus.wb" );
}
}

// Try to find a match in the next siblings
result = selectByLetter(
which,
$parent.nextAll().find( menuitemSelector ).get()
);
// Select a menu item in the current menu by the first letter
} else if ( which > 64 && which < 91 ) {
event.preventDefault();
$parent = $menuItem.closest( "li" );

// If couldn't find a match, try the previous siblings
if ( !result ) {
// Try to find a match in the next siblings
result = selectByLetter(
which,
$parent.prevAll().find( menuitemSelector ).get()
$parent.nextAll().find( menuitemSelector ).get()
);

// If couldn't find a match, try the previous siblings
if ( !result ) {
result = selectByLetter(
which,
$parent.prevAll().find( menuitemSelector ).get()
);
}
}
}
}
Expand Down
47 changes: 25 additions & 22 deletions src/plugins/multimedia/multimedia.js
Expand Up @@ -784,37 +784,40 @@ $document.on( "keydown", selector, function( event ) {
$this = ref[ 0 ],
volume = 0;

switch ( which ) {
case 32:
$this.find( ctrls + " .playpause" ).trigger( "click" );
break;
if ( !( event.ctrlKey || event.altKey || event.metaKey ) ) {
switch ( which ) {
case 32:
$this.find( ctrls + " .playpause" ).trigger( "click" );
break;

case 37:
$this.find( ctrls + " .rewind" ).trigger( "click" );
break;
case 37:
$this.find( ctrls + " .rewind" ).trigger( "click" );
break;

case 39:
$this.find( ctrls + " .fastforward" ).trigger( "click" );
break;
case 39:
$this.find( ctrls + " .fastforward" ).trigger( "click" );
break;

case 38:
volume = Math.round( playerTarget.player( "getVolume" ) * 10 ) / 10 + 0.1;
playerTarget.player( "setVolume", volume < 1 ? volume : 1 );
break;
case 38:
volume = Math.round( playerTarget.player( "getVolume" ) * 10 ) / 10 + 0.1;
playerTarget.player( "setVolume", volume < 1 ? volume : 1 );
break;

case 40:
volume = Math.round( playerTarget.player( "getVolume" ) * 10 ) / 10 - 0.1;
playerTarget.player( "setVolume", volume > 0 ? volume : 0 );
break;
case 40:
volume = Math.round( playerTarget.player( "getVolume" ) * 10 ) / 10 - 0.1;
playerTarget.player( "setVolume", volume > 0 ? volume : 0 );
break;

default:
return true;
default:
return true;
}
return false;
}
return false;
});

$document.on( "keyup", selector, function( event ) {
if ( event.which === 32 ) {
if ( event.which === 32 && !( event.ctrlKey || event.altKey || event.metaKey ) ) {

// Allows the spacebar to be used for play/pause without double triggering
return false;
}
Expand Down

0 comments on commit b8f4223

Please sign in to comment.