Skip to content

Commit e111bef

Browse files
committed
Demos: Fix search navigation through keyboard
Fixes jquery-archive#8405 Refs jquery-archive#8245
1 parent e839359 commit e111bef

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

demos/_assets/css/jqm-demos.css

+4
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,10 @@ li.jqm-3rd-party .ui-listview-item-button::before {
968968
color: #333;
969969
}
970970

971+
.jqm-search-list.ui-listview > .ui-listview-item-active {
972+
background-color: #eee;
973+
}
974+
971975
.jqm-search-list.ui-listview > .ui-listview-item > .ui-listview-item-button:focus {
972976
-webkit-box-shadow: inset 0 0 1px #0e82a5;
973977
-moz-box-shadow: inset 0 0 1px #0e82a5;

demos/_assets/js/jqm-demos.js

+19-31
Original file line numberDiff line numberDiff line change
@@ -315,24 +315,28 @@ $( document ).on( "mobileinit", function() {
315315
input = this.element.prev("form").find( "input" );
316316

317317
if ( e.which === $.ui.keyCode.DOWN ) {
318-
if ( this.element.find( "li.ui-button-active" ).length === 0 ) {
319-
this.element.find( "li:first" ).toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
318+
if ( this.element.find( "li.ui-listview-item-active" ).length === 0 ) {
319+
this.element.find( "li:not('.ui-screen-hidden'):first" ).toggleClass( "ui-listview-item-active" )
320+
.find("a").toggleClass( "ui-button-active" );
320321
} else {
321-
this.element.find( "li.ui-button-active a" ).toggleClass( "ui-button-active");
322-
this.element.find( "li.ui-button-active" ).toggleClass( "ui-button-active" ).next().toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
322+
this.element.find( "li.ui-listview-item-active a" ).toggleClass( "ui-button-active");
323+
this.element.find( "li.ui-listview-item-active" ).toggleClass( "ui-listview-item-active" )
324+
.nextAll("li:not('.ui-screen-hidden'):first").toggleClass( "ui-listview-item-active" )
325+
.find("a").toggleClass( "ui-button-active" );
323326
}
324-
325-
this.highlightDown();
326327
} else if ( e.which === $.ui.keyCode.UP ) {
327-
if ( this.element.find( "li.ui-button-active" ).length !== 0 ) {
328-
this.element.find( "li.ui-button-active a" ).toggleClass( "ui-button-active");
329-
this.element.find( "li.ui-button-active" ).toggleClass( "ui-button-active" ).prev().toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
328+
if ( this.element.find( "li.ui-listview-item-active" ).length !== 0 ) {
329+
this.element.find( "li.ui-listview-item-active a" ).toggleClass( "ui-button-active");
330+
this.element.find( "li.ui-listview-item-active" ).toggleClass( "ui-listview-item-active" )
331+
.prevAll("li:not('.ui-screen-hidden'):first").toggleClass( "ui-listview-item-active" )
332+
.find("a").toggleClass( "ui-button-active" );
330333
} else {
331-
this.element.find( "li:last" ).toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
334+
this.element.find( "li:not('.ui-screen-hidden'):last" ).toggleClass( "ui-listview-item-active" ).find("a").toggleClass( "ui-button-active" );
332335
}
333-
this.highlightUp();
334-
} else if ( typeof e.which !== "undefined" ) {
335-
this.element.find( "li.ui-button-active" ).removeClass( "ui-button-active" );
336+
} else if ( e.which === $.ui.keyCode.ENTER ) {
337+
this.submitHandler();
338+
}else if ( typeof e.which !== "undefined" ) {
339+
this.element.find( "li.ui-listview-item-active" ).removeClass( "ui-listview-item-active" );
336340

337341
if ( this.options.highlight ) {
338342
search = input.val();
@@ -345,8 +349,8 @@ $( document ).on( "mobileinit", function() {
345349
}
346350
},
347351
submitHandler: function() {
348-
if ( this.element.find( "li.ui-button-active" ).length !== 0 ) {
349-
var href = this.element.find( "li.ui-button-active a" ).attr( "href" );
352+
if ( this.element.find( "li.ui-listview-item-active" ).length !== 0 ) {
353+
var href = this.element.find( "li.ui-listview-item-active a" ).attr( "href" );
350354

351355
$( ":mobile-pagecontainer" ).pagecontainer( "change", href );
352356
return false;
@@ -355,22 +359,6 @@ $( document ).on( "mobileinit", function() {
355359
if ( this.options.submitTo ) {
356360
this.submitTo();
357361
}
358-
},
359-
highlightDown: function() {
360-
if ( this.element.find( "li.ui-button-active" ).hasClass( "ui-screen-hidden" ) ) {
361-
this.element.find( "li.ui-button-active" ).find("a").toggleClass( "ui-button-active" );
362-
this.element.find( "li.ui-button-active" ).toggleClass( "ui-button-active" ).next().toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
363-
this.highlightDown();
364-
}
365-
return;
366-
},
367-
highlightUp: function() {
368-
if ( this.element.find( "li.ui-button-active" ).hasClass( "ui-screen-hidden" ) ) {
369-
this.element.find( "li.ui-button-active" ).find("a").toggleClass( "ui-button-active" );
370-
this.element.find( "li.ui-button-active" ).toggleClass( "ui-button-active" ).prev().toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
371-
this.highlightUp();
372-
}
373-
return;
374362
}
375363
});
376364
})( jQuery );

0 commit comments

Comments
 (0)