Difference between revisions of "Team:Aachen/Template:Team:Aachen/JS/references"

(Created page with "$(function() { var matches = $('.container-primary').html().match(/<ref>(.*?)<\/ref>/gi); //Step 1 build reference list var n = 1; var referenceLis...")
 
Line 1: Line 1:
$(function() {
+
$(function () {
 
     var matches = $('.container-primary').html().match(/&lt;ref&gt;(.*?)&lt;\/ref&gt;/gi);
 
     var matches = $('.container-primary').html().match(/&lt;ref&gt;(.*?)&lt;\/ref&gt;/gi);
 +
    var uniqueReferences = [] // collecting unique references
 
     //Step 1 build reference list
 
     //Step 1 build reference list
 
     var n = 1;
 
     var n = 1;
 
     var referenceList = "<ol>";
 
     var referenceList = "<ol>";
 
     if (matches != null) {
 
     if (matches != null) {
matches.forEach(function (match) {
+
        matches.forEach(function (match) {
referenceList += "<li>" + match.replace("&lt;ref&gt;", "").replace("&lt;/ref&gt;", "") + "</li>";
+
            if (match in uniqueReferences == false)
n++;
+
            {
});
+
                uniqueReferences += match;
$(referenceList + "</ol>").insertAfter($("#References").parent());
+
                n++;
var html = $('.container-primary').html();
+
            }
//substitute original links
+
            else
n = 1;//reset counter
+
            {
matches.forEach(function (match) {
+
                // do not add this reference again
html = html.replace(match, '&nbsp;<sup><a href="#References">[' + n + ']</a></sup>');
+
            }           
n++;
+
        });
});
+
        uniq.forEach(function (reference) {
$('.container-primary').html(html);
+
            referenceList += "<li>" + match.replace("&lt;ref&gt;", "").replace("&lt;/ref&gt;", "") + "</li>";
 +
        });
 +
        $(referenceList + "</ol>").insertAfter($("#References").parent());
 +
        var html = $('.container-primary').html();
 +
        //substitute original links
 +
        n = 1;//reset counter
 +
        matches.forEach(function (match) {
 +
            html = html.replace(match, '&nbsp;<sup><a href="#References">[' + uniqueReferences.indexOf(match) + ']</a></sup>');
 +
            n++;
 +
        });
 +
        $('.container-primary').html(html);
 
     }
 
     }
 
});
 
});

Revision as of 19:32, 17 September 2015

$(function () {

   var matches = $('.container-primary').html().match(/<ref>(.*?)<\/ref>/gi);
   var uniqueReferences = [] // collecting unique references
   //Step 1 build reference list
   var n = 1;
var referenceList = "
    "; if (matches != null) { matches.forEach(function (match) { if (match in uniqueReferences == false) { uniqueReferences += match; n++; } else { // do not add this reference again } }); uniq.forEach(function (reference) { referenceList += "
  1. " + match.replace("<ref>", "").replace("</ref>", "") + "
  2. ";
           });
    
    $(referenceList + "
").insertAfter($("#References").parent());
       var html = $('.container-primary').html();
       //substitute original links
       n = 1;//reset counter
       matches.forEach(function (match) {
           html = html.replace(match, ' <a href="#References">[' + uniqueReferences.indexOf(match) + ']</a>');
           n++;
       });
       $('.container-primary').html(html);
   }

});