Difference between revisions of "MediaWiki:Common.js"
From EG1004 Lab Manual
Line 3: | Line 3: | ||
function getKmaps() { | function getKmaps() { | ||
var arrKmapsTBH = new Array(); | var arrKmapsTBH = new Array(); | ||
var | var arrTables = document.getElementsByTagName("table"); | ||
for (var i in arrTables) { | |||
for (var | if (arrTables[i].className == "kmap km_highlight_8ls") { | ||
if ( | |||
alert("found one!"); | alert("found one!"); | ||
arrKmapsTBH.push(elTable); | arrKmapsTBH.push(elTable); | ||
Line 30: | Line 29: | ||
//check for 8-cell highlight | //check for 8-cell highlight | ||
var full = true; | var full = true; | ||
for ( | for (i in kmap) { | ||
for ( | for (j in kmap[i]) { | ||
if ( | if (kmap[i][j].innerHTML == "0") full = false; | ||
} | } | ||
} | } | ||
Line 38: | Line 37: | ||
//check for 4-cell highlight | //check for 4-cell highlight | ||
full = true; | full = true; | ||
for ( | for (i=0;i<kmap.length;i++) { | ||
for ( | for (j=0;j<kmap[i].length;j++) { | ||
if ((kmap[i][j].innerHTML == "1") && (j == 0)) { | if ((kmap[i][j].innerHTML == "1") && (j == 0)) { | ||
} | } | ||
if ((kmap[i][j].innerHTML == "1")) { | if ((kmap[i][j].innerHTML == "1")) { | ||
kmap[i][j].style.border = " | kmap[i][j].style.border = "3px solid black"; | ||
} | } | ||
} | } | ||
Line 52: | Line 51: | ||
function highlight_kmaps() { | function highlight_kmaps() { | ||
var arrKmaps = getKmaps(); | var arrKmaps = getKmaps(); | ||
for ( | for (var i in arrKmaps) { | ||
highlightKmap( | highlightKmap(arrKmaps[i]); | ||
} | } | ||
} | } | ||
addOnloadHook( highlight_kmaps ); | addOnloadHook( highlight_kmaps ); |
Revision as of 04:36, 4 August 2010
/* Any JavaScript here will be loaded for all users on every page load. */ function getKmaps() { var arrKmapsTBH = new Array(); var arrTables = document.getElementsByTagName("table"); for (var i in arrTables) { if (arrTables[i].className == "kmap km_highlight_8ls") { alert("found one!"); arrKmapsTBH.push(elTable); } } return arrKmapsTBH; } function highlightKmap(kmapTable) { var tblBody = kmapTable.getElementsByTagName("tbody")[0]; var tblNumRows = tblBody.childNodes.length; var tblNumCols = tblBody.childNodes[0].childNodes.length; var kmap = new Array(); for (var i=2;i<tblNumRows;i++){ kmapRow = new Array(); for (var j=2;j<tblNumCols;j++) { kmapRow.push(tblBody.childNodes[i].childNodes[j]); } kmap.push(kmapRow); } //check for 8-cell highlight var full = true; for (i in kmap) { for (j in kmap[i]) { if (kmap[i][j].innerHTML == "0") full = false; } } //check for 4-cell highlight full = true; for (i=0;i<kmap.length;i++) { for (j=0;j<kmap[i].length;j++) { if ((kmap[i][j].innerHTML == "1") && (j == 0)) { } if ((kmap[i][j].innerHTML == "1")) { kmap[i][j].style.border = "3px solid black"; } } } } function highlight_kmaps() { var arrKmaps = getKmaps(); for (var i in arrKmaps) { highlightKmap(arrKmaps[i]); } } addOnloadHook( highlight_kmaps );