You are here

function advagg_js_builder in Advanced CSS/JS Aggregation 6

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

Build and theme JS output for header.

Parameters

$external_no_preprocess: array(array($src, $defer, $prefix, $suffix))

$output_preprocess: array(array($src, $prefix, $suffix))

$output_no_preprocess: array(array(array($src, $defer, $prefix, $suffix)))

$setting_no_preprocess: array(array($code))

$inline_no_preprocess: array(array($code, $defer, $prefix, $suffix))

$scope: header or footer.

$js_settings_array: array of settings used.

$inline_included: array of inline scripts used.

$files_included: array of files used.

$files_aggregates_included: array of files and aggregates used.

Return value

String of themed JavaScript.

1 string reference to 'advagg_js_builder'
advagg.module in ./advagg.module
Advanced CSS/JS aggregation module

File

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

Code

function advagg_js_builder($external_no_preprocess, $output_preprocess, $output_no_preprocess, $setting_no_preprocess, $inline_no_preprocess, $js_settings_array, $inline_included, $files_included, $files_aggregates_included) {
  $output = '';

  // For inline Javascript to validate as XHTML, all Javascript containing
  // XHTML needs to be wrapped in CDATA. To make that backwards compatible
  // with HTML 4, we need to comment out the CDATA-tag.
  $embed_prefix = "\n<!--//--><![CDATA[//><!--\n";
  $embed_suffix = "\n//--><!]]>\n";

  // Keep the order of JS files consistent as some are preprocessed and others are not.
  // Make sure any inline or JS setting variables appear last after libraries have loaded.
  if (!empty($external_no_preprocess)) {
    foreach ($external_no_preprocess as $values) {
      list($src, $defer, $prefix, $suffix) = $values;
      $output .= $prefix . '<script type="text/javascript"' . ($defer ? ' defer="defer"' : '') . ' src="' . $src . '"></script>' . $suffix . "\n";
    }
  }
  if (!empty($output_preprocess)) {
    foreach ($output_preprocess as $values) {
      list($src, $prefix, $suffix) = $values;
      $output .= $prefix . '<script type="text/javascript" src="' . $src . '"></script>' . $suffix . "\n";
    }
  }
  foreach ($output_no_preprocess as $type => $list) {
    if (!empty($list)) {
      foreach ($list as $values) {
        list($src, $defer, $prefix, $suffix) = $values;
        $output .= $prefix . '<script type="text/javascript"' . ($defer ? ' defer="defer"' : '') . ' src="' . $src . '"></script>' . $suffix . "\n";
      }
    }
  }
  if (!empty($setting_no_preprocess)) {
    foreach ($setting_no_preprocess as $code) {
      $output .= '<script type="text/javascript">' . $embed_prefix . $code . $embed_suffix . "</script>\n";
    }
  }
  if (!empty($inline_no_preprocess)) {
    foreach ($inline_no_preprocess as $values) {
      list($code, $defer, $prefix, $suffix) = $values;
      $output .= $prefix . '<script type="text/javascript"' . ($defer ? ' defer="defer"' : '') . '>' . $embed_prefix . $code . $embed_suffix . '</script>' . $suffix . "\n";
    }
  }
  return $output;
}