1
0

page.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. ( function handleLegacyURLs() {
  2. const hash = window.location.hash;
  3. if ( hash.startsWith( '#api/' ) || hash.startsWith( '#examples/' ) ) {
  4. const mappings = {
  5. '3DMLoader': 'Rhino3dmLoader',
  6. 'BufferGeometryUtils': 'module-BufferGeometryUtils',
  7. 'CameraUtils': 'module-CameraUtils',
  8. 'SceneUtils': 'module-SceneUtils',
  9. 'SkeletonUtils': 'module-SkeletonUtils',
  10. 'UniformsUtils': 'module-UniformsUtils',
  11. 'DefaultLoadingManager': 'LoadingManager',
  12. 'Interpolations': 'module-Interpolations',
  13. 'Animation': 'global',
  14. 'BufferAttributeUsage': 'global',
  15. 'Core': 'global',
  16. 'CustomBlendingEquations': 'global',
  17. 'Materials': 'global',
  18. 'Textures': 'global'
  19. };
  20. const parts = hash.split( '/' );
  21. let className = parts[ parts.length - 1 ];
  22. if ( className ) {
  23. if ( className in mappings ) className = mappings[ className ];
  24. window.location.href = `${className}.html`;
  25. }
  26. }
  27. } )();
  28. ( function loadNavigation() {
  29. const navContainer = document.querySelector( '#content nav' );
  30. if ( navContainer ) {
  31. fetch( 'nav.html' )
  32. .then( response => response.text() )
  33. .then( html => {
  34. navContainer.innerHTML = html;
  35. } )
  36. .catch( err => console.error( 'Failed to load navigation:', err ) );
  37. }
  38. } )();
  39. //
  40. const panel = document.getElementById( 'panel' );
  41. const panelScrim = document.getElementById( 'panelScrim' );
  42. const expandButton = document.getElementById( 'expandButton' );
  43. const clearSearchButton = document.getElementById( 'clearSearchButton' );
  44. const filterInput = document.getElementById( 'filterInput' );
  45. // code copy buttons
  46. const elements = document.getElementsByTagName( 'pre' );
  47. for ( let i = 0; i < elements.length; i ++ ) {
  48. const element = elements[ i ];
  49. if ( element.classList.contains( 'linenums' ) === false ) {
  50. addCopyButton( element );
  51. }
  52. }
  53. function addCopyButton( element ) {
  54. const copyButton = document.createElement( 'button' );
  55. copyButton.className = 'copy-btn';
  56. element.appendChild( copyButton );
  57. copyButton.addEventListener( 'click', function () {
  58. const codeContent = element.textContent;
  59. navigator.clipboard.writeText( codeContent ).then( () => {
  60. copyButton.classList.add( 'copied' );
  61. setTimeout( () => {
  62. copyButton.classList.remove( 'copied' );
  63. }, 1000 );
  64. } );
  65. } );
  66. }
  67. // Functionality for hamburger button (on small devices)
  68. expandButton.onclick = function ( event ) {
  69. event.preventDefault();
  70. panel.classList.toggle( 'open' );
  71. };
  72. panelScrim.onclick = function ( event ) {
  73. event.preventDefault();
  74. panel.classList.toggle( 'open' );
  75. };
  76. // Functionality for search/filter input field
  77. filterInput.onfocus = function () {
  78. panel.classList.add( 'searchFocused' );
  79. };
  80. filterInput.onblur = function () {
  81. if ( filterInput.value === '' ) {
  82. panel.classList.remove( 'searchFocused' );
  83. }
  84. };
  85. filterInput.oninput = function () {
  86. const term = filterInput.value.trim();
  87. // eslint-disable-next-line no-undef
  88. search( term ); // defined in search.js
  89. };
  90. clearSearchButton.onclick = function () {
  91. filterInput.value = '';
  92. filterInput.focus();
  93. // eslint-disable-next-line no-undef
  94. hideSearch(); // defined in search.js
  95. };
  96. //
  97. window.addEventListener( 'DOMContentLoaded', updateNavigation );
  98. window.addEventListener( 'hashchange', updateNavigation );
  99. function updateNavigation() {
  100. // unselected elements
  101. const selected = document.querySelectorAll( 'nav a.selected' );
  102. selected.forEach( link => link.classList.remove( 'selected' ) );
  103. // determine target
  104. const filename = window.location.pathname.split( '/' ).pop();
  105. const pagename = filename.split( '.' )[ 0 ];
  106. let target = pagename.replace( 'module-', '' );
  107. if ( pagename === 'global' ) {
  108. target = window.location.hash.split( '#' ).pop();
  109. }
  110. if ( target === '' ) return;
  111. // select target and move into view
  112. const aElement = document.querySelector( `nav a[href="${filename}"], nav a[href="${filename}#${target}"]` );
  113. if ( aElement !== null ) {
  114. aElement.scrollIntoView( { block: 'center' } );
  115. aElement.classList.add( 'selected' );
  116. }
  117. }
  118. // eslint-disable-next-line no-undef
  119. prettyPrint();
  120. console.log( [
  121. ' __ __',
  122. ' __/ __\\ / __\\__ ____ _____ _____',
  123. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  124. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  125. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  126. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  127. ' / __/ / \\__ \\',
  128. ' \\/____/\\/_____/'
  129. ].join( '\n' ) );
  130. // console sandbox
  131. import( '/build/three.module.js' ).then( THREE => {
  132. window.THREE = THREE;
  133. } );
粤ICP备19079148号