MediaWiki:SupportPage.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
new toc code |
||
Line 14: | Line 14: | ||
$(function() { |
$(function() { |
||
/* |
/* -- table of contents code -- */ |
||
⚫ | |||
// Build a list of corresponding toc links and anchors |
|||
⚫ | |||
⚫ | |||
⚫ | |||
toc.push({ |
|||
⚫ | |||
anchor: $( document.getElementById(id) ) |
|||
⚫ | |||
⚫ | |||
// |
// Add smooth scrolling effect |
||
var scrollOffset = 24, // Offset in px |
|||
// var lastId, |
|||
scrollDuration = 500, // in ms |
|||
smoothScroll = function(event) { |
|||
var offsetTop = event.data.anchor.offset().top; |
|||
// scrollItems = $('.sp-content .mw-headline'), // Anchors corresponding to TOC links |
|||
$('html, body').stop().animate({ |
|||
scrollTop: offsetTop - scrollOffset |
|||
// scrollDuration = 500; // in ms |
|||
⚫ | |||
⚫ | |||
⚫ | |||
for (var i = 0; i < toc.length; i++) { |
|||
toc[i].link.on( 'click', toc[i], smoothScroll ); |
|||
} |
|||
⚫ | |||
// /* Bind click handler to menu items so we can get a fancy scroll animation */ |
|||
var lastSection; |
|||
$(window).scroll(function() { |
|||
⚫ | |||
var fromTop = $(this).scrollTop(); // Get container scroll position |
|||
var currentSection = toc.filter(function(item) { |
|||
return fromTop > item.anchor.offset().top - 48; |
|||
}); |
|||
currentSection = currentSection[currentSection.length - 1]; |
|||
⚫ | |||
if ( lastSection !== currentSection ) { |
|||
⚫ | |||
lastSection = currentSection; |
|||
⚫ | |||
currentSection.link.addClass('-active'); |
|||
} |
|||
}); |
|||
/* -- end of table of contents code -- */ |
|||
⚫ | |||
⚫ | |||
// var fromTop = $(this).scrollTop(); // Get container scroll position |
|||
// // Get id of current scroll item |
|||
// var cur = scrollItems.map(function(){ |
|||
// if ( $(this).offset().top < fromTop ) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
// // Get the id of the current element |
|||
// cur = cur[cur.length-1]; |
|||
// var id = cur && cur.length ? cur[0].id : ''; |
|||
// if (lastId !== id) { |
|||
// lastId = id; |
|||
// // Set/remove active class |
|||
// menuItems |
|||
⚫ | |||
// .end().filter('[href=#' + id + ']').addClass('-active'); |
|||
⚫ | |||
⚫ | |||
// /* END of highlighting current section in TOC */ |
|||
/*! |
/*! |