@@ -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
}
@@ -1281,9 +1294,7 @@ if (!DOMTokenList.prototype.remove) {
1281
1294
} else if ( e . which === 16 ) { // shift
1282
1295
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
1283
1296
} else if ( e . which === 27 ) { // escape
1284
- removeClass ( actives [ currentTab ] [ 0 ] , "highlighted" ) ;
1285
- search_input . value = "" ;
1286
- defocusSearchBar ( ) ;
1297
+ handleEscape ( e ) ;
1287
1298
} else if ( actives [ currentTab ] . length > 0 ) {
1288
1299
removeClass ( actives [ currentTab ] [ 0 ] , "highlighted" ) ;
1289
1300
}
@@ -1434,7 +1445,7 @@ if (!DOMTokenList.prototype.remove) {
1434
1445
ret_others [ 0 ] + ret_in_args [ 0 ] + ret_returned [ 0 ] + "</div>" ;
1435
1446
1436
1447
addClass ( main , "hidden" ) ;
1437
- var search = document . getElementById ( "search" ) ;
1448
+ var search = getSearchElement ( ) ;
1438
1449
removeClass ( search , "hidden" ) ;
1439
1450
search . innerHTML = output ;
1440
1451
var tds = search . getElementsByTagName ( "td" ) ;
@@ -1644,7 +1655,7 @@ if (!DOMTokenList.prototype.remove) {
1644
1655
if ( hasClass ( main , "content" ) ) {
1645
1656
removeClass ( main , "hidden" ) ;
1646
1657
}
1647
- var search_c = document . getElementById ( "search" ) ;
1658
+ var search_c = getSearchElement ( ) ;
1648
1659
if ( hasClass ( search_c , "content" ) ) {
1649
1660
addClass ( search_c , "hidden" ) ;
1650
1661
}
@@ -1691,7 +1702,7 @@ if (!DOMTokenList.prototype.remove) {
1691
1702
if ( hasClass ( main , "content" ) ) {
1692
1703
removeClass ( main , "hidden" ) ;
1693
1704
}
1694
- var search_c = document . getElementById ( "search" ) ;
1705
+ var search_c = getSearchElement ( ) ;
1695
1706
if ( hasClass ( search_c , "content" ) ) {
1696
1707
addClass ( search_c , "hidden" ) ;
1697
1708
}
@@ -2460,7 +2471,7 @@ if (!DOMTokenList.prototype.remove) {
2460
2471
var params = getQueryStringParams ( ) ;
2461
2472
if ( params && params . search ) {
2462
2473
addClass ( main , "hidden" ) ;
2463
- var search = document . getElementById ( "search" ) ;
2474
+ var search = getSearchElement ( ) ;
2464
2475
removeClass ( search , "hidden" ) ;
2465
2476
search . innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>" ;
2466
2477
}
@@ -2545,10 +2556,10 @@ if (!DOMTokenList.prototype.remove) {
2545
2556
2546
2557
// Sets the focus on the search bar at the top of the page
2547
2558
function focusSearchBar ( ) {
2548
- document . getElementsByClassName ( "search-input" ) [ 0 ] . focus ( ) ;
2559
+ getSearchInput ( ) . focus ( ) ;
2549
2560
}
2550
2561
2551
2562
// Removes the focus from the search bar
2552
2563
function defocusSearchBar ( ) {
2553
- document . getElementsByClassName ( "search-input" ) [ 0 ] . blur ( ) ;
2564
+ getSearchInput ( ) . blur ( ) ;
2554
2565
}
0 commit comments