Answer: Use the ajax_load module http://drupal.org/project/ajax_load

Ajax Load was written to accompany a patch that added AJAX loading to the Views module. When enabled, Ajax Load will ensure that any needed JS and CSS files are loaded along with dynamically loaded views.

Issue summary:
When working with javascript that needs settings that will change depending on what happens with an AJAX enabled View, standards like drupal_add_js($myModulesSettings, "setting") will only work on a full page load, not an AJAX loaded View. I've resorted to adding javascript in a hook_form_alter()

$form['myModulesSettings'] = array(
  "#value" => '<script type="text/javascript">Drupal.settings.myModulesSettings = ' . json_encode($myModulesSettings) . '; </script>';
);

I poked around the Views code and CTools but nothing jumped out at me. There must be a better way... Or we must create one.

Comments

merlinofchaos’s picture

Status: Active » Fixed

In Drupal 6 you can use the ajax_load module, I believe.

R.J. Steinert’s picture

Thanks Earl, that looks like the ticket. From the project page:

Ajax Load was written to accompany a patch that added AJAX loading to the Views module. When enabled, Ajax Load will ensure that any needed JS and CSS files are loaded along with dynamically loaded views.

R.J. Steinert’s picture

Issue summary: View changes

More general example given.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Placing the answer in the issue summary