javascript:PMA_markRowsInit speedup

This commit is contained in:
Sebastian Mendel
2005-10-20 12:31:52 +00:00
parent 53f593fa58
commit 3d26b10f0d

View File

@@ -468,82 +468,70 @@ var marked_row = new Array;
* *
*/ */
function PMA_markRowsInit() { function PMA_markRowsInit() {
// in every table ... // for every table row ...
var tables = document.getElementsByTagName('table'); var rows = document.getElementsByTagName('tr');
for (var t=0; t<tables.length; t++) { for ( var i = 0; i < rows.length; i++ ) {
// ... with the class 'data' ... // ... with the class 'odd' or 'even' ...
if ( 'data' != tables[t].className ) { if ( 'odd' != rows[i].className && 'even' != rows[i].className ) {
continue; continue;
} }
// ... add event listeners ...
// ... in tbody ... // ... to highlight the row on mouseover ...
var body = tables[t].getElementsByTagName('tbody') if ( navigator.appName == 'Microsoft Internet Explorer' ) {
// ... for every row ('tr') ... // but only for IE, other browsers are handled by :hover in css
var rows = body[0].getElementsByTagName('tr'); rows[i].onmouseover = function() {
this.className += ' hover';
for (var i = 0; i < rows.length; i++) {
// ... add event listeners ...
// ... to highlight the row on mouseover ...
if ( navigator.appName == 'Microsoft Internet Explorer' ) {
// but only for IE, other browsers are handled by :hover in css
rows[i].onmouseover = function() {
this.className += ' hover';
}
rows[i].onmouseout = function() {
this.className = this.className.replace(' hover', '');
}
}
// ... and to mark the row on click ...
rows[i].onmousedown = function() {
var unique_id;
var checkbox;
var checkbox = this.getElementsByTagName('input')[0];
if ( checkbox && checkbox.type == 'checkbox' ) {
if ( checkbox.id.length > 0 ) {
unique_id = checkbox.id;
} else {
unique_id = checkbox.name + checkbox.value;
}
} else if ( this.id.length > 0 ) {
unique_id = this.id;
} else {
return;
}
if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
marked_row[unique_id] = true;
} else {
marked_row[unique_id] = false;
}
if ( marked_row[unique_id] ) {
this.className += ' marked';
} else {
this.className = this.className.replace(' marked', '');
}
if ( checkbox && checkbox.disabled == false ) {
checkbox.checked = marked_row[unique_id];
}
} }
rows[i].onmouseout = function() {
this.className = this.className.replace( ' hover', '' );
}
}
// ... and to mark the row on click ...
rows[i].onmousedown = function() {
var unique_id;
var checkbox;
// ... and disable label ... var checkbox = this.getElementsByTagName( 'input' )[0];
var labeltag = rows[i].getElementsByTagName('label')[0]; if ( checkbox && checkbox.type == 'checkbox' ) {
if ( labeltag ) { unique_id = checkbox.name + checkbox.value;
labeltag.onclick = function() { } else if ( this.id.length > 0 ) {
return false; unique_id = this.id;
} } else {
} return;
// .. and checkbox clicks
var checkbox = rows[i].getElementsByTagName('input')[0];
if ( checkbox ) {
checkbox.onclick = function() {
// opera does not recognize return false;
this.checked = ! this.checked;
}
} }
if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
marked_row[unique_id] = true;
} else {
marked_row[unique_id] = false;
}
if ( marked_row[unique_id] ) {
this.className += ' marked';
} else {
this.className = this.className.replace(' marked', '');
}
if ( checkbox && checkbox.disabled == false ) {
checkbox.checked = marked_row[unique_id];
}
} }
// ... and disable label ...
var labeltag = rows[i].getElementsByTagName('label')[0];
if ( labeltag ) {
labeltag.onclick = function() {
return false;
}
}
// .. and checkbox clicks
var checkbox = rows[i].getElementsByTagName('input')[0];
if ( checkbox ) {
checkbox.onclick = function() {
// opera does not recognize return false;
this.checked = ! this.checked;
}
}
} }
} }
window.onload=PMA_markRowsInit; window.onload=PMA_markRowsInit;