User:Mrblahblah200/toc.js

// Options: //  TOC_fixed: When true the contents scrolls with the page. Defaults to true

importStylesheet('User:Mrblahblah200/toc.css');

(function(options) {	var tocContents = $('#toc > ul').clone;	// If there is no table of contents on the page, don't add anything	if (tocContents.length !== 0) {		var newTOC = $('#p-interaction').clone;		newTOC.attr('id', 'p-toc');		newTOC.attr('aria-labelledby', 'p-toc-label');		var outer = $(' ');		outer.append(newTOC);		newTOC.find('h3').text('Contents').attr('id', 'p-toc-label');		newTOC.find('.body').html(tocContents);		$('#mw-panel').append(outer);		if (options.fixed) {			$(window).on('scroll', function { var lang = $('#p-lang'); var scrollTop = $(document).scrollTop; var langBottomRel = lang.position.top + lang.outerHeight(true) - scrollTop; // console.log('postop: ' + lang.position.top.toFixed(2) + ', outerheight: ' + lang.outerHeight(true) + ', scrollTop: ' + scrollTop); // console.log(' = ' + langBottomRel); var toc = $('#p-toc'); var toc_outer = $('#outer-p-toc'); if (langBottomRel >= 0) { // Remove fixed positioning toc.removeClass('lang-fixed'); toc_outer.removeClass('lang-fixed'); } else { // Add fixed positioning toc.addClass('lang-fixed'); toc_outer.addClass('lang-fixed'); }			});		}	} })({	fixed: typeof TOC_fixed === 'undefined' ? true : TOC_fixed, });