| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // Initialize prettify for syntax highlighting
- if ( typeof prettyPrint === 'function' ) {
- prettyPrint();
- }
- // Scroll to hash on page load
- ( function () {
- const hash = window.location.hash.substring( 1 );
- if ( hash ) {
- const element = document.getElementById( hash );
- if ( element ) element.scrollIntoView();
- }
- } )();
- // Update URL hash when clicking on method/property links
- ( function () {
- const h1 = document.querySelector( 'h1' );
- const className = h1 ? h1.textContent.trim() : null;
- if ( ! className ) return;
- document.addEventListener( 'click', function ( event ) {
- const target = event.target.closest( 'a[href^="#"]' );
- if ( ! target || ! target.hash ) return;
- const hash = target.hash.substring( 1 );
- const newHash = ( hash !== className ) ? `#${className}.${hash}` : `#${hash}`;
- const targetWindow = ( window.parent !== window ) ? window.parent : window;
- targetWindow.history.pushState( null, '', newHash );
- } );
- } )();
- // Add code copy buttons
- ( function addCopyButtons() {
- const elements = document.getElementsByTagName( 'pre' );
- for ( let i = 0; i < elements.length; i ++ ) {
- const element = elements[ i ];
- if ( element.classList.contains( 'linenums' ) === false ) {
- 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 );
- } );
- } );
- }
- }
- } )();
|