From: sjy Date: Fri, 17 Aug 2012 09:50:50 +0000 (+0800) Subject: Identify current section of document by bolding menu on left X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=cf335ab9c1d1f3f1b37e0b13367559714f408b45;p=sjy%2Faustlii.git Identify current section of document by bolding menu on left General code cleanup Fix judge regexes to use \s; newlines should no longer break judge detection Stop attempting to remove random sections of the page --- diff --git a/austlii.css b/austlii.css index 64f5845..a9e0f8e 100644 --- a/austlii.css +++ b/austlii.css @@ -8,7 +8,7 @@ body { border-right: 1px #ccc solid; } -h1 center {border-bottom: 1px black solid;} +h1 {border-bottom: 1px black solid;} ol li {text-align: justify;} @@ -16,8 +16,9 @@ ol li {text-align: justify;} /* austlii.js special features */ .citation {font-size: 150%; font-weight: bold;} -#menu {position: fixed; top: 5em; left: 0; padding: 1em; width: 10em;} +#menu {position: fixed; top: 2em; left: 0; padding: 1em; width: 10em;} #menu ol {list-style-type: none; padding: 0;} #menu ol li {text-align: left; margin-bottom: 0.5em;} +#menu ol li a.current {font-weight: bold;} a.judge {font-weight: bold;} diff --git a/austlii.js b/austlii.js index e506188..e2ce166 100644 --- a/austlii.js +++ b/austlii.js @@ -17,14 +17,13 @@ window.austlii = { s.rel = "stylesheet"; s.type = "text/css"; s.href = url; document.getElementsByTagName('head').item(0).appendChild(s); return; }, - main: function() { - austlii.prune("austlii", "jquery"); + init: function() { if (window.location.host.slice(-14) != "austlii.edu.au" || window.location.pathname.slice(0,10) != "/au/cases/" || window.location.pathname.slice(-5) != ".html") console.log("You're not looking at a case on AustLII."); else - austlii.paintMenu(); + austlii.main(); }, prune: function() { // Remove all but the newest script tag containing the queries passed in as arguments. @@ -39,48 +38,80 @@ window.austlii = { }, }; -austlii.paintMenu = function() { +austlii.main = function() { + + // grab austlii.css from the same directory as this JavaScript + var cssUrl = $('script[src$="austlii.js"]').attr('src').replace(/austlii\.js/, "austlii.css"); + austlii.style(cssUrl); + + austlii.cleanup(); + austlii.addMarkup(); + austlii.paintMenu(); - austlii.style("http://splintax.ucc.asn.au/austlii/austlii.css"); +}; +austlii.cleanup = function() { // remove text nodes ([] surrounding "Download", etc) - var textNodes = $("body").contents().filter(function(){return this.nodeType == 3;}).remove(); - // hide other unnecessary menu elements - var $els = $("body").children(); // excludes text nodes - var index = 0; - while ($els[index].tagName != "H1") { - $els[index].style.display = "none"; index++; - } - // add back to top + // var textNodes = $("body").contents().filter(function(){return this.nodeType == 3;}).remove(); + // remove unnecessary
s + $("br").remove(); +}; + +austlii.addMarkup = function() { + + // add back to top around header $("h1").eq(1).wrap(''); // highlight case title $("center i").first().parent().addClass("citation"); // find and markup judges - var judgeExp = /([A-Zc, ]+)(( | )C?JJ?\.)/g; + var judgeExp = /([A-Zc]+)(\s[A-Zc,\s]+\sC?JJ?\.)/g; var replacementText = document.body.innerHTML.replace(judgeExp, '$1$2'); document.body.innerHTML = replacementText; - // add menu - var $menu = $(''); +}; + +austlii.paintMenu = function() { + + // create menu + var $menu = $(''); + $("body").append($menu); + + // add fixed link to headnote + $("#menu ol").append('
  • Headnote
  • ') + // add jumplinks for each judge - var $judges = $('
      '); $("a.judge").each(function(){ var $li = $('
    1. ' + $(this).html() + '
    2. '); - $judges.append($li); - }); $menu.append($judges); + $("#menu ol").append($li); + }); + + // add fixed link to footnotes + $("#menu ol").append('
    3. Footnotes
    4. '); + // add annotation features - $menu.append($('Highlight')); - $("body").append($menu); + //$menu.append($('Highlight')); // enable smooth scrolling on anchors - austlii.load("http://splintax.ucc.asn.au/cases/jquery.scrollTo-1.4.2-min.js", function() { - austlii.load("http://splintax.ucc.asn.au/cases/jquery.localscroll-1.2.7-min.js", function() { + austlii.load("http://splintax.ucc.asn.au/austlii/jquery.scrollTo-1.4.2-min.js", function() { + austlii.load("http://splintax.ucc.asn.au/austlii/jquery.localscroll-1.2.7-min.js", function() { $.localScroll({duration: '200'}); }); }); + // update right menu on scroll + $(window).scroll(function() { + $("#menu ol li a").each(function(){ + // if the relevant link appearsmore than half way down the page + var $anchor = $('a[name="'+$(this).attr("href").slice(1)+'"]'); + if ($(window).scrollTop() + $(window).height()/2 > $anchor.offset().top) { + austlii.$currentSection = $(this); + } + }); + $("#menu ol li a").not(austlii.$currentSection).removeClass("current"); + austlii.$currentSection.addClass("current"); + }); $(window).scroll(); // and run it once $("#trigger-highlight").click(austlii.highlight); @@ -108,5 +139,9 @@ austlii.highlight = function(event) { else {console.log("You haven't highlighted anything.")} }; -console.log("Loaded austlii.js v"+austlii.VERSION+"."); -austlii.load('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', austlii.main); +if (document.getElementsByTagName("script").length == 1) { + console.log("Loaded austlii.js v"+austlii.VERSION+"."); + austlii.load('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', austlii.init); +} else { + alert("austlii.js will not run when there are other scripts on the page."); +}