page.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const panel = document.getElementById( 'panel' );
  2. const panelScrim = document.getElementById( 'panelScrim' );
  3. const expandButton = document.getElementById( 'expandButton' );
  4. const clearSearchButton = document.getElementById( 'clearSearchButton' );
  5. const filterInput = document.getElementById( 'filterInput' );
  6. // Functionality for hamburger button (on small devices)
  7. expandButton.onclick = function ( event ) {
  8. event.preventDefault();
  9. panel.classList.toggle( 'open' );
  10. };
  11. panelScrim.onclick = function ( event ) {
  12. event.preventDefault();
  13. panel.classList.toggle( 'open' );
  14. };
  15. // Functionality for search/filter input field
  16. filterInput.onfocus = function () {
  17. panel.classList.add( 'searchFocused' );
  18. };
  19. filterInput.onblur = function () {
  20. if ( filterInput.value === '' ) {
  21. panel.classList.remove( 'searchFocused' );
  22. }
  23. };
  24. filterInput.oninput = function () {
  25. const term = filterInput.value.trim();
  26. // eslint-disable-next-line no-undef
  27. search( term ); // defined in search.js
  28. };
  29. clearSearchButton.onclick = function () {
  30. filterInput.value = '';
  31. filterInput.focus();
  32. // eslint-disable-next-line no-undef
  33. hideSearch(); // defined in search.js
  34. };
  35. //
  36. window.addEventListener( 'DOMContentLoaded', updateNavigation );
  37. window.addEventListener( 'hashchange', updateNavigation );
  38. function updateNavigation() {
  39. // unselected elements
  40. const selected = document.querySelectorAll( 'nav a.selected' );
  41. selected.forEach( link => link.classList.remove( 'selected' ) );
  42. // determine target
  43. const filename = window.location.pathname.split( '/' ).pop();
  44. const pagename = filename.split( '.' )[ 0 ];
  45. let target = pagename;
  46. if ( pagename === 'global' ) {
  47. target = window.location.hash.split( '#' ).pop();
  48. }
  49. if ( target === '' ) return;
  50. // select target and move into view
  51. const liElement = document.querySelector( `li[data-name="${target}"]` );
  52. if ( liElement !== null ) {
  53. const aElement = liElement.firstChild;
  54. aElement.scrollIntoView( { block: 'center' } );
  55. aElement.classList.add( 'selected' );
  56. }
  57. }
  58. // eslint-disable-next-line no-undef
  59. prettyPrint();
  60. console.log( [
  61. ' __ __',
  62. ' __/ __\\ / __\\__ ____ _____ _____',
  63. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  64. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  65. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  66. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  67. ' / __/ / \\__ \\',
  68. ' \\/____/\\/_____/'
  69. ].join( '\n' ) );
粤ICP备19079148号