MediaWiki:SupportPage.js: Difference between revisions

Content deleted Content added
Undo revision 30549 by Pcoombe (talk)
Tag: Undo
minor cleanup
Line 18:
// Cache selectors
var lastId,
topMenu = $("'#toc > ul"'),
menuItems = topMenu.find('a'), // All listTOC itemslinks
scrollItems = $('.sp-content .mw-headline'); // Anchors corresponding to TOC links
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = $('.sp-content .mw-headline');
 
//* Bind click handler to menu items so we can get a fancy scroll animation */
// so we can get a fancy scroll animation
menuItems.click(function(e){
var id = $(this).attr("'href"').replace('#', ''),
offsetTop = $( document.getElementById(id) ).offset().top;
$('html, body').stop().animate({
Line 35 ⟶ 32:
});
 
/* Highlighting current section in TOC */
// Bind to scroll
$(window).scroll(function(){
// Get container scroll position
Line 42 ⟶ 39:
// Get id of current scroll item
var cur = scrollItems.map(function(){
if ( $(this).offset().top < fromTop )
return this;
});
// Get the id of the current element
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : ""'';
 
if (lastId !== id) {
Line 53 ⟶ 50:
// Set/remove active class
menuItems
.removeClass("'-active"')
.end().filter("'[href=#"' + id +" ']"').addClass("'-active"');
}
});
/* END of code for highlighting current section in TOC */
 
/*!