|
11 | 11 | <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.10.0/styles/github.min.css"> |
12 | 12 | <style> |
13 | 13 |
|
| 14 | +input[type="search"]::-webkit-search-cancel-button { |
| 15 | + -webkit-appearance: searchfield-cancel-button; |
| 16 | +} |
| 17 | +
|
14 | 18 | .jumbotron { |
15 | 19 | margin-bottom: 0; |
16 | 20 | border-radius: 0; |
|
182 | 186 |
|
183 | 187 | <div class="col-md-3 hidden-sm hidden-xs"> |
184 | 188 |
|
185 | | - <input type="text" class="form-control search" id="search-methods" placeholder="Search..." autocomplete="off"> |
| 189 | + <input type="search" class="form-control search" id="search-methods" placeholder="Search..." autocomplete="off"> |
186 | 190 |
|
187 | 191 | <ul class="menu"> |
188 | 192 |
|
|
417 | 421 | hljs.highlightBlock(this); |
418 | 422 | }); |
419 | 423 |
|
| 424 | + var $searchInput = $('#search-methods'); |
420 | 425 | var $methodLinks = $('.method-link'); |
| 426 | + var $methodNames = $('.method .method-name'); |
421 | 427 |
|
422 | | - $('#search-methods').on('keyup', function (e) { |
| 428 | + var urlQuery = window.location.search.match(/q=([^&]+)/); |
| 429 | +
|
| 430 | + $searchInput.on('keyup', function (e) { |
423 | 431 |
|
424 | 432 | var query = new RegExp(e.target.value.replace(' ', '|'), 'ig'); |
425 | 433 |
|
|
439 | 447 |
|
440 | 448 | }); |
441 | 449 |
|
| 450 | + $methodNames.each(function () { |
| 451 | +
|
| 452 | + var $this = $(this); |
| 453 | +
|
| 454 | + if (!$this.text().match(query)) { |
| 455 | +
|
| 456 | + $this.closest('.method').hide(); |
| 457 | +
|
| 458 | + } else { |
| 459 | +
|
| 460 | + $this.closest('.method').show(); |
| 461 | +
|
| 462 | + } |
| 463 | +
|
| 464 | + }); |
| 465 | +
|
| 466 | + window.history.replaceState({}, '', window.location.pathname + '?q=' + e.target.value); |
| 467 | +
|
| 468 | + }); |
| 469 | +
|
| 470 | + $searchInput.on('search', function () { |
| 471 | +
|
| 472 | + $searchInput.trigger('keyup'); |
| 473 | +
|
442 | 474 | }); |
443 | 475 |
|
| 476 | + if (urlQuery && urlQuery.length > 1) { |
| 477 | +
|
| 478 | + $searchInput.val(urlQuery[1]).trigger('keyup'); |
| 479 | +
|
| 480 | + } |
| 481 | +
|
444 | 482 | $(window).on('scroll', handleScrollEvent); |
445 | 483 |
|
446 | 484 | handleScrollEvent(); |
|
0 commit comments