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

Commit 09d917e

Browse files
committed
Demos: Fix search navigation through keyboard
Fixes #8405, #8407 Refs #8245
1 parent 5e95ee0 commit 09d917e

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

demos/_assets/css/jqm-demos.css

+10-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ html body .ui-group-theme-a a:hover {
727727
.jqm-navmenu-panel > .ui-panel-inner > .ui-listview li > .ui-accordion-header:active,
728728
.jqm-navmenu-panel > .ui-panel-inner > .ui-listview li .ui-accordion-content .ui-accordion-header:hover {
729729
color: #333;
730-
text-shadow: 0 1px 0 #f3f3f3;
730+
text-shadow: 0 1px 0 #f3f3f3;
731731
background: #cccccc;
732732
}
733733
.jqm-navmenu-panel > .ui-panel-inner > .ui-listview li .ui-accordion-content li > .ui-listview-item-button:hover {
@@ -977,6 +977,15 @@ li.jqm-3rd-party .ui-listview-item-button::before {
977977
color: #000000;
978978
}
979979

980+
.jqm-search-list.ui-listview > .ui-listview-item-active > .ui-listview-item-button {
981+
background-color: #eee;
982+
color: #000000;
983+
border-top: 0;
984+
border-bottom: 1px solid #eee;
985+
font-weight: 400;
986+
text-shadow: 0 1px 0 #f5f5f5;
987+
}
988+
980989
.jqm-search-list.ui-listview > .ui-listview-item > .ui-listview-item-button:focus {
981990
-webkit-box-shadow: inset 0 0 1px #0e82a5;
982991
-moz-box-shadow: inset 0 0 1px #0e82a5;

demos/_assets/js/jqm-demos.js

+29-35
Original file line numberDiff line numberDiff line change
@@ -312,27 +312,37 @@ $( document ).on( "mobileinit", function() {
312312
},
313313
handleKeyUp: function( e ) {
314314
var search,
315-
input = this.element.prev("form").find( "input" );
316-
317-
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" );
315+
toBeHighlightled,
316+
input = this.element.prev("form").find( "input" ),
317+
isDownKeyUp = e.which === $.ui.keyCode.DOWN,
318+
isUpKeyUp = e.which === $.ui.keyCode.UP;
319+
320+
if ( isDownKeyUp || isUpKeyUp ) {
321+
if ( this.element.find( "li.ui-listview-item-active" ).length === 0 ) {
322+
toBeHighlightled = this.element.find( "li" )
323+
.not( ".ui-screen-hidden" )
324+
[ isDownKeyUp ? "first" : "last" ]();
320325
} 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" );
326+
this.element.find( "li.ui-listview-item-active a" )
327+
.toggleClass( "ui-button-active");
328+
329+
toBeHighlightled = this.element.find( "li.ui-listview-item-active" )
330+
.toggleClass( "ui-listview-item-active" )
331+
[ isDownKeyUp ? "nextAll" : "prevAll" ]( "li" )
332+
.not( ".ui-screen-hidden" )
333+
.first();
323334
}
324335

325-
this.highlightDown();
326-
} 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" );
330-
} else {
331-
this.element.find( "li:last" ).toggleClass( "ui-button-active" ).find("a").toggleClass( "ui-button-active" );
332-
}
333-
this.highlightUp();
336+
// Highlight the selected list item
337+
toBeHighlightled
338+
.toggleClass( "ui-listview-item-active" )
339+
.find( "a" )
340+
.toggleClass( "ui-button-active" );
341+
} else if ( e.which === $.ui.keyCode.ENTER ) {
342+
this.submitHandler();
334343
} else if ( typeof e.which !== "undefined" ) {
335-
this.element.find( "li.ui-button-active" ).removeClass( "ui-button-active" );
344+
this.element.find( "li.ui-listview-item-active" )
345+
.removeClass( "ui-listview-item-active" );
336346

337347
if ( this.options.highlight ) {
338348
search = input.val();
@@ -345,8 +355,8 @@ $( document ).on( "mobileinit", function() {
345355
}
346356
},
347357
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" );
358+
if ( this.element.find( "li.ui-listview-item-active" ).length !== 0 ) {
359+
var href = this.element.find( "li.ui-listview-item-active a" ).attr( "href" );
350360

351361
$( ":mobile-pagecontainer" ).pagecontainer( "change", href );
352362
return false;
@@ -355,22 +365,6 @@ $( document ).on( "mobileinit", function() {
355365
if ( this.options.submitTo ) {
356366
this.submitTo();
357367
}
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;
374368
}
375369
});
376370
})( jQuery );

0 commit comments

Comments
 (0)