You are here

function javascript_libraries_add_js in JavaScript Libraries Manager 7

Helper function that calls drupal_add_js().

1 call to javascript_libraries_add_js()
javascript_libraries_preprocess_html in ./javascript_libraries.module
Implements hook_preprocess_html().

File

./javascript_libraries.module, line 215
Toggle the inclusion of Drupal system libraries. Upload and reference custom libraries as well.

Code

function javascript_libraries_add_js($library, $options = array()) {

  // Add a variable offset so user-added scripts come after theme scripts.
  $offset = variable_get('javascript_libraries_custom_weight_offset', 100);

  // Test taken from drupal_get_js() for whether we are preprocessing.
  $preprocess_js = variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update');

  // Get/build local cached versions of external scripts.
  if ($preprocess_js && $library['type'] == 'external' && !empty($library['cache'])) {
    $local_path = javascript_libraries_cache($library['uri']);
    if ($local_path) {
      $options['type'] = 'file';
      $library['uri'] = $local_path;
    }
    else {

      // Error getting the local path.
      return;
    }
  }
  else {
    $options['type'] = $library['type'];
  }
  if (!isset($options['scope'])) {
    $options['scope'] = $library['scope'];
  }
  $options['weight'] = $library['weight'] + $offset;
  $options['group'] = JS_THEME;
  drupal_add_js($library['uri'], $options);
}