Team:Freiburg/Templates/html/inlinejs.html

From 2014.igem.org

(Difference between revisions)
Line 2: Line 2:
<script>
<script>
(function(){
(function(){
-
   var DEBUG = true;
+
   function hasClass( elem, klass ) {
-
  // grab navigation links
+
    return (" " + elem.className + " " ).indexOf( " "+klass+" " ) > -1;
-
  var navLinks = document.getElementsByTagName('nav');
+
   }
-
console.log('length: '+ navLinks.length);
+
-
  if (navLinks.length > 0) {
+
-
console.log(navLinks);navLinks = navLinks[0];}
+
-
   navLinks = navLinks.getElementsByTagName('a');
+
-
   // check all links' href attributes for equality with url
+
   // remove unnecessary css
-
  var currentPath = location.pathname;
+
   if (hasClass(document.body, 'mediawiki')){
-
   if (DEBUG) console.log("Current Path: " + currentPath);
+
    var unwantedStylesheets = document.head.querySelectorAll('head link[rel="stylesheet"], head style[type="text/css"]');
-
  for (var i=0;i<navLinks.length;i++) {
+
    for (var i=0;i<unwantedStylesheets.length; i++){
-
    var href = navLinks[i].getAttribute('href')
+
       unwantedStylesheets[i].remove();
-
    if (DEBUG) console.log(href);
+
-
    if (href.indexOf(currentPath) !== -1){
+
-
       // set active state
+
-
      if (DEBUG) console.log('Setting active state for: ' + href);
+
-
      var parent = navLinks[i].parentNode;
+
-
      while (parent.tagName != 'NAV') {
+
-
        // set active class for all ancestral list items
+
-
        if (parent.tagName == 'LI') {
+
-
          parent.setAttribute('class', 'active');
+
-
        }
+
-
        parent = parent.parentNode;
+
-
      }
+
     }
     }
   }
   }

Revision as of 18:14, 7 October 2014