moved the listview a11y handling to just selectmenu custom menus, since that's the only place it's now relevant

This commit is contained in:
scottjehl 2011-03-31 16:44:25 -04:00
parent 776e23ee95
commit 57649cd066

View file

@ -205,17 +205,28 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
.focus(function(){
$(this).blur();
button.focus();
});
});
//button events
button
.bind( "vclick" , function( event ){
self.open();
event.preventDefault();
.bind( "vclick keydown" , function( event ){
if( event.type == "vclick" ||
event.keyCode && ( event.keyCode === $.mobile.keyCode.ENTER || event.keyCode === $.mobile.keyCode.SPACE ) ){
self.open();
event.preventDefault();
}
});
//events for list items
list.delegate("li:not(.ui-disabled, .ui-li-divider)", "vclick", function(event){
list
.attr( "role", "listbox" )
.delegate( ".ui-li>a", "focusin", function() {
$( this ).attr( "tabindex", "0" );
})
.delegate( ".ui-li>a", "focusout", function() {
$( this ).attr( "tabindex", "-1" );
})
.delegate("li:not(.ui-disabled, .ui-li-divider)", "vclick", function(event){
// index of option tag to be selected
var oldIndex = select[0].selectedIndex,
@ -244,7 +255,55 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
}
event.preventDefault();
});
})
//keyboard events for menu items
.keydown(function( e ) {
var target = $( e.target ),
li = target.closest( "li" );
// switch logic based on which key was pressed
switch ( e.keyCode ) {
// up or left arrow keys
case 38:
var prev = li.prev();
// if there's a previous option, focus it
if ( prev.length ) {
target
.blur()
.attr( "tabindex", "-1" );
prev.find( "a" ).first().focus();
}
return false;
break;
// down or right arrow keys
case 40:
var next = li.next();
// if there's a next option, focus it
if ( next.length ) {
target
.blur()
.attr( "tabindex", "-1" );
next.find( "a" ).first().focus();
}
return false;
break;
// if enter or space is pressed, trigger click
case 13:
case 32:
target.trigger( "vclick" );
return false;
break;
}
});
//events on "screen" overlay
screen.bind("vclick", function( event ){
@ -309,6 +368,10 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
});
self.list.html( lis.join(" ") );
self.list.find( "li" )
.attr({ "role": "option", "tabindex": "-1" })
.first().attr( "tabindex", "0" );
// hide header close link for single selects
if( !this.isMultiple ){