X-Git-Url: https://git.ucc.asn.au/?p=sjy%2Faustlii.git;a=blobdiff_plain;f=austlii.js;h=1908d47e00b827cc11e68f42509f2ef3632bfe02;hp=e506188145da3078030dcef3a9567a4d7b01c3e6;hb=806d9100311c20ba414b05a893198f623c2d6c98;hpb=f36beed7e8739a9d037fa04c947fffb0c9277fb2;ds=sidebyside diff --git a/austlii.js b/austlii.js index e506188..1908d47 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,81 @@ 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 judgeExp = /([A-Z]{3})((?:[A-Z\s,]| )+C?J?J\.)/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 current judge 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 +140,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."); +}