MediaWiki: Common.js
From EG1004 Lab Manual
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* 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") { arrKmapsTBH.push(arrTables[i]); } } return arrKmapsTBH; } function highlightCells(kmap, i1, j1, i2, j2) { for (var i=i1;i<=i2;i=(i+1)%2) for (var j=j1;j<=j2;j=(j+1)%4) kmap[i][j].style.border = "3px solid red"; } function highlightKmap(kmapTable) { var kmap = new Array(); for (var i=2;i<4;i++){ kmapRow = new Array(); for (var j=2;j<6;j++) { kmapRow.push(kmapTable.rows[i].cells[j]); } kmap.push(kmapRow); } //check for 8-cell highlight var highlight = true; for (i in kmap) { for (j in kmap[i]) { if ((kmap[i][j].innerHTML == "0") || (kmap[i][j].innerHTML == "0\n")) highlight = false; } } if (highlight) highlightCells(kmap, 0, 0, 1, 3); //check for 4-cell highlight for (i in kmap) { for (j in kmap[i]) { if ((kmap[i][j].innerHTML == "1") || (kmap[i][j].innerHTML == "1\n")) { if ((kmap[i][j].borderTopColor == "red") || (kmap[i][j].borderBottomColor == "red")) continue; //check row highlight = true; for (k in kmap[i]) { if ((kmap[i][k].innerHTML == "0") || (kmap[i][k].innerHTML == "0\n")) highlight = false; } if (highlight) highlightCells(kmap, i, 0, i, 3); else { //check forward square highlight = true; if ((kmap[i][(j+1)%4].innerHTML == "0") || (kmap[i][(j+1)%4].innerHTML == "0\n")) highlight = false; if ((kmap[(i+1)%2][j].innerHTML == "0") || (kmap[(i+1)%2][j].innerHTML == "0\n")) highlight = false; if ((kmap[(i+1)%2][(j+1)%4].innerHTML == "0") || (kmap[(i+1)%2][(j+1)%4].innerHTML == "0\n")) highlight = false; if (highlight) highlightCells(kmap, 0, j, 1, (j+1)%4); else if (j > 0) { highlight = true; if ((kmap[i][j-1].innerHTML == "0") || (kmap[i][j-1].innerHTML == "0\n")) highlight = false; if ((kmap[(i+1)%2][j].innerHTML == "0") || (kmap[(i+1)%2][j].innerHTML == "0\n")) highlight = false; if ((kmap[(i+1)%2][j-1].innerHTML == "0") || (kmap[(i+1)%2][j-1].innerHTML == "0\n")) highlight = false; if (highlight) highlightCells(kmap, 0, j, 1, j-1); } } } } } } function highlight_kmap_0() { var kmapTable = document.getElementById("kmap_0"); var kmap = new Array(); for (var i=2;i<4;i++){ kmapRow = new Array(); for (var j=2;j<6;j++) { kmapRow.push(kmapTable.rows[i].cells[j]); } kmap.push(kmapRow); } kmap[0][1].style.borderTop = "3px solid red"; kmap[0][1].style.borderLeft = "3px solid red"; kmap[1][1].style.borderLeft = "3px solid red"; kmap[1][1].style.borderBottom = "3px solid red"; kmap[0][2].style.borderTop = "3px solid red"; kmap[0][2].style.borderRight = "3px solid red"; kmap[1][2].style.borderRight = "3px solid red"; kmap[1][2].style.borderBottom = "3px solid red"; kmap[0][2].style.borderTop = "3px solid red"; kmap[0][2].style.borderLeft = "3px solid red"; kmap[0][2].style.borderBottom = "3px solid red"; kmap[0][3].style.borderTop = "3px solid red"; kmap[0][3].style.borderRight = "3px solid red"; kmap[0][3].style.borderBottom = "3px solid red"; } addOnloadHook( highlight_kmap_0 );