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

Line 1: Line 1:
 
$(function () {
 
$(function () {
 
     var matches = $('.container-primary').html().match(/<ref>(.*?)<\/ref>/gi);
 
     var matches = $('.container-primary').html().match(/<ref>(.*?)<\/ref>/gi);
     alert($('.container-primary').html());
+
     alert(matches);
 
     var uniqueReferences = [] // collecting unique references
 
     var uniqueReferences = [] // collecting unique references
 
     //Step 1 build reference list
 
     //Step 1 build reference list
Line 8: Line 8:
 
     if (matches != null)
 
     if (matches != null)
 
     {
 
     {
 +
        alert("drin");
 
         matches.forEach(function (match) {
 
         matches.forEach(function (match) {
 
             if (uniqueReferences.indexOf(match) == -1)
 
             if (uniqueReferences.indexOf(match) == -1)
Line 22: Line 23:
 
             referenceList += "<li>" + reference.replace("&lt;ref&gt;", "").replace("&lt;/ref&gt;", "") + "</li>";
 
             referenceList += "<li>" + reference.replace("&lt;ref&gt;", "").replace("&lt;/ref&gt;", "") + "</li>";
 
         });
 
         });
         $("<p>Test</p>").insertAfter($("#blatest"));
+
         $(referenceList + "</ol>").insertAfter($("#References").parent());
 
         var html = $('.container-primary').html();
 
         var html = $('.container-primary').html();
 
         //substitute original links
 
         //substitute original links

Revision as of 02:05, 18 September 2015

$(function () {

   var matches = $('.container-primary').html().match(/<ref>(.*?)<\/ref>/gi);
   alert(matches);
   var uniqueReferences = [] // collecting unique references
   //Step 1 build reference list
   var n = 1;
var referenceList = "
    "; if (matches != null) { alert("drin"); matches.forEach(function (match) { if (uniqueReferences.indexOf(match) == -1) { uniqueReferences.push(match); n++; } else { // do not add this reference again } }); uniqueReferences.forEach(function (reference) { referenceList += "
  1. " + reference.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) + 1) + ']</a>');
           n++;
       });
       $('.container-primary').html(html);
   }
   else
$("

Test5null

").insertAfter($("#References").parent());

});