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: | ||
function | mw.loader.using( ['jquery', 'mediawiki.util'], function () { | ||
var $toc = $( '#toc' ); | $( function () { | ||
var $toc = $( '#toc' ); | |||
if ( !$toc.length ) { | |||
return; | |||
} | |||
var $mwContent = $( '#mw-content-text' ); | |||
var $floatTOC = $toc | |||
.clone() | |||
.removeAttr( 'id' ) | |||
.addClass( 'floatTOC' ) | |||
.appendTo( $mwContent ) | |||
.css( { | |||
height: $mwContent.height(), // Set ToC height to match article height | |||
overflowY: 'auto' // Enable vertical scrolling if ToC exceeds article height | |||
} ); | |||
// Update scrollHandler function to use $mwContent instead of window | |||
var scrollHandler = function () { | |||
var scrollTop = $mwContent.scrollTop(); // Use scrollTop of $mwContent | |||
if ( scrollTop > 0 ) { // Adjust condition based on scroll position | |||
$floatTOC.css( 'visibility', 'visible' ); | |||
} | } else { | ||
$floatTOC.css( 'visibility', 'hidden' ); | |||
} | |||
}; | |||
// | // Update event binding to use $mwContent instead of window | ||
$mwContent.on( 'scroll', scrollHandler ); | |||
} ); | |||
} ); |
Revision as of 07:20, 22 February 2024
mw.loader.using( ['jquery', 'mediawiki.util'], function () {
$( function () {
var $toc = $( '#toc' );
if ( !$toc.length ) {
return;
}
var $mwContent = $( '#mw-content-text' );
var $floatTOC = $toc
.clone()
.removeAttr( 'id' )
.addClass( 'floatTOC' )
.appendTo( $mwContent )
.css( {
height: $mwContent.height(), // Set ToC height to match article height
overflowY: 'auto' // Enable vertical scrolling if ToC exceeds article height
} );
// Update scrollHandler function to use $mwContent instead of window
var scrollHandler = function () {
var scrollTop = $mwContent.scrollTop(); // Use scrollTop of $mwContent
if ( scrollTop > 0 ) { // Adjust condition based on scroll position
$floatTOC.css( 'visibility', 'visible' );
} else {
$floatTOC.css( 'visibility', 'hidden' );
}
};
// Update event binding to use $mwContent instead of window
$mwContent.on( 'scroll', scrollHandler );
} );
} );