I have a global jQuery object defined in an external file:
var App = function () {
function handleTableRowSelection()
{
/*
TRs being generated dynamically via json AJAX call.
Select nearest static element then pass in TRs.
*/
$('table.allow-selection tbody').on('click', 'tr', function(e)
{
/*Don't change row class if clicking on a link (HTMLAnchorElement), or any other sub-element*/
if ((e.target instanceof HTMLTableCellElement) == true)
{
var row = $(this);
row.find('td').each(function()
{
$(this).toggleClass('user-selected');
});
}
});
}
return {
init: function ()
{
handleTableRowSelection();
},
};
}();
When I call App.init(); in my $(document).ready it works fine (from my master blade template), even though I'm not passing any parameters to handleTableRowSelection.
When I try to call App.handleTableRowSelection('#details', 'table.allow-selection tbody tr') from a sub-template for a single view, I get "undefined is not a function".
I'm calling the init method in my master template like so: App.init();
I thought I'd be able to access the App object (my IDE code-completion finds it), is this not the case?