Skip to content

Commit 4e6f819

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

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-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

+31-31
Original file line numberDiff line numberDiff line change
@@ -315,24 +315,40 @@ $( 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" )
320+
.toggleClass( "ui-listview-item-active" )
321+
.find("a").toggleClass( "ui-button-active" );
320322
} 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" );
323+
this.element.find( "li.ui-listview-item-active a" )
324+
.toggleClass( "ui-button-active");
325+
326+
this.element.find( "li.ui-listview-item-active" )
327+
.toggleClass( "ui-listview-item-active" )
328+
.nextAll("li:not('.ui-screen-hidden'):first")
329+
.toggleClass( "ui-listview-item-active" )
330+
.find("a").toggleClass( "ui-button-active" );
323331
}
324-
325-
this.highlightDown();
326332
} 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" );
333+
if ( this.element.find( "li.ui-listview-item-active" ).length !== 0 ) {
334+
this.element.find( "li.ui-listview-item-active a" )
335+
.toggleClass( "ui-button-active");
336+
337+
this.element.find( "li.ui-listview-item-active" )
338+
.toggleClass( "ui-listview-item-active" )
339+
.prevAll("li:not('.ui-screen-hidden'):first")
340+
.toggleClass( "ui-listview-item-active" )
341+
.find("a").toggleClass( "ui-button-active" );
330342
} else {
331-
this.element.find( "li:last" ).toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
343+
this.element.find( "li:not('.ui-screen-hidden'):last" )
344+
.toggleClass( "ui-listview-item-active" )
345+
.find("a").toggleClass( "ui-button-active" );
332346
}
333-
this.highlightUp();
334-
} else if ( typeof e.which !== "undefined" ) {
335-
this.element.find( "li.ui-button-active" ).removeClass( "ui-button-active" );
347+
} else if ( e.which === $.ui.keyCode.ENTER ) {
348+
this.submitHandler();
349+
}else if ( typeof e.which !== "undefined" ) {
350+
this.element.find( "li.ui-listview-item-active" )
351+
.removeClass( "ui-listview-item-active" );
336352

337353
if ( this.options.highlight ) {
338354
search = input.val();
@@ -345,8 +361,8 @@ $( document ).on( "mobileinit", function() {
345361
}
346362
},
347363
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" );
364+
if ( this.element.find( "li.ui-listview-item-active" ).length !== 0 ) {
365+
var href = this.element.find( "li.ui-listview-item-active a" ).attr( "href" );
350366

351367
$( ":mobile-pagecontainer" ).pagecontainer( "change", href );
352368
return false;
@@ -355,22 +371,6 @@ $( document ).on( "mobileinit", function() {
355371
if ( this.options.submitTo ) {
356372
this.submitTo();
357373
}
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;
374374
}
375375
});
376376
})( jQuery );

0 commit comments

Comments
 (0)