Difference between revisions of "MediaWiki:Common.js"
m |
|||
Line 16: | Line 16: | ||
*/ | */ | ||
var autoCollapse = 2; | var autoCollapse = 2; | ||
− | var collapseCaption = | + | var collapseCaption = 'hide'; |
− | var expandCaption = | + | var expandCaption = 'show'; |
function collapseTable(tableIndex) { | function collapseTable(tableIndex) { | ||
Line 45: | Line 45: | ||
var tableIndex = 0; | var tableIndex = 0; | ||
var NavigationBoxes = new Object(); | var NavigationBoxes = new Object(); | ||
− | var Tables = document.getElementsByTagName( | + | var Tables = document.getElementsByTagName('table'); |
for (var i = 0; i < Tables.length; i++) { | for (var i = 0; i < Tables.length; i++) { | ||
− | if (hasClass(Tables[i], | + | if (hasClass(Tables[i], 'collapsible')) { |
− | + | var HeaderRow = Tables[i].getElementsByTagName('tr')[0]; | |
− | var HeaderRow = Tables[i].getElementsByTagName( | + | |
if (!HeaderRow) { | if (!HeaderRow) { | ||
continue; | continue; | ||
} | } | ||
− | var Header = HeaderRow.getElementsByTagName( | + | var Header = HeaderRow.getElementsByTagName('th')[0]; |
if (!Header) { | if (!Header) { | ||
continue; | continue; | ||
Line 61: | Line 60: | ||
NavigationBoxes[tableIndex] = Tables[i]; | NavigationBoxes[tableIndex] = Tables[i]; | ||
− | Tables[i].setAttribute( | + | Tables[i].setAttribute('id', 'collapsibleTable' + tableIndex); |
− | var Spacer = document.createElement( | + | var Spacer = document.createElement('div'); |
− | Spacer.appendChild(document.createTextNode( | + | Spacer.appendChild(document.createTextNode('\u00a0')); |
− | Spacer.style.cssFloat = | + | Spacer.style.cssFloat = 'left'; |
− | Spacer.style.styleFloat = | + | Spacer.style.styleFloat = 'left'; |
− | Spacer.style.textAlign = | + | Spacer.style.textAlign = 'left'; |
− | Spacer.style.width = | + | Spacer.style.width = '35px'; |
− | var Button = document.createElement( | + | var Button = document.createElement('span'); |
− | var ButtonLink = document.createElement( | + | var ButtonLink = document.createElement('a'); |
var ButtonText = document.createTextNode(collapseCaption); | var ButtonText = document.createTextNode(collapseCaption); | ||
− | Button.style.cssFloat = | + | Button.style.cssFloat = 'right'; |
− | Button.style.styleFloat = | + | Button.style.styleFloat = 'right'; |
− | Button.style.fontSize = | + | Button.style.fontSize = '11px'; |
− | Button.style.fontWeight = | + | Button.style.fontWeight = 'normal'; |
− | Button.style.textAlign = | + | Button.style.textAlign = 'right'; |
− | Button.style.width = | + | Button.style.width = '35px'; |
− | ButtonLink.style.color = | + | ButtonLink.style.color = '#FFFFFF'; |
− | ButtonLink.setAttribute( | + | ButtonLink.setAttribute('id', 'collapseButton' + tableIndex); |
− | ButtonLink.setAttribute( | + | ButtonLink.setAttribute('href', 'javascript:collapseTable(' + tableIndex + ');'); |
ButtonLink.appendChild(ButtonText); | ButtonLink.appendChild(ButtonText); | ||
− | Button.appendChild(document.createTextNode( | + | Button.appendChild(document.createTextNode('[')); |
Button.appendChild(ButtonLink); | Button.appendChild(ButtonLink); | ||
− | Button.appendChild(document.createTextNode( | + | Button.appendChild(document.createTextNode(']')); |
Header.insertBefore(Spacer, Header.childNodes[0]); | Header.insertBefore(Spacer, Header.childNodes[0]); | ||
Line 98: | Line 97: | ||
for (var i = 0; i < tableIndex; i++) { | for (var i = 0; i < tableIndex; i++) { | ||
− | if (hasClass(NavigationBoxes[i], | + | if (hasClass(NavigationBoxes[i], 'collapsed') || (tableIndex >= autoCollapse && hasClass(NavigationBoxes[i], 'autocollapse'))) { |
collapseTable(i); | collapseTable(i); | ||
} | } | ||
− | else if (hasClass(NavigationBoxes[i], | + | else if (hasClass(NavigationBoxes[i], 'innercollapse')) { |
var element = NavigationBoxes[i]; | var element = NavigationBoxes[i]; | ||
while (element = element.parentNode) { | while (element = element.parentNode) { | ||
− | if (hasClass(element, | + | if (hasClass(element, 'outercollapse')) { |
collapseTable(i); | collapseTable(i); | ||
break; | break; | ||
Line 117: | Line 116: | ||
* Code for sortable tables. | * Code for sortable tables. | ||
*/ | */ | ||
− | var upArrow = | + | var upArrow = 'images/5/5b/Sort_up.gif'; |
− | var downArrow = | + | var downArrow = 'images/7/7a/Sort_down.gif'; |
− | var noneArrow = | + | var noneArrow = 'images/e/e8/Sort_none.gif'; |
function sortTablesInit() { | function sortTablesInit() { | ||
Line 129: | Line 128: | ||
idnum++; | idnum++; | ||
} | } | ||
− | + | makeSortable(tables[i]); | |
} | } | ||
} | } | ||
Line 135: | Line 134: | ||
function makeSortable(table) { | function makeSortable(table) { | ||
var firstRow; | var firstRow; | ||
+ | |||
if (table.rows && table.rows.length > 0) { | if (table.rows && table.rows.length > 0) { | ||
if (table.tHead && table.tHead.rows.length > 0) { | if (table.tHead && table.tHead.rows.length > 0) { | ||
Line 142: | Line 142: | ||
} | } | ||
} | } | ||
+ | |||
if (!firstRow) { | if (!firstRow) { | ||
return; | return; | ||
} | } | ||
− | + | ||
for (var i = 0; i < firstRow.cells.length; i++) { | for (var i = 0; i < firstRow.cells.length; i++) { | ||
var cell = firstRow.cells[i]; | var cell = firstRow.cells[i]; | ||
Line 165: | Line 166: | ||
return el.innerText; | return el.innerText; | ||
} | } | ||
+ | |||
var innerText = ''; | var innerText = ''; | ||
var cs = el.childNodes; | var cs = el.childNodes; | ||
var l = cs.length; | var l = cs.length; | ||
+ | |||
for (var i = 0; i < l; i++) { | for (var i = 0; i < l; i++) { | ||
switch (cs[i].nodeType) { | switch (cs[i].nodeType) { | ||
Line 174: | Line 177: | ||
} | } | ||
} | } | ||
+ | |||
return innerText; | return innerText; | ||
} | } | ||
Line 183: | Line 187: | ||
var column = td.cellIndex; | var column = td.cellIndex; | ||
var table = tr.parentNode; | var table = tr.parentNode; | ||
+ | |||
while (table && !(table.tagName && table.tagName.toLowerCase() == 'table')) { | while (table && !(table.tagName && table.tagName.toLowerCase() == 'table')) { | ||
table = table.parentNode; | table = table.parentNode; | ||
} | } | ||
+ | |||
if (!table) { | if (!table) { | ||
return; | return; | ||
Line 192: | Line 198: | ||
return; | return; | ||
} | } | ||
+ | |||
var rowStart = (table.tHead && table.tHead.rows.length > 0 ? 0 : 1); | var rowStart = (table.tHead && table.tHead.rows.length > 0 ? 0 : 1); | ||
var itm = ''; | var itm = ''; | ||
+ | |||
for (var i = rowStart; i < table.rows.length; i++) { | for (var i = rowStart; i < table.rows.length; i++) { | ||
if (table.rows[i].cells.length > column) { | if (table.rows[i].cells.length > column) { | ||
Line 203: | Line 211: | ||
} | } | ||
} | } | ||
+ | |||
sortfn = sortCaseInsensitive; | sortfn = sortCaseInsensitive; | ||
+ | |||
if (itm.match(/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/)) { | if (itm.match(/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/)) { | ||
sortfn = sortDate; | sortfn = sortDate; | ||
Line 212: | Line 222: | ||
if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d$/)) { | if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d$/)) { | ||
sortfn = sortDate; | sortfn = sortDate; | ||
+ | } | ||
if (itm.match(/^[\u00a3$\u20ac]/)) { | if (itm.match(/^[\u00a3$\u20ac]/)) { | ||
sortfn = sortCurrency; | sortfn = sortCurrency; | ||
Line 218: | Line 229: | ||
sortfn = sortNumeric; | sortfn = sortNumeric; | ||
} | } | ||
+ | |||
var reverse = (span.getAttribute('sortdir') == 'down'); | var reverse = (span.getAttribute('sortdir') == 'down'); | ||
var newRows = new Array(); | var newRows = new Array(); | ||
+ | |||
for (var j = rowStart; j < table.rows.length; j++) { | for (var j = rowStart; j < table.rows.length; j++) { | ||
var row = table.rows[j]; | var row = table.rows[j]; | ||
Line 227: | Line 240: | ||
} | } | ||
newRows.sort(sortfn); | newRows.sort(sortfn); | ||
+ | |||
var arrowHTML; | var arrowHTML; | ||
+ | |||
if (reverse) { | if (reverse) { | ||
− | arrowHTML = '<img src="'+ downArrow + '" alt="↓"/>'; | + | arrowHTML = '<img src="' + downArrow + '" alt="↓"/>'; |
newRows.reverse(); | newRows.reverse(); | ||
− | span.setAttribute('sortdir','up'); | + | span.setAttribute('sortdir', 'up'); |
} else { | } else { | ||
− | arrowHTML = '<img src="'+ upArrow + '" alt="↑"/>'; | + | arrowHTML = '<img src="' + upArrow + '" alt="↑"/>'; |
− | span.setAttribute('sortdir','down'); | + | span.setAttribute('sortdir', 'down'); |
} | } | ||
+ | |||
for (var i = 0; i < newRows.length; i++) { | for (var i = 0; i < newRows.length; i++) { | ||
− | if (( | + | if ((' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') == -1) { |
table.tBodies[0].appendChild(newRows[i][0]); | table.tBodies[0].appendChild(newRows[i][0]); | ||
} | } | ||
} | } | ||
+ | |||
for (var i = 0; i < newRows.length; i++) { | for (var i = 0; i < newRows.length; i++) { | ||
− | if (( | + | if ((' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') != -1) { |
table.tBodies[0].appendChild(newRows[i][0]); | table.tBodies[0].appendChild(newRows[i][0]); | ||
} | } | ||
} | } | ||
+ | |||
var spans = getElementsByClassName(tr, 'span', 'sortarrow'); | var spans = getElementsByClassName(tr, 'span', 'sortarrow'); | ||
+ | |||
for (var i = 0; i < spans.length; i++) { | for (var i = 0; i < spans.length; i++) { | ||
− | spans[i].innerHTML = '<img src="'+ noneArrow + '" alt="↓"/>'; | + | spans[i].innerHTML = '<img src="' + noneArrow + '" alt="↓"/>'; |
} | } | ||
+ | |||
span.innerHTML = arrowHTML; | span.innerHTML = arrowHTML; | ||
alternate(table); | alternate(table); | ||
Line 282: | Line 302: | ||
return year + date.substr(0, 2) + date.substr(3, 2); | return year + date.substr(0, 2) + date.substr(3, 2); | ||
} | } | ||
+ | |||
return '00000000'; | return '00000000'; | ||
} | } | ||
Line 289: | Line 310: | ||
return 0; | return 0; | ||
} | } | ||
− | num = parseFloat(num.replace(/,/g, | + | |
+ | num = parseFloat(num.replace(/,/g, '')); | ||
+ | |||
return (isNaN(num) ? 0 : num); | return (isNaN(num) ? 0 : num); | ||
} | } | ||
function sortDate(a, b) { | function sortDate(a, b) { | ||
− | var aa = | + | var aa = dateToSortKey(a[1]); |
− | var bb = | + | var bb = dateToSortKey(b[1]); |
return (aa < bb ? -1 : aa > bb ? 1 : a[2] - b[2]); | return (aa < bb ? -1 : aa > bb ? 1 : a[2] - b[2]); | ||
} | } | ||
function sortCurrency(a, b) { | function sortCurrency(a, b) { | ||
− | var aa = | + | var aa = parseFloat(a[1].replace(/[^0-9.]/g, '')); |
− | var bb = | + | var bb = parseFloat(b[1].replace(/[^0-9.]/g, '')); |
return (aa != bb ? aa - bb : a[2] - b[2]); | return (aa != bb ? aa - bb : a[2] - b[2]); | ||
} | } | ||
function sortNumeric(a, b) { | function sortNumeric(a, b) { | ||
− | var aa = | + | var aa = parseFloat(a[1]); |
− | var bb = | + | var bb = parseFloat(b[1]); |
return (aa != bb ? aa - bb : a[2] - b[2]); | return (aa != bb ? aa - bb : a[2] - b[2]); | ||
} | } | ||
Line 325: | Line 348: | ||
for (var i = 0; i < tableBodies.length; i++) { | for (var i = 0; i < tableBodies.length; i++) { | ||
var tableRows = tableBodies[i].getElementsByTagName('tr'); | var tableRows = tableBodies[i].getElementsByTagName('tr'); | ||
+ | |||
for (var j = 0; j < tableRows.length; j++) { | for (var j = 0; j < tableRows.length; j++) { | ||
var oldClasses = tableRows[j].className.split(' '); | var oldClasses = tableRows[j].className.split(' '); | ||
var newClassName = ''; | var newClassName = ''; | ||
+ | |||
for (var k = 0; k < oldClasses.length; k++) { | for (var k = 0; k < oldClasses.length; k++) { | ||
if (oldClasses[k] != '' && oldClasses[k] != 'even' && oldClasses[k] != 'odd') { | if (oldClasses[k] != '' && oldClasses[k] != 'even' && oldClasses[k] != 'odd') { | ||
− | newClassName += oldClasses[k] + | + | newClassName += oldClasses[k] + ' '; |
} | } | ||
} | } | ||
− | tableRows[j].className = newClassName + (j % 2 == 0 ? | + | |
+ | tableRows[j].className = newClassName + (j % 2 == 0 ? 'even' : 'odd'); | ||
} | } | ||
} | } | ||
} | } |
Revision as of 19:56, 24 December 2009
/* Any JavaScript here will be loaded for all users on every page load. */ /** * Tests if a particular element possesses a class. */ var hasClass = (function () { var reCache = {}; return function (element, className) { return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); }; })(); /** * Code for collapsible tables. */ var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show'; function collapseTable(tableIndex) { var Button = document.getElementById("collapseButton" + tableIndex); var Table = document.getElementById("collapsibleTable" + tableIndex); if (!Table || !Button) { return false; } var Rows = Table.rows; if (Button.firstChild.data == collapseCaption) { for (var i = 1; i < Rows.length; i++) { Rows[i].style.display = "none"; } Button.firstChild.data = expandCaption; } else { for (var i = 1; i < Rows.length; i++) { Rows[i].style.display = Rows[0].style.display; } Button.firstChild.data = collapseCaption; } } function createCollapseButtons() { var tableIndex = 0; var NavigationBoxes = new Object(); var Tables = document.getElementsByTagName('table'); for (var i = 0; i < Tables.length; i++) { if (hasClass(Tables[i], 'collapsible')) { var HeaderRow = Tables[i].getElementsByTagName('tr')[0]; if (!HeaderRow) { continue; } var Header = HeaderRow.getElementsByTagName('th')[0]; if (!Header) { continue; } NavigationBoxes[tableIndex] = Tables[i]; Tables[i].setAttribute('id', 'collapsibleTable' + tableIndex); var Spacer = document.createElement('div'); Spacer.appendChild(document.createTextNode('\u00a0')); Spacer.style.cssFloat = 'left'; Spacer.style.styleFloat = 'left'; Spacer.style.textAlign = 'left'; Spacer.style.width = '35px'; var Button = document.createElement('span'); var ButtonLink = document.createElement('a'); var ButtonText = document.createTextNode(collapseCaption); Button.style.cssFloat = 'right'; Button.style.styleFloat = 'right'; Button.style.fontSize = '11px'; Button.style.fontWeight = 'normal'; Button.style.textAlign = 'right'; Button.style.width = '35px'; ButtonLink.style.color = '#FFFFFF'; ButtonLink.setAttribute('id', 'collapseButton' + tableIndex); ButtonLink.setAttribute('href', 'javascript:collapseTable(' + tableIndex + ');'); ButtonLink.appendChild(ButtonText); Button.appendChild(document.createTextNode('[')); Button.appendChild(ButtonLink); Button.appendChild(document.createTextNode(']')); Header.insertBefore(Spacer, Header.childNodes[0]); Header.insertBefore(Button, Header.childNodes[0]); tableIndex++; } } for (var i = 0; i < tableIndex; i++) { if (hasClass(NavigationBoxes[i], 'collapsed') || (tableIndex >= autoCollapse && hasClass(NavigationBoxes[i], 'autocollapse'))) { collapseTable(i); } else if (hasClass(NavigationBoxes[i], 'innercollapse')) { var element = NavigationBoxes[i]; while (element = element.parentNode) { if (hasClass(element, 'outercollapse')) { collapseTable(i); break; } } } } } addOnloadHook(createCollapseButtons); /** * Code for sortable tables. */ var upArrow = 'images/5/5b/Sort_up.gif'; var downArrow = 'images/7/7a/Sort_down.gif'; var noneArrow = 'images/e/e8/Sort_none.gif'; function sortTablesInit() { var idnum = 0; var tables = getElementsByClassName(document, 'table', 'sorts'); for (var i = 0; i < tables.length; i++) { if (!tables[i].id) { tables[i].setAttribute('id', 'sortable_table_id_' + idnum); idnum++; } makeSortable(tables[i]); } } function makeSortable(table) { var firstRow; if (table.rows && table.rows.length > 0) { if (table.tHead && table.tHead.rows.length > 0) { firstRow = table.tHead.rows[table.tHead.rows.length - 1]; } else { firstRow = table.rows[0]; } } if (!firstRow) { return; } for (var i = 0; i < firstRow.cells.length; i++) { var cell = firstRow.cells[i]; if ((' ' + cell.className + ' ').indexOf(' unsortable ') == -1) { cell.innerHTML += ' <a href="#" class="sortheader" onclick="reSortTable(this);return false;"><span class="sortarrow"><img src="' + noneArrow + '" alt="↓"/></span></a>'; } } alternate(table); } function getInnerText(el) { if (typeof el == 'string' || typeof el == 'undefined') { return el; } if (el.textContent) { return el.textContent; } if (el.innerText) { return el.innerText; } var innerText = ''; var cs = el.childNodes; var l = cs.length; for (var i = 0; i < l; i++) { switch (cs[i].nodeType) { case 1: innerText += getInnerText(cs[i]); break; case 3: innerText += cs[i].nodeValue; break; } } return innerText; } function reSortTable(lnk) { var span = lnk.getElementsByTagName('span')[0]; var td = lnk.parentNode; var tr = td.parentNode; var column = td.cellIndex; var table = tr.parentNode; while (table && !(table.tagName && table.tagName.toLowerCase() == 'table')) { table = table.parentNode; } if (!table) { return; } if (table.rows.length <= 1) { return; } var rowStart = (table.tHead && table.tHead.rows.length > 0 ? 0 : 1); var itm = ''; for (var i = rowStart; i < table.rows.length; i++) { if (table.rows[i].cells.length > column) { itm = getInnerText(table.rows[i].cells[column]); itm = itm.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, ''); if (itm != '') { break; } } } sortfn = sortCaseInsensitive; if (itm.match(/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/)) { sortfn = sortDate; } if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/)) { sortfn = sortDate; } if (itm.match(/^\d\d[\/.-]\d\d[\/.-]\d\d$/)) { sortfn = sortDate; } if (itm.match(/^[\u00a3$\u20ac]/)) { sortfn = sortCurrency; } if (itm.match(/^[\d.,]+\%?$/)) { sortfn = sortNumeric; } var reverse = (span.getAttribute('sortdir') == 'down'); var newRows = new Array(); for (var j = rowStart; j < table.rows.length; j++) { var row = table.rows[j]; var keyText = getInnerText(row.cells[column]); var oldIndex = (reverse ? -j : j); newRows[newRows.length] = new Array(row, keyText, oldIndex); } newRows.sort(sortfn); var arrowHTML; if (reverse) { arrowHTML = '<img src="' + downArrow + '" alt="↓"/>'; newRows.reverse(); span.setAttribute('sortdir', 'up'); } else { arrowHTML = '<img src="' + upArrow + '" alt="↑"/>'; span.setAttribute('sortdir', 'down'); } for (var i = 0; i < newRows.length; i++) { if ((' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') == -1) { table.tBodies[0].appendChild(newRows[i][0]); } } for (var i = 0; i < newRows.length; i++) { if ((' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') != -1) { table.tBodies[0].appendChild(newRows[i][0]); } } var spans = getElementsByClassName(tr, 'span', 'sortarrow'); for (var i = 0; i < spans.length; i++) { spans[i].innerHTML = '<img src="' + noneArrow + '" alt="↓"/>'; } span.innerHTML = arrowHTML; alternate(table); } function dateToSortKey(date) { if (date.length == 11) { switch (date.substr(3, 3).toLowerCase()) { case 'jan': var month = '01'; break; case 'feb': var month = '02'; break; case 'mar': var month = '03'; break; case 'apr': var month = '04'; break; case 'may': var month = '05'; break; case 'jun': var month = '06'; break; case 'jul': var month = '07'; break; case 'aug': var month = '08'; break; case 'sep': var month = '09'; break; case 'oct': var month = '10'; break; case 'nov': var month = '11'; break; case 'dec': var month = '12'; break; } return date.substr(7, 4) + month + date.substr(0, 2); } else if (date.length == 10) { return date.substr(6, 4) + date.substr(0, 2) + date.substr(3, 2); } else if (date.length == 8) { year = date.substr(6, 2); if (parseInt(year) < 50) { year = '20' + year; } else { year = '19' + year; } return year + date.substr(0, 2) + date.substr(3, 2); } return '00000000'; } function parseFloat(num) { if (!num) { return 0; } num = parseFloat(num.replace(/,/g, '')); return (isNaN(num) ? 0 : num); } function sortDate(a, b) { var aa = dateToSortKey(a[1]); var bb = dateToSortKey(b[1]); return (aa < bb ? -1 : aa > bb ? 1 : a[2] - b[2]); } function sortCurrency(a, b) { var aa = parseFloat(a[1].replace(/[^0-9.]/g, '')); var bb = parseFloat(b[1].replace(/[^0-9.]/g, '')); return (aa != bb ? aa - bb : a[2] - b[2]); } function sortNumeric(a, b) { var aa = parseFloat(a[1]); var bb = parseFloat(b[1]); return (aa != bb ? aa - bb : a[2] - b[2]); } function sortCaseInsensitive(a, b) { var aa = a[1].toLowerCase(); var bb = b[1].toLowerCase(); return (aa < bb ? -1 : aa > bb ? 1 : a[2] - b[2]); } function sortDefault(a, b) { return (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : a[2] - b[2]); } function alternate(table) { var tableBodies = table.getElementsByTagName('tbody'); for (var i = 0; i < tableBodies.length; i++) { var tableRows = tableBodies[i].getElementsByTagName('tr'); for (var j = 0; j < tableRows.length; j++) { var oldClasses = tableRows[j].className.split(' '); var newClassName = ''; for (var k = 0; k < oldClasses.length; k++) { if (oldClasses[k] != '' && oldClasses[k] != 'even' && oldClasses[k] != 'odd') { newClassName += oldClasses[k] + ' '; } } tableRows[j].className = newClassName + (j % 2 == 0 ? 'even' : 'odd'); } } }