Or: How can I structure the code in my application.js file of my Rails 3.0.10 app, or distribute it (logically) among various files so that I know what the bleep is going on?
Currently my application.js is running to 700 lines of code. It's mostly flat with lots of jQuery bits like:
//////////// the following code is for the need_email_confirmation page and user_sign_in page
$('body').delegate('#sign_up_resend_confirmation', 'click', function(event) {
event.preventDefault();
$('form#new_user').submit();
});
Sometimes I use comment delimiters as above to make different sections, but it seems kind of ... (is it ok to say "ghetto"?). Lots of code like the above, all inside of a $(document).ready(function() {...
piece. Sometimes I want to prevent too much indenting so I write a top-level function, something like:
$('body').delegate('#new_canvas_item_cancel', "click", hideEditorAndPreventServerHit);
$('body').delegate('#edit_canvas_item_cancel', "click", hideEditorAndPreventServerHit);
function hideEditorAndPreventServerHit(event) {
$(this).closest('div.new_item_div, div.edit_canvas_item').slideUp();
event.preventDefault();
}
What are the best practices?