Difference between revisions of "Template:Waterloo/JS/citetag"
m |
(no longer creates new li for repeated referencing) |
||
Line 1: | Line 1: | ||
// Implements the <cite> tag. Requires a "ref" attribute that corresponds to one listed in references.json and that | // Implements the <cite> tag. Requires a "ref" attribute that corresponds to one listed in references.json and that | ||
// references.json be included in the global scope | // references.json be included in the global scope | ||
+ | var scrollLinks = {}; | ||
− | + | $(document).ready(function() { | |
− | + | ||
− | $(document).ready(function() { | + | |
var citation_idx = 1; | var citation_idx = 1; | ||
// On first encounter, fill in all <cite> tags on the page with a certain reference | // On first encounter, fill in all <cite> tags on the page with a certain reference | ||
− | $( "cite" ).each(function() { | + | $( "cite" ).each( function() { |
− | if ( $(this).html.indexOf("href") != -1 ) { // tag already been given link in reference list | + | |
+ | if ( $(this).html().indexOf("href") != -1 ) { // tag already been given link in reference list | ||
} | } | ||
else { | else { | ||
− | + | var refID = $(this).attr("ref"); | |
+ | |||
+ | // Add link with ordinal citation inside <cite> tag of all with refID | ||
+ | $( "cite[ref~='" + refID + "']" ).each( function() { | ||
+ | $(this).html( "<a class=\"ref-link\" href=\"#" + refID + "\"><em>[" + citation_idx + "]</em></a>"); | ||
+ | }); | ||
+ | |||
+ | // Add refID to list | ||
+ | scrollLinks[$(this).text()] = refID; | ||
− | + | // Add appropriate li to the references list | |
− | + | $("#reflist").append("<li id=\"" + refID + "\">" + references[refID] + "</li>"); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | citation_idx = citation_idx + 1; | |
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | }); // end | + | }); // end citetag.each |
− | + | }); // end document.ready | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | }); | + | |
// for smooth scrolling | // for smooth scrolling |
Revision as of 23:12, 13 September 2015
// Implements the tag. Requires a "ref" attribute that corresponds to one listed in references.json and that // references.json be included in the global scope var scrollLinks = {};
$(document).ready(function() {
var citation_idx = 1; // On first encounter, fill in all <cite> tags on the page with a certain reference $( "cite" ).each( function() { if ( $(this).html().indexOf("href") != -1 ) { // tag already been given link in reference list } else { var refID = $(this).attr("ref"); // Add link with ordinal citation inside <cite> tag of all with refID $( "cite[ref~='" + refID + "']" ).each( function() { $(this).html( "<a class=\"ref-link\" href=\"#" + refID + "\">[" + citation_idx + "]</a>"); }); // Add refID to list scrollLinks[$(this).text()] = refID; // Add appropriate li to the references list$("#reflist").append("
citation_idx = citation_idx + 1; } }); // end citetag.each
}); // end document.ready
// for smooth scrolling function scrollToAnchor(aid){
var aTag = $('#'+aid); if(aTag.length){ $('html, body').animate({scrollTop:$(aTag).position().top}, 'slow'); }
}