Merry Christmas from the IIWiki Team! Have a happy new year!
MediaWiki:Gadget-SidebarTOC.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
function customizeToC() { | |||
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', $.throttle( 250, scrollHandler ) ); | |||
} | |||
// Call the customizeToC function when jQuery and its dependencies are ready | |||
mw.loader.using( ['jquery', 'jquery.throttle-debounce'], customizeToC ); | |||
Revision as of 07:17, 22 February 2024
function customizeToC() {
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', $.throttle( 250, scrollHandler ) );
}
// Call the customizeToC function when jQuery and its dependencies are ready
mw.loader.using( ['jquery', 'jquery.throttle-debounce'], customizeToC );