Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
removed navigation-specific list keyboard handling and ARIA out of li…
Browse files Browse the repository at this point in the history
…stview and over to select, which is the only place it's used. Lists are also now much friendlier to readonly markup - so forms and all of the formatted content previously supported in navigation-based listviews now work without an anchor wrapper.
  • Loading branch information
scottjehl committed Mar 31, 2011
1 parent 57649cd commit 19400af
Showing 1 changed file with 9 additions and 88 deletions.
97 changes: 9 additions & 88 deletions js/jquery.mobile.listview.js
Expand Up @@ -23,92 +23,16 @@ $.widget( "mobile.listview", $.mobile.widget, {

// create listview markup
$list
.addClass( "ui-listview" )
.attr( "role", "listbox" )
.addClass( "ui-listview" );

if ( o.inset ) {
$list.addClass( "ui-listview-inset ui-corner-all ui-shadow" );
}

$list.delegate( ".ui-li", "focusin", function() {
$( this ).attr( "tabindex", "0" );
});
}

this._itemApply( $list, $list );

this.refresh( true );

//keyboard events for menu items
$list.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;

case 39:
var a = li.find( "a.ui-li-link-alt" );

if ( a.length ) {
target.blur();
a.first().focus();
}

return false;
break;

case 37:
var a = li.find( "a.ui-link-inherit" );

if ( a.length ) {
target.blur();
a.first().focus();
}

return false;
break;

// if enter or space is pressed, trigger click
case 13:
case 32:
target.trigger( "vclick" );

return false;
break;
}
});

},

_itemApply: function( $list, item ) {
Expand All @@ -120,9 +44,8 @@ $.widget( "mobile.listview", $.mobile.widget, {

item.find( "p, dl" ).addClass( "ui-li-desc" );

$list.find( "li" ).find( ">img:eq(0), >a:first>img:eq(0)" ).addClass( "ui-li-thumb" ).each(function() {
$( this ).closest( "li" )
.addClass( $(this).is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
$list.find( "li" ).find( ">img:eq(0), >:first>img:eq(0)" ).addClass( "ui-li-thumb" ).each(function() {
$( this ).closest( "li" ).addClass( $(this).is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
});

var aside = item.find( ".ui-li-aside" );
Expand Down Expand Up @@ -158,11 +81,6 @@ $.widget( "mobile.listview", $.mobile.widget, {
$list.find( ".ui-li-dec" ).remove();
}

li.attr({ "role": "option", "tabindex": "-1" });

li.first().attr( "tabindex", "0" );


li.each(function( pos ) {
var item = $( this ),
itemClass = "ui-li";
Expand All @@ -174,11 +92,14 @@ $.widget( "mobile.listview", $.mobile.widget, {

var itemTheme = item.jqmData("theme") || o.theme;

var a = item.find( "a" );
var a = item.find( ">a" );

if ( a.length ) {
var icon = item.jqmData("icon");

//readonly lists need style exceptions
item.not( "li:has(>a)" ).addClass( "ui-li-readonly" );

item
.buttonMarkup({
wrapperEls: "div",
Expand Down Expand Up @@ -229,7 +150,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
}

} else {
itemClass += " ui-li-static ui-btn-up-" + itemTheme;
itemClass += " ui-li-static ui-body-" + itemTheme;
}


Expand Down

0 comments on commit 19400af

Please sign in to comment.