Emoji u1f384.svg
Merry Christmas from the IIWiki Team! Have a happy new year!

MediaWiki:Gadget-SidebarTOC.js: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 6: Line 6:
$sidebar = $( '#mw-panel' );
$sidebar = $( '#mw-panel' );
$article = $( '#content' );
$article = $( '#content' );
$tocContainer = $( '<div class="mw-table-of-contents-container"></div>' ).insertAfter( $sidebar ).append($article);
$tocContainer = $( '<div class="mw-table-of-contents-container"></div>' ).insertAfter( $sidebar );
$toc = $( '.toc' ).addClass( 'vector-sticky-toc-container' ).appendTo( $tocContainer );
$toc = $( '.toc' ).addClass( 'vector-sticky-toc-container' ).appendTo( $tocContainer );


Line 13: Line 13:
}
}


tocLimit = $article.offset().top + $article.height();
tocLimit = $sidebar.offset().top + $sidebar.height();


$window.on('scroll', function () {
$window.on('scroll', function () {

Revision as of 07:03, 22 February 2024

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

		$window = $( window );
		$sidebar = $( '#mw-panel' );
		$article = $( '#content' );
		$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 = $sidebar.offset().top + $sidebar.height();

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

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