Template:Team:Groningen/Header/AncestorLinks.js

From 2009.igem.org

(Difference between revisions)
m
 
(5 intermediate revisions not shown)
Line 1: Line 1:
-
var pnc = wgPageName.split('/');
+
function createAncestorLinks() {
-
var tc = wgTitle.split('/');
+
  var firstHeadingNode = document.getElementById('content').getElementsByTagName('h1')[0];
-
for(var i=0; i<pnc.length; i++) {
+
  if (firstHeadingNode) {
-
  var c = tc[i];
+
    var pageTitle = firstHeadingNode.innerHTML;
-
  var p = pnc.slice(0,i+1).join('/');
+
    var prefix = pageTitle.substring(0,pageTitle.indexOf('Team:Groningen'));
-
  if (i>0) document.write(' > ');
+
    firstHeadingNode.innerHTML = prefix;
-
  if (i+1<pnc.length) {
+
    var pnc = wgPageName.split('/');
-
    document.write(c.link(wgArticlePath.replace('$1',p)));
+
    var tc = wgTitle.split('/');
-
  } else {
+
    for(var i=0; i<pnc.length; i++) {
-
    document.write(c);
+
      var c = tc[i];
 +
      var p = pnc.slice(0,i+1).join('/');
 +
      if (i>0) firstHeadingNode.appendChild(document.createTextNode(' > '));
 +
      if (i+1<pnc.length) {
 +
        var link = document.createElement('a');
 +
        link.href = wgArticlePath.replace('$1',p);
 +
        link.innerHTML = c;
 +
        firstHeadingNode.appendChild(link);
 +
      } else {
 +
        var cur = document.createElement('span');
 +
        cur.innerHTML = c;
 +
        firstHeadingNode.appendChild(cur);
 +
      }
 +
    }
   }
   }
}
}
 +
addOnloadHook(createAncestorLinks);

Latest revision as of 15:12, 31 August 2009

function createAncestorLinks() {

 var firstHeadingNode = document.getElementById('content').getElementsByTagName('h1')[0];
 if (firstHeadingNode) {
   var pageTitle = firstHeadingNode.innerHTML;
   var prefix = pageTitle.substring(0,pageTitle.indexOf('Team:Groningen'));
   firstHeadingNode.innerHTML = prefix;
   var pnc = wgPageName.split('/');
   var tc = wgTitle.split('/');
   for(var i=0; i<pnc.length; i++) {
     var c = tc[i];
     var p = pnc.slice(0,i+1).join('/');
     if (i>0) firstHeadingNode.appendChild(document.createTextNode(' > '));
     if (i+1<pnc.length) {
       var link = document.createElement('a');
       link.href = wgArticlePath.replace('$1',p);
       link.innerHTML = c;
       firstHeadingNode.appendChild(link);
     } else {
       var cur = document.createElement('span');
       cur.innerHTML = c;
       firstHeadingNode.appendChild(cur);
     }
   }
 }

} addOnloadHook(createAncestorLinks);