@@ -39,6 +39,14 @@ if (!DOMTokenList.prototype.remove) {
39
39
} ;
40
40
}
41
41
42
+ function getSearchInput ( ) {
43
+ return document . getElementsByClassName ( "search-input" ) [ 0 ] ;
44
+ }
45
+
46
+ function getSearchElement ( ) {
47
+ return document . getElementById ( "search" ) ;
48
+ }
49
+
42
50
( function ( ) {
43
51
"use strict" ;
44
52
@@ -71,7 +79,7 @@ if (!DOMTokenList.prototype.remove) {
71
79
"derive" ,
72
80
"traitalias" ] ;
73
81
74
- var search_input = document . getElementsByClassName ( "search-input" ) [ 0 ] ;
82
+ var search_input = getSearchInput ( ) ;
75
83
76
84
// On the search screen, so you remain on the last tab you opened.
77
85
//
@@ -158,7 +166,7 @@ if (!DOMTokenList.prototype.remove) {
158
166
// If we're in mobile mode, we should add the sidebar in any case.
159
167
hideSidebar ( ) ;
160
168
var elem ;
161
- var search = document . getElementById ( "search" ) ;
169
+ var search = getSearchElement ( ) ;
162
170
var i , from , to , match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
163
171
if ( match ) {
164
172
from = parseInt ( match [ 1 ] , 10 ) ;
@@ -250,7 +258,12 @@ if (!DOMTokenList.prototype.remove) {
250
258
return String . fromCharCode ( c ) ;
251
259
}
252
260
261
+ function getHelpElement ( ) {
262
+ return document . getElementById ( "help" ) ;
263
+ }
264
+
253
265
function displayHelp ( display , ev , help ) {
266
+ var help = help ? help : getHelpElement ( ) ;
254
267
if ( display === true ) {
255
268
if ( hasClass ( help , "hidden" ) ) {
256
269
ev . preventDefault ( ) ;
@@ -264,9 +277,10 @@ if (!DOMTokenList.prototype.remove) {
264
277
}
265
278
}
266
279
267
- function handleEscape ( ev , help ) {
280
+ function handleEscape ( ev ) {
281
+ var help = getHelpElement ( ) ;
282
+ var search = getSearchElement ( ) ;
268
283
hideModal ( ) ;
269
- var search = document . getElementById ( "search" ) ;
270
284
if ( hasClass ( help , "hidden" ) === false ) {
271
285
displayHelp ( false , ev , help ) ;
272
286
} else if ( hasClass ( search , "hidden" ) === false ) {
@@ -284,22 +298,21 @@ if (!DOMTokenList.prototype.remove) {
284
298
return ;
285
299
}
286
300
287
- var help = document . getElementById ( "help" ) ;
288
301
if ( document . activeElement . tagName === "INPUT" ) {
289
302
switch ( getVirtualKey ( ev ) ) {
290
303
case "Escape" :
291
- handleEscape ( ev , help ) ;
304
+ handleEscape ( ev ) ;
292
305
break ;
293
306
}
294
307
} else {
295
308
switch ( getVirtualKey ( ev ) ) {
296
309
case "Escape" :
297
- handleEscape ( ev , help ) ;
310
+ handleEscape ( ev ) ;
298
311
break ;
299
312
300
313
case "s" :
301
314
case "S" :
302
- displayHelp ( false , ev , help ) ;
315
+ displayHelp ( false , ev ) ;
303
316
hideModal ( ) ;
304
317
ev . preventDefault ( ) ;
305
318
focusSearchBar ( ) ;
@@ -314,7 +327,7 @@ if (!DOMTokenList.prototype.remove) {
314
327
case "?" :
315
328
if ( ev . shiftKey ) {
316
329
hideModal ( ) ;
317
- displayHelp ( true , ev , help ) ;
330
+ displayHelp ( true , ev ) ;
318
331
}
319
332
break ;
320
333
}
@@ -1285,9 +1298,7 @@ if (!DOMTokenList.prototype.remove) {
1285
1298
} else if ( e . which === 16 ) { // shift
1286
1299
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
1287
1300
} else if ( e . which === 27 ) { // escape
1288
- removeClass ( actives [ currentTab ] [ 0 ] , "highlighted" ) ;
1289
- search_input . value = "" ;
1290
- defocusSearchBar ( ) ;
1301
+ handleEscape ( e ) ;
1291
1302
} else if ( actives [ currentTab ] . length > 0 ) {
1292
1303
removeClass ( actives [ currentTab ] [ 0 ] , "highlighted" ) ;
1293
1304
}
@@ -1438,7 +1449,7 @@ if (!DOMTokenList.prototype.remove) {
1438
1449
ret_others [ 0 ] + ret_in_args [ 0 ] + ret_returned [ 0 ] + "</div>" ;
1439
1450
1440
1451
addClass ( main , "hidden" ) ;
1441
- var search = document . getElementById ( "search" ) ;
1452
+ var search = getSearchElement ( ) ;
1442
1453
removeClass ( search , "hidden" ) ;
1443
1454
search . innerHTML = output ;
1444
1455
var tds = search . getElementsByTagName ( "td" ) ;
@@ -1648,7 +1659,7 @@ if (!DOMTokenList.prototype.remove) {
1648
1659
if ( hasClass ( main , "content" ) ) {
1649
1660
removeClass ( main , "hidden" ) ;
1650
1661
}
1651
- var search_c = document . getElementById ( "search" ) ;
1662
+ var search_c = getSearchElement ( ) ;
1652
1663
if ( hasClass ( search_c , "content" ) ) {
1653
1664
addClass ( search_c , "hidden" ) ;
1654
1665
}
@@ -1695,7 +1706,7 @@ if (!DOMTokenList.prototype.remove) {
1695
1706
if ( hasClass ( main , "content" ) ) {
1696
1707
removeClass ( main , "hidden" ) ;
1697
1708
}
1698
- var search_c = document . getElementById ( "search" ) ;
1709
+ var search_c = getSearchElement ( ) ;
1699
1710
if ( hasClass ( search_c , "content" ) ) {
1700
1711
addClass ( search_c , "hidden" ) ;
1701
1712
}
@@ -2464,7 +2475,7 @@ if (!DOMTokenList.prototype.remove) {
2464
2475
var params = getQueryStringParams ( ) ;
2465
2476
if ( params && params . search ) {
2466
2477
addClass ( main , "hidden" ) ;
2467
- var search = document . getElementById ( "search" ) ;
2478
+ var search = getSearchElement ( ) ;
2468
2479
removeClass ( search , "hidden" ) ;
2469
2480
search . innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>" ;
2470
2481
}
@@ -2549,10 +2560,10 @@ if (!DOMTokenList.prototype.remove) {
2549
2560
2550
2561
// Sets the focus on the search bar at the top of the page
2551
2562
function focusSearchBar ( ) {
2552
- document . getElementsByClassName ( "search-input" ) [ 0 ] . focus ( ) ;
2563
+ getSearchInput ( ) . focus ( ) ;
2553
2564
}
2554
2565
2555
2566
// Removes the focus from the search bar
2556
2567
function defocusSearchBar ( ) {
2557
- document . getElementsByClassName ( "search-input" ) [ 0 ] . blur ( ) ;
2568
+ getSearchInput ( ) . blur ( ) ;
2558
2569
}
0 commit comments