MediaWiki:SupportPage.js: Difference between revisions

Content deleted Content added
add code for highlighting current section
No edit summary
Line 23:
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function$('.sp-content .mw-headline'){;
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
 
// Bind click handler to menu items
Line 32 ⟶ 29:
menuItems.click(function(e){
var href = $(this).attr("href"),
offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
$('html, body').stop().animate({
scrollTop: offsetTop
}, 850);
e.preventDefault();
Line 46 ⟶ 43:
// 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];
Line 54 ⟶ 51:
 
if (lastId !== id) {
lastId = id;
// Set/remove active class
menuItems
.parent() .removeClass("-active")
.end().filter("[href=#"+id+"]").parent().addClass("-active");
}
});