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 1: | Line 1: | ||
mw.loader.using( 'mediawiki.toc', function () { | mw.loader.using( 'mediawiki.toc', function () { | ||
$( function () { | $( function () { | ||
var $window, $sidebar, $tocContainer, $toc, tocLimit; | var $window, $sidebar, $article, $tocContainer, $toc, tocLimit; | ||
$window = $( window ); | $window = $( window ); | ||
$sidebar = $( '#mw-panel' ); | $sidebar = $( '#mw-panel' ); | ||
$tocContainer = $( '<div class="mw-table-of-contents-container"></div>' ).insertAfter( $sidebar ); | $article = $( '#content' ); | ||
$tocContainer = $( '<div class="mw-table-of-contents-container"></div>' ).insertAfter( $sidebar ).append($article); | |||
$toc = $( '.toc' ).addClass( 'vector-sticky-toc-container' ).appendTo( $tocContainer ); | $toc = $( '.toc' ).addClass( 'vector-sticky-toc-container' ).appendTo( $tocContainer ); | ||
Line 12: | Line 13: | ||
} | } | ||
tocLimit = $ | tocLimit = $article.offset().top + $article.height(); | ||
$window.on('scroll', function () { | $window.on('scroll', function () { |
Revision as of 06:59, 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 ).append($article);
$toc = $( '.toc' ).addClass( 'vector-sticky-toc-container' ).appendTo( $tocContainer );
if ( !$toc.length ) {
return;
}
tocLimit = $article.offset().top + $article.height();
$window.on('scroll', function () {
var scrollTop = $window.scrollTop();
if (scrollTop > tocLimit) {
$toc.addClass('sticky');
} else {
$toc.removeClass('sticky');
}
});
});
});