Created
December 8, 2011 15:16
-
-
Save czj/1447253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function init_checkout_selection_table(id) { | |
var table = $(id); | |
var clicked_td = null; | |
// Clicking on the input box changes the row to active | |
// Add this behaviour + simulate the first click | |
// Use triggerHandler to only execute the function (the input is already clicked) | |
table.find('input').on('click', function(event) { | |
table.find('.active').removeClass('active'); | |
clicked_td = $(this).closest('td'); | |
clicked_td.closest('tr').addClass('active'); | |
}).filter(':checked').triggerHandler('click'); | |
// Clicking on the whole table row clicks the input | |
// Clicking an input also clicks an the TD that contains it | |
// We have to prevent this behavior (detect if the current TD doesn't contain a INPUT) | |
// We cannot use stopPropagation() because event has to propagate up to the <form> | |
// We have to remember which TD has just been clicked ! | |
table.find('td').click(function(event) { | |
var td = $(this); | |
if (!td.is(clicked_td)) | |
td.closest('tr').find('input[type=radio]').click(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment