You are here

function advagg_get_js_scopes in Advanced CSS/JS Aggregation 7.2

Same name and namespace in other branches
  1. 7 advagg.module \advagg_get_js_scopes()

Get all javascript scopes set in the $javascript array.

Parameters

array $javascript: An array with all JavaScript code.

Return value

array Array of scopes that are currently being used.

1 call to advagg_get_js_scopes()
_advagg_build_js_arrays_for_rendering in ./advagg.module
Builds the arrays needed for js rendering and caching.

File

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

Code

function advagg_get_js_scopes(array $javascript) {

  // Return if nothing given to us.
  if (empty($javascript)) {
    return array();
  }

  // Filter out elements of the given scope.
  $scopes = array();
  $js_settings_in_footer = FALSE;
  foreach ($javascript as $name => $item) {

    // Skip if the scope is not set.
    if (!is_array($item) || empty($item['scope'])) {
      continue;
    }
    if (!isset($scopes[$item['scope']])) {
      $scopes[$item['scope']] = TRUE;
    }
    if ($name === 'settings' && $item['scope'] === 'footer') {
      $js_settings_in_footer = TRUE;
    }
  }

  // Default to header if nothing found.
  if (empty($scopes)) {
    $scopes['header'] = TRUE;
  }

  // Process header last.
  if (isset($scopes['header']) && count($scopes) > 1) {
    $temp = $scopes['header'];
    unset($scopes['header']);
    $scopes['header'] = $temp;
  }

  // Process footer last if everything has been moved to the footer.
  if (isset($scopes['footer']) && count($scopes) > 1 && $js_settings_in_footer) {
    $temp = $scopes['footer'];
    unset($scopes['footer']);
    $scopes['footer'] = $temp;
  }

  // Return the scopes.
  return $scopes;
}