22window . onload = function ( ) {
33 "use strict" ;
44
5+ var searchedText = "" ;
56 var forceFocusToContent = false ;
67 /* The search result container */
78 var searchResults = document . getElementById ( 'search-results' ) ;
@@ -25,7 +26,9 @@ window.onload = function() {
2526
2627 /* Shows the page mapped to the active <select> item */
2728 var clickToView = function ( evnt ) {
28- evnt . preventDefault ( ) ; // Cancel any submit action
29+ if ( evnt ) {
30+ evnt . preventDefault ( ) ; // Cancel any submit action
31+ }
2932 try {
3033 if ( ! Boolean ( helpTopics . value ) ) // Nothing selected
3134 return ;
@@ -77,12 +80,17 @@ window.onload = function() {
7780 return ;
7881 }
7982
83+ var query = searchBox . value . trim ( ) ;
84+ if ( query === searchedText )
85+ return ;
86+
87+ searchedText = query ;
88+
8089 /* The global 'NPPEXEC_HELP_TOPICS' object is defined in 'topics.js', which *must*
8190 * be loaded before this script
8291 */
8392 var topicIndex = JSON . parse ( JSON . stringify ( NPPEXEC_HELP_TOPICS ) ) ;
8493 /* Compile RegExp from the search string that was just typed */
85- var query = searchBox . value . trim ( ) ;
8694 var queryRE = new RegExp ( '(?:)(' + query . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) + ')\s?' , 'iu' ) ;
8795 /* Collection of objects holding topic metadata */
8896 var foundTopics = [ ] ;
@@ -114,12 +122,14 @@ window.onload = function() {
114122 searchResults . style . display = 'block' ;
115123 /* Min visible size is 2 b/c the <optgroup> label is counted */
116124 helpTopics . size = Math . max ( foundTopics . length + 1 , 2 ) ;
117- /* Make sure mobile <select> boxes are never blank */
118- //helpTopics.selectedIndex = 0;
125+ helpTopics . selectedIndex = - 1 ;
119126 helpTopics . addEventListener ( 'change' , clickToView , { 'passive' : false } ) ;
120- helpTopics . addEventListener ( 'focus' ,
121- /* Selecting the first <option> should *also* fire a 'change' event */
122- function ( ) { if ( this . selectedIndex === 0 ) this . selectedIndex -- } , { 'once' : true } ) ;
127+ helpTopics . addEventListener ( 'focus' , function ( ) {
128+ if ( this . selectedIndex === - 1 ) {
129+ this . selectedIndex = 0 ;
130+ clickToView ( null ) ;
131+ }
132+ } , { 'once' : true } ) ;
123133
124134 var focusContent = function ( evnt ) {
125135 if ( evnt . type === 'dblclick' || evnt . key === 'Enter' || evnt . keyCode === 13 ) {
0 commit comments