MediaWiki:SupportPage.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
Undo revision 30549 by Pcoombe (talk)
Tag: Undo
minor cleanup
Line 18: Line 18:
// Cache selectors
// Cache selectors
var lastId,
var lastId,
topMenu = $("#toc > ul"),
topMenu = $('#toc > ul'),
// All list items
menuItems = topMenu.find('a'), // All TOC links
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
/* 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){
menuItems.click(function(e){
var id = $(this).attr("href").replace('#', ''),
var id = $(this).attr('href').replace('#', ''),
offsetTop = $( document.getElementById(id) ).offset().top;
offsetTop = $( document.getElementById(id) ).offset().top;
$('html, body').stop().animate({
$('html, body').stop().animate({
Line 35: Line 32:
});
});


/* Highlighting current section in TOC */
// Bind to scroll
$(window).scroll(function(){
$(window).scroll(function(){
// Get container scroll position
// Get container scroll position
Line 42: Line 39:
// 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];
var id = cur && cur.length ? cur[0].id : "";
var id = cur && cur.length ? cur[0].id : '';


if (lastId !== id) {
if (lastId !== id) {
Line 53: Line 50:
// Set/remove active class
// Set/remove active class
menuItems
menuItems
.removeClass("-active")
.removeClass('-active')
.end().filter("[href=#"+id+"]").addClass("-active");
.end().filter('[href=#' + id + ']').addClass('-active');
}
}
});
});
/* END of code for highlighting current section in TOC */
/* END of highlighting current section in TOC */


/*!
/*!