PageSourceSearch

https://www.giulianodibernardo.com/wp-content/plugins/powerkit/mod…lic-powerkit-table-of-contents.js?ver=3.0.4

js giulianodibernardo.com collected 2026-10-02 23:40:55 UTC 2,838 bytes, 109 lines download raw bytes

1/**
2 * Table of Contents
3 */
4( function( $ ) {
5
6	$( document ).ready( function() {
7
8		var pk_toc_container  = '.entry-content';
9		var pk_toc_wpadminbar = 0;
10		var pk_toc_offset     = 80;
11
12		// Get height adminbar.
13		if ( $( '#wpadminbar' ).length > 0 ) {
14			pk_toc_wpadminbar = $( '#wpadminbar' ).outerHeight();
15
16			if ( 'absolute' === $( '#wpadminbar' ).css( 'position' ) ) {
17				pk_toc_wpadminbar = 0;
18			}
19		}
20
21		/**
22		 * TOC: Click hide.
23		 */
24		$( document ).on( 'click', '.pk-toc-btn-hide', function() {
25
26			if ( $( this ).closest( '.pk-toc' ).hasClass( 'pk-toc-hide' ) ) {
27				$( this ).closest( '.pk-toc' ).removeClass( 'pk-toc-hide' );
28
29				$( this ).html( powerkit_toc_config.label_hide );
30
31				$( this ).closest( '.pk-toc' ).find('> ol, > ul').slideDown(200, function(){
32					$( this ).animate({opacity: 1}, 150, 'swing');
33				});
34			} else {
35				$( this ).closest( '.pk-toc' ).addClass( 'pk-toc-hide' );
36
37				$( this ).html( powerkit_toc_config.label_show );
38
39				$( this ).closest( '.pk-toc' ).find('> ol, > ul').animate({opacity: 0}, 150, 'swing', function(){
40					$( this ).slideUp(200);
41				});
42			}
43		} );
44
45		/**
46		 * TOC: Scroll to Heading.
47		 */
48		$( document ).on( 'click', '.pk-toc a', function() {
49
50			var objContent = $( pk_toc_container );
51
52			// If the list is found inside the content.
53			if ( $( this ).closest( pk_toc_container ).length > 0 ) {
54				objContent = $( this ).closest( pk_toc_container );
55			}
56
57			// Get position heading.
58			var offsetHeading = $( objContent ).find( $( this ).attr( 'href' ) ).offset();
59
60			if ( typeof offsetHeading === 'undefined' ) {
61				return;
62			}
63
64			var positionHeading = offsetHeading.top;
65
66			// Scroll to Heading.
67			$( 'body, html' ).animate( {
68				scrollTop: positionHeading - pk_toc_wpadminbar - pk_toc_offset
69			}, 400 );
70
71			return false;
72		} );
73
74		/**
75		 * TOC: Active element of toc widget.
76		 */
77		$( window ).scroll( function() {
78			var scrollTop = $( window ).scrollTop();
79
80			$( '.powerkit_toc_widget' ).first().find( '.pk-toc a' ).each( function( index, elem ) {
81
82				// Get position heading.
83				var offsetHeading = $( $( elem ).attr( 'href' ) ).offset();
84
85				if ( typeof offsetHeading === 'undefined' ) {
86					return;
87				}
88
89				var positionHeading = offsetHeading.top;
90
91				if ( positionHeading - scrollTop - pk_toc_wpadminbar - pk_toc_offset <= 0 ) {
92					var filterElem = '[href="%1s"]'.replace( '%1s', $( elem ).attr( 'href' ) );
93
94					// Find menu element.
95					var menuElem = $( '.powerkit_toc_widget .pk-toc' ).find( 'a' ).filter( filterElem );
96
97					// Remove class active.
98					$( '.powerkit_toc_widget .pk-toc li' ).removeClass( 'active active-child' );
99
100					// Add class active.
101					$( menuElem ).parents( 'li' ).addClass( 'active-child' );
102					$( menuElem ).parent( 'li' ).addClass( 'active' );
103				}
104			} );
105		} );
106
107	} );
108
109} )( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.