Drupal - How do I add JavaScript specific for a view?

You could use the template_preprocess_views_view() hook to do this:

function THEME_preprocess_views_view(&$vars) {
  $view = &$vars['view'];
  // Make sure it's the correct view
  if ($view->name == 'your-view-name') {
    // add needed javascript
    drupal_add_js(drupal_get_path('theme', 'your-theme') . '/your-js.js');
    // add needed stylesheet
    drupal_add_css(drupal_get_path('theme', 'your-theme') . '/your-css.css');
  }
}

Note that you could also check the specific display of the view using:

if ($view->name == 'your-view-name' && $view->current_display == 'your-display-id') {
  // include javascript & css here
}

You should be able to check for a custom css class like this:

if ($view->name == 'your-view-name' && $view->display[$view->current_display]->display_options['css_class'] == 'your-css-class') {
   // include javascript & css here
}

You can use views_get_page_view function to find out which view is being served on the page. It return views object. Note that in the code snippet below you should compare with views machine readable name, but of course you can write your own comparaison basing on the view object returned by views_get_page_view

function YOURTHEMENAME_preprocess_page(&$variables) {
    $view = views_get_page_view();
    if($view->name == 'YOURVIEW') {
    //Do what ever you want 
    }

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.