Took me a while(attempts) to get this working exactly how I want but I thought I would post it here for suggestions to improvements(performance/accessibility).
$('table').each(function(){
var $table= $(this), $cell, $row;
/*
* Badass Table Row
* 1. Click row redirect to url
* @param tr[data-url]
* 2. Double click row load link. First checks last cell or any link
* 3. Cells with checkboxes, phpmyadmin style click cell toggles child checkbox
*/
$table.find('tr').each(function(){
$row = $(this);
var url = $row.attr("data-url");
if(url && url.length){
$row.addClass("table-row-click").find("td").click(function(){
window.location = url;
return false;
});
}
$row.children('td').each(function(){
$cell = $(this);
if($cell.find("input[type=checkbox]").length){
$cell.addClass("table-cell-hasCheckbox").click(function(e) {
if(e.target.type !== 'checkbox') $(':checkbox', this).trigger('click');
});
}
// Double click open edit link
if(!$table.hasClass("table-noDoubleClick")){
$cell.dblclick(function(e){
var linkEl = $(this).parents('tr').find('td:last-child a');
if(!linkEl.length) linkEl = $(this).parents('tr').find('td a');
var linkElHref = linkEl.attr('href');
// Check if has href and http protocol
if(linkElHref && (!linkElHref.length || linkEl.prop('protocol').indexOf("http") !== 0)){
e.preventDefault();
return false;
}
if (linkElHref && linkEl.attr('onclick') === undefined && !linkEl.hasClass("popup")) {
document.location = linkElHref;
} else {
linkEl.click();
}
});
}
}); // end CELLS
}); // end ROWS
}); // end TABLE