Template:Team:Groningen/Header/AncestorLinks.js

From 2009.igem.org

(Difference between revisions)
(Trying to modify top heading.)
m
 
(4 intermediate revisions not shown)
Line 1: Line 1:
-
var firstHeadingNode = document.getElementById('firstHeading');
+
function createAncestorLinks() {
-
if (firstHeadingNode) {
+
  var firstHeadingNode = document.getElementById('content').getElementsByTagName('h1')[0];
-
  var pageTitle = firstHeadingNode.innerHTML;
+
  if (firstHeadingNode) {
-
  var prefix = pageTitle.substring(0,pageTitle.indexOf('Team:Groningen'));
+
    var pageTitle = firstHeadingNode.innerHTML;
-
  firstHeadingNode.innerHTML = prefix;
+
    var prefix = pageTitle.substring(0,pageTitle.indexOf('Team:Groningen'));
-
  var pnc = wgPageName.split('/');
+
    firstHeadingNode.innerHTML = prefix;
-
  var tc = wgTitle.split('/');
+
    var pnc = wgPageName.split('/');
-
  for(var i=0; i<pnc.length; i++) {
+
    var tc = wgTitle.split('/');
-
    var c = tc[i];
+
    for(var i=0; i<pnc.length; i++) {
-
    var p = pnc.slice(0,i+1).join('/');
+
      var c = tc[i];
-
    if (i>0) firstHeadingNode.appendChild(document.createTextNode(' > '));
+
      var p = pnc.slice(0,i+1).join('/');
-
    if (i+1<pnc.length) {
+
      if (i>0) firstHeadingNode.appendChild(document.createTextNode(' > '));
-
      var link = document.createElement('a');
+
      if (i+1<pnc.length) {
-
      link.href = wgArticlePath.replace('$1',p);
+
        var link = document.createElement('a');
-
      link.innerHTML = c;
+
        link.href = wgArticlePath.replace('$1',p);
-
      firstHeadingNode.appendChild(link);
+
        link.innerHTML = c;
-
    } else {
+
        firstHeadingNode.appendChild(link);
-
      firstHeadingNode.appendChild(document.createTextNode(c));
+
      } 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);