MediaWiki:SupportPage.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
add code for highlighting current section
No edit summary
Line 23: Line 23:
menuItems = topMenu.find("a"),
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
// Anchors corresponding to menu items
scrollItems = menuItems.map(function(){
scrollItems = $('.sp-content .mw-headline');
var item = $($(this).attr("href"));
if (item.length) { return item; }
});


// Bind click handler to menu items
// Bind click handler to menu items
Line 32: Line 29:
menuItems.click(function(e){
menuItems.click(function(e){
var href = $(this).attr("href"),
var href = $(this).attr("href"),
offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
$('html, body').stop().animate({
$('html, body').stop().animate({
scrollTop: offsetTop
scrollTop: offsetTop
}, 850);
}, 850);
e.preventDefault();
e.preventDefault();
Line 46: Line 43:
// Get id of current scroll item
// Get id of current scroll item
var cur = scrollItems.map(function(){
var cur = scrollItems.map(function(){
if ($(this).offset().top < fromTop)
if ($(this).offset().top < fromTop)
return this;
return this;
});
});
// Get the id of the current element
// Get the id of the current element
cur = cur[cur.length-1];
cur = cur[cur.length-1];
Line 54: Line 51:


if (lastId !== id) {
if (lastId !== id) {
lastId = id;
lastId = id;
// Set/remove active class
// Set/remove active class
menuItems
menuItems
.parent().removeClass("-active")
.removeClass("-active")
.end().filter("[href=#"+id+"]").parent().addClass("active");
.end().filter("[href=#"+id+"]").addClass("-active");
}
}
});
});