5 function scrollTo(thing) {
6 $('html, body').scrollTop($(thing).offset().top - $('#level-chooser').outerHeight());
9 function updateView() {
10 var scrolltop = $(window).scrollTop();
12 $('#level-chooser-place').each(function(i, el){
13 if (scrolltop > $(el).offset().top) {
14 $("#level-chooser").addClass("fixed");
17 $("#level-chooser").removeClass("fixed");
21 $('.level-toc').each(function(i, el) {
22 var $sect = $($(el).parent());
23 var menu_top = $('#level-chooser').outerHeight();
24 var menu_scrolltop = scrolltop + menu_top;
26 if (menu_scrolltop + 2 >= $sect.offset().top &&
27 menu_scrolltop < $sect.offset().top + $sect.outerHeight()) {
28 $(el).addClass("fixed").css("top", Math.min(
30 - scrolltop + $sect.offset().top + $sect.outerHeight() - $(el).outerHeight()
32 $("#level-chooser a[href='#" + $sect.attr('id') + "']").addClass('active');
35 $(el).removeClass("fixed");
36 $("#level-chooser a[href='#" + $sect.attr('id') + "']").removeClass('active');
43 $("#level-chooser a, .level-toc a").click(function(ev) {
45 scrollTo($(this).attr('href'));
53 $(document).scroll(updateView);
54 if (window.location.hash) {
55 scrollTo(window.location.hash);