You are here

function advagg_ctools_process_js_files in Advanced CSS/JS Aggregation 7

Same name and namespace in other branches
  1. 6 advagg.module \advagg_ctools_process_js_files()

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.

1 call to advagg_ctools_process_js_files()
advagg_advagg_js_header_footer_alter in ./advagg.module
Implements hook_advagg_js_header_footer_alter().

File

./advagg.module, line 3098
Advanced CSS/JS aggregation module

Code

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

  // Automatically extract any 'settings' added via drupal_add_js() and make
  // them the first command.
  $scripts = drupal_add_js(NULL, array(
    'type' => NULL,
    'scope' => $scope,
  ));
  if (empty($scripts)) {
    $scripts = drupal_add_js(NULL, array(
      'type' => NULL,
      'scope' => $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;
}