Difference between revisions of "MediaWiki:Common.js"

From EG1004 Lab Manual
Jump to: navigation, search
Line 4: Line 4:
     var arrKmapsTBH = new Array();
     var arrKmapsTBH = new Array();
     var arrTables = document.getElementsByTagName("table");
     var arrTables = document.getElementsByTagName("table");
     for (elTable in arrTables) {
     for (var elTable in arrTables) {
         if (elTable.className == "kmap km_highlight_8ls") {
         if (elTable.className == "kmap km_highlight_8ls") {
             alert("found one!");
             alert("found one!");
Line 19: Line 19:


     var kmap = new Array();
     var kmap = new Array();
     for (i=2;i<tblNumRows;i++){
     for (var i=2;i<tblNumRows;i++){
         kmapRow = new Array();
         kmapRow = new Array();
         for (j=2;j<tblNumCols;j++) {
         for (var j=2;j<tblNumCols;j++) {
             kmapRow.push(tblBody.childNodes[i].childNodes[j]);
             kmapRow.push(tblBody.childNodes[i].childNodes[j]);
         }
         }
Line 29: Line 29:
     //check for 8-cell highlight
     //check for 8-cell highlight
     var full = true;
     var full = true;
     for (kmapRow in kmap) {
     for (var kmapRow in kmap) {
         for (cell in kmapRow) {
         for (var cell in kmapRow) {
             if (cell.innerHTML == "1") full = false;
             if (cell.innerHTML == "1") full = false;
         }
         }
Line 36: Line 36:


     //check for 4-cell highlight
     //check for 4-cell highlight
     var full = true;
     full = true;
     for (i=0;i<kmap.length;i++) {
     for (var i=0;i<kmap.length;i++) {
         for (j=0;j<kmap[i].length;j++) {
         for (var j=0;j<kmap[i].length;j++) {
             if ((kmap[i][j].innerHTML == "1") && (j == 0)) {
             if ((kmap[i][j].innerHTML == "1") && (j == 0)) {
                  
                  

Revision as of 03:59, 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 elTable in arrTables) {
        if (elTable.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 (var kmapRow in kmap) {
        for (var cell in kmapRow) {
            if (cell.innerHTML == "1") full = false;
        }
    }

    //check for 4-cell highlight
    full = true;
    for (var i=0;i<kmap.length;i++) {
        for (var 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 = "thick solid black";
            }
        }
    }
}

function highlight_kmaps() {
    var arrKmaps = getKmaps();
    for (kmap in arrKmaps) {
        highlightKmap(kmap);
    }
}

addOnloadHook( highlight_kmaps );