-austlii.paintMenu = function() {
-
- // create menu
- var $menu = $('<div id="menu"><ol></ol></div>');
- $("body").append($menu);
-
- // add fixed link to headnote
- $("#menu ol").append('<li><a href="#top">Headnote</a></li>')
+// Updates responsive menu whenever the page is scrolled.
+austlii.scrollHandler = function() {
+ var currentPosition = $(window).scrollTop() + $(window).height()/2;
+
+ var $anchors = $("#container a.section");
+ var $links = $("#menu ol li a");
+ var $pars = $("#container ol li").not("ol ol li");
+
+ // remove existing section highlight and citation
+ $links.removeClass("current");
+ $("#menu .pinpoint").remove();
+
+ // find the current document section
+ var $anchor = $anchors.filter(function(){
+ // is this anchor above the fold?
+ return currentPosition > $(this).offset().top;
+ }).last(); // current section = last anchor above fold
+ // highlight the link to the current document section
+ $links.filter('[href="#' + $anchor.attr("name") + '"]').addClass("current");
+
+ // check whether we're in the judgment body
+ if ( currentPosition > $pars.first().offset().top &&
+ currentPosition < $pars.last().offset().top ) {
+ // we are, so find the current paragraph and add a pinpoint citation
+ var $par = $pars.filter(function(){
+ // is this paragraph above the fold?
+ return currentPosition > $(this).offset().top;
+ }).last(); // current paragraph = last paragraph above fold
+ if ( $par.val() != 0 ) { // don't add unofficial paragraph citations on old cases
+ // TODO: make it work anyway, but add a warning?
+ var $pinpoint = $('<span class="pinpoint"> at ['+ $par.val() +']</span>');
+ $("#menu a.current").after($pinpoint); // add citation
+ }
+ }
+};