| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- ( function handleLegacyURLs() {
- const hash = window.location.hash;
- if ( hash.startsWith( '#api/' ) || hash.startsWith( '#examples/' ) ) {
- const mappings = {
- '3DMLoader': 'Rhino3dmLoader',
- 'BufferGeometryUtils': 'module-BufferGeometryUtils',
- 'CameraUtils': 'module-CameraUtils',
- 'SceneUtils': 'module-SceneUtils',
- 'SkeletonUtils': 'module-SkeletonUtils',
- 'UniformsUtils': 'module-UniformsUtils',
- 'DefaultLoadingManager': 'LoadingManager',
- 'Interpolations': 'module-Interpolations',
- 'Animation': 'global',
- 'BufferAttributeUsage': 'global',
- 'Core': 'global',
- 'CustomBlendingEquations': 'global',
- 'Materials': 'global',
- 'Textures': 'global'
- };
- const parts = hash.split( '/' );
- let className = parts[ parts.length - 1 ];
- if ( className ) {
- if ( className in mappings ) className = mappings[ className ];
- window.location.href = `${className}.html`;
- }
- }
- } )();
- ( function loadNavigation() {
- const content = document.getElementById( 'content' );
- const navContainer = content.querySelector( 'nav' );
- fetch( 'nav.html' )
- .then( response => response.text() )
- .then( html => {
- navContainer.innerHTML = html;
- const savedScrollTop = sessionStorage.getItem( 'navScrollTop' );
- if ( savedScrollTop !== null ) {
- content.scrollTop = parseInt( savedScrollTop, 10 );
- }
- // Save scroll position when clicking nav links
- navContainer.addEventListener( 'click', function ( event ) {
- const link = event.target.closest( 'a' );
- if ( link ) {
- sessionStorage.setItem( 'navScrollTop', content.scrollTop );
- }
- } );
- updateNavigation();
- sessionStorage.removeItem( 'navScrollTop' );
- } )
- .catch( err => console.error( 'Failed to load navigation:', err ) );
- } )();
- //
- const panel = document.getElementById( 'panel' );
- const panelScrim = document.getElementById( 'panelScrim' );
- const expandButton = document.getElementById( 'expandButton' );
- const clearSearchButton = document.getElementById( 'clearSearchButton' );
- const filterInput = document.getElementById( 'filterInput' );
- // code copy buttons
- const elements = document.getElementsByTagName( 'pre' );
- for ( let i = 0; i < elements.length; i ++ ) {
- const element = elements[ i ];
- if ( element.classList.contains( 'linenums' ) === false ) {
- addCopyButton( element );
- }
- }
- function addCopyButton( element ) {
- const copyButton = document.createElement( 'button' );
- copyButton.className = 'copy-btn';
- element.appendChild( copyButton );
- copyButton.addEventListener( 'click', function () {
- const codeContent = element.textContent;
- navigator.clipboard.writeText( codeContent ).then( () => {
- copyButton.classList.add( 'copied' );
- setTimeout( () => {
- copyButton.classList.remove( 'copied' );
- }, 1000 );
- } );
- } );
- }
- // Functionality for hamburger button (on small devices)
- expandButton.onclick = function ( event ) {
- event.preventDefault();
- panel.classList.toggle( 'open' );
- };
- panelScrim.onclick = function ( event ) {
- event.preventDefault();
- panel.classList.toggle( 'open' );
- };
- // Functionality for search/filter input field
- filterInput.onfocus = function () {
- panel.classList.add( 'searchFocused' );
- };
- filterInput.onblur = function () {
- if ( filterInput.value === '' ) {
- panel.classList.remove( 'searchFocused' );
- }
- };
- filterInput.oninput = function () {
- const term = filterInput.value.trim();
- // eslint-disable-next-line no-undef
- search( term ); // defined in search.js
- };
- clearSearchButton.onclick = function () {
- filterInput.value = '';
- filterInput.focus();
- // eslint-disable-next-line no-undef
- hideSearch(); // defined in search.js
- };
- //
- window.addEventListener( 'hashchange', updateNavigation );
- function updateNavigation() {
- // unselected elements
- const selected = document.querySelectorAll( 'nav a.selected' );
- selected.forEach( link => link.classList.remove( 'selected' ) );
- // determine target
- const filename = window.location.pathname.split( '/' ).pop();
- const pagename = filename.split( '.' )[ 0 ];
- let target = pagename.replace( 'module-', '' );
- if ( pagename === 'global' ) {
- target = window.location.hash.split( '#' ).pop();
- }
- if ( target === '' ) return;
- // select target and move into view
- const aElement = document.querySelector( `nav a[href="${filename}"], nav a[href="${filename}#${target}"]` );
- if ( aElement !== null ) {
- const savedScrollTop = sessionStorage.getItem( 'navScrollTop' );
- if ( savedScrollTop === null ) {
- aElement.scrollIntoView( { block: 'center' } );
- }
- aElement.classList.add( 'selected' );
- }
- }
- // eslint-disable-next-line no-undef
- prettyPrint();
- console.log( [
- ' __ __',
- ' __/ __\\ / __\\__ ____ _____ _____',
- '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
- '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
- '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
- '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
- ' / __/ / \\__ \\',
- ' \\/____/\\/_____/'
- ].join( '\n' ) );
- // console sandbox
- import( '/build/three.module.js' ).then( THREE => {
- window.THREE = THREE;
- } );
|