MediaWiki:SupportPage.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Tag: Undo |
minor cleanup |
||
Line 18: | Line 18: | ||
// Cache selectors |
// Cache selectors |
||
var lastId, |
var lastId, |
||
topMenu = $( |
topMenu = $('#toc > ul'), |
||
// All |
menuItems = topMenu.find('a'), // All TOC links |
||
⚫ | |||
menuItems = topMenu.find("a"), |
|||
// Anchors corresponding 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( |
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( |
.removeClass('-active') |
||
.end().filter( |
.end().filter('[href=#' + id + ']').addClass('-active'); |
||
} |
} |
||
}); |
}); |
||
/* END of |
/* END of highlighting current section in TOC */ |
||
/*! |
/*! |