drupal_get_js

Versions
5 – 7
drupal_get_js($scope = 'header', $javascript = NULL)

Returns a themed presentation of all JavaScript code for the current page. References to JavaScript files are placed in a certain order: first, all 'core' files, then all 'module' and finally all 'theme' JavaScript files are added to the page. Then, all settings are output, followed by 'inline' JavaScript code.

Parameters

$scope (optional) The scope for which the JavaScript rules should be returned. Defaults to 'header'.

$javascript (optional) An array with all JavaScript code. Defaults to the default JavaScript array for the given scope.

Return value

All JavaScript code segments and includes for the scope as HTML tags.

Related topics

▾ 6 functions call drupal_get_js()

chameleon_page in drupal/themes/chameleon/chameleon.theme
phptemplate_page in drupal/themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_page function to be passed into a pluggable template engine. Uses the arg() function to generate a series of page template files suggestions based on the current path. If none are found, the default page.tpl.php…
theme_closure in drupal/includes/theme.inc
Execute hook_footer() which is run at the end of the page right before the close of the body tag.
theme_install_page in drupal/includes/theme.inc
theme_maintenance_page in drupal/includes/theme.inc
theme_page in drupal/includes/theme.inc
Return an entire Drupal page displaying the supplied content.

Code

drupal/includes/common.inc, line 1814

<?php
function drupal_get_js($scope = 'header', $javascript = NULL) {
  $output = '';
  if (is_null($javascript)) {
    $javascript = drupal_add_js(NULL, NULL, $scope);
  }

  foreach ($javascript as $type => $data) {
    if (!$data) continue;

    switch ($type) {
      case 'setting':
        $output .= '<script type="text/javascript">Drupal.extend({ settings: '. drupal_to_js(call_user_func_array('array_merge_recursive', $data)) ." });</script>\n";
        break;
      case 'inline':
        foreach ($data as $info) {
          $output .= '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .'>'. $info['code'] ."</script>\n";
        }
        break;
      default:
        foreach ($data as $path => $info) {
          $output .= '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .' src="'. check_url(base_path() . $path) . ($info['cache'] ? '' : '?'. time()) ."\"></script>\n";
        }
    }
  }

  return $output;
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.