User:Dnessett/Template/Bref/Clean Back Links.js

// Helper Javascript code that removes backlinks and upper arrows from formated data. // Useful for text that calls the Bref template, since in that case backlinks point to display:none text.

var brefElementNodeType = 1; function BrefHideBackLinks { // Create array of all Tags with classname "references" and tagName "ol" var brefAllReferencesTags = new Array; brefAllReferencesTags = getElementsByClassName(document.body, "ol","references"); //Loop through list elements, blanking text in all child nodes other than and for (var i in brefAllReferencesTags) {   var brefRefList = brefAllReferencesTags[i].childNodes; for (var j in brefRefList) {     // Leave embedded text between citation entries alone if (brefRefList[j].nodeType == brefElementNodeType) {       var brefRefListEntry = brefRefList[j].childNodes; for (var k = brefRefListEntry.length - 1; k >= 0; --k) {         // Only retain the and tag text. Handle IE as well as other browsers if (brefRefListEntry[k].nodeType != brefElementNodeType || (brefRefListEntry[k].tagName != "CITE" && brefRefListEntry[k].tagName != "SPAN")) {           if (brefRefListEntry[k].innerText) // IE inner node {             brefRefListEntry[k].innerText = ""; }           else if( brefRefListEntry[k].nodeName && brefRefListEntry[k].nodeName == "#text") { // IE list entry text brefRefListEntry[k].nodeValue = ""; }           else if (brefRefListEntry[k].textContent) { // Others brefRefListEntry[k].textContent = ""; }           }          }        }      }    }  }

// // hook BrefHideBackLinks // addOnloadHook (     function         {        BrefHideBackLinks;        }    );