Just in case this is useful to anyone else stumbling across this question, searching like I did for attach JavaScript to a Drupal View. In terms of D7 & Views 3.7, the following worked best for me:
function HOOK_views_pre_render ( &$view ) {
/// check to make sure the view has a classname
if ( $view->display_handler && !empty($view->display_handler->options['css_class']) ) {
$cln = $view->display_handler->options['css_class'];
$cls = 'CLASS GOES HERE';
/// test that the classname contains our class
if ( preg_match('/(^|\s+)' . preg_quote($cls) . '(\s+|$)/i', $cln) ) {
/// build the path to the js, which is local to my module, js/view.js
$sep = DIRECTORY_SEPARATOR;
$dir = rtrim(drupal_get_path('module', 'HOOK'), $sep);
$pth = "{$dir}{$sep}js{$sep}view.js";
drupal_add_js($pth);
}
}
}
This was beneficial as I wanted to keep the code within my module, rather than the theme — because the enhancements brought by the JavaScript had nothing to do with visual appearance.
NOTE: Obviously HOOK
should be replaced with your module name, in both locations, and CLASS GOES HERE
should also be replaced with the class you are searching for.