Changeset 13750
- Timestamp:
- 05/28/2024 12:45:57 AM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/js/section-faq.js
r11655 r13750 6 6 var $question = $( question ), 7 7 $button = $( '<button />' ), 8 $h3 = $( '<h3 />' ), 9 id = $question.attr( 'id' ); 10 11 // If there is no ID, create our own. 12 if ( ! id ) { 13 id = encodeURIComponent( $question.text().toLowerCase().trim() ); 14 $question.attr( 'id', id ); 15 } 16 17 $button.attr( 'formaction', id ).on( 'click', function( event ) { 18 event.preventDefault(); 19 window.location.hash = id; 20 } ); 8 $h3 = $( '<h3 />' ); 21 9 22 10 $question.html( $h3.html( $button.text( $question.text() ) ) ); … … 42 30 window.scrollTo( 0, $question.offset().top - scrollPaddingTop ); 43 31 } 32 33 if ( $question.prop( 'id' ) ) { 34 window.location.hash = $question.prop( 'id' ); 35 } 44 36 } ); 45 37 46 38 if ( window.location.hash ) { 47 jQuery( 39 var uriHash = window.location.hash.substr(1), 40 uriElement = document.getElementById( uriHash ); 41 42 if ( ! uriElement ) { 48 43 // Decode/Encode here is to work with any existing links that are not fully-encoded, the trim handles whitespace/newlines. 49 document.getElementById( encodeURIComponent( decodeURIComponent( window.location.hash.substr(1) ).trim() ) ) 50 ).trigger( 'click' ); 44 uriHash = encodeURIComponent( decodeURIComponent( uriHash ) ).trim(); 45 uriElement = document.getElementById( uriHash ); 46 47 if ( ! uriElement ) { 48 // Perform PHP-style URI encoding. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI#encoding_for_rfc3986 49 uriHash = uriHash.replace( /[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}` ); 50 uriElement = document.getElementById( uriHash ); 51 } 52 } 53 54 jQuery( uriElement ).trigger( 'click' ); 51 55 } 52 56 } )( jQuery );
Note: See TracChangeset
for help on using the changeset viewer.