You are here

function ctools_process_js_files in Chaos Tool Suite (ctools) 6

Create a list of javascript files that are on the page.

Parameters

$js_files: Array of js files that are loaded on this page.

$scope: String usually containing header or footer.

$scripts: (Optional) array returned from drupal_add_js(). If NULL then it will load the array from drupal_add_js for the given scope.

Return value

array $settings The JS 'setting' array for the given scope.

2 calls to ctools_process_js_files()
ctools_ajax_page_preprocess in includes/ajax.inc
Implement hook_preprocess_page. Process variables for page.tpl.php
ctools_ajax_render in includes/ajax.inc
Render a commands array into JSON and immediately hand this back to the AJAX requester.

File

includes/ajax.inc, line 673
Utilize the CTools AJAX responder.

Code

function ctools_process_js_files(&$js_files, $scope, $scripts = NULL) {

  // Automatically extract any 'settings' added via drupal_add_js() and make
  // them the first command.
  if (empty($scripts)) {
    $scripts = drupal_add_js(NULL, NULL, $scope);
  }

  // Get replacements that are going to be made by contrib modules and take
  // them into account so we don't double-load scripts.
  static $replacements = NULL;
  if (!isset($replacements)) {
    $replacements = module_invoke_all('js_replacements');
  }
  $settings = array();
  foreach ($scripts as $type => $data) {
    switch ($type) {
      case 'setting':
        $settings = $data;
        break;
      case 'inline':
      case 'theme':

        // Presently we ignore inline javascript.
        // Theme JS is already added and because of admin themes, this could add
        // improper JS to the page.
        break;
      default:

        // If JS preprocessing is off, we still need to output the scripts.
        // Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
        foreach ($data as $path => $info) {

          // If the script is being replaced, take that replacement into account.
          $final_path = isset($replacements[$type][$path]) ? $replacements[$type][$path] : $path;
          $js_files[base_path() . $final_path] = TRUE;
        }
    }
  }
  return $settings;
}