MediaWiki:Gadget-SidebarTOC.js: Difference between revisions

Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 1: Line 1:
mw.loader.using( 'mediawiki.toc', function () {
mw.loader.using( 'mediawiki.toc', function () {
$( function () {
$( function () {
var $tocContainer = $( '<div>' )
var $window, $sidebar, $tocContainer, $toc, tocLimit;
.addClass( 'mw-table-of-contents-container' )
.appendTo( '#mw-content' ); // Append the ToC container under the content area


var $floatTOC = $( '.toc' )
$window = $( window );
.clone()
$sidebar = $( '#mw-panel' );
.removeAttr( 'id' )
$tocContainer = $( '<div class="mw-table-of-contents-container"></div>' ).insertAfter( $sidebar );
.addClass( 'vector-sticky-toc-container' )
$toc = $( '.toc' ).addClass( 'vector-sticky-toc-container' ).appendTo( $tocContainer );
.appendTo( $tocContainer ); // Append the cloned ToC inside the ToC container
 
});
if ( !$toc.length ) {
return;
}
 
tocLimit = $tocContainer.offset().top + $tocContainer.height();
 
$window.on('scroll', function () {
var scrollTop = $window.scrollTop();
 
if (scrollTop > tocLimit) {
$toc.addClass('sticky');
} else {
$toc.removeClass('sticky');
}
});
    });
});
});

Revision as of 06:52, 22 February 2024

mw.loader.using( 'mediawiki.toc', function () {
	$( function () {
		var $window, $sidebar, $tocContainer, $toc, tocLimit;

		$window = $( window );
		$sidebar = $( '#mw-panel' );
		$tocContainer = $( '<div class="mw-table-of-contents-container"></div>' ).insertAfter( $sidebar );
		$toc = $( '.toc' ).addClass( 'vector-sticky-toc-container' ).appendTo( $tocContainer );

		if ( !$toc.length ) {
			return;
		}

		tocLimit = $tocContainer.offset().top + $tocContainer.height();

		$window.on('scroll', function () {
			var scrollTop = $window.scrollTop();

			if (scrollTop > tocLimit) {
				$toc.addClass('sticky');
			} else {
				$toc.removeClass('sticky');
			}
		});
    });
});