You are here

function drupal_add_js_library in jQuery Plugin Handler (JQP) 6.2

Add a shared library from the javascript library directory

Parameters

$name: the name of the library to add

$version: the version of the library to add

$options: Array containing additional options to pass to drupal_add_js or drupal_add_css. array( 'css' => array($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE), 'js' => array($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE), );

See also

drupal_add_js()

drupal_add_css()

File

./jqp.module, line 229
Used to register and load javascript libraries and plugins from a cetral point

Code

function drupal_add_js_library($name, $version = 0, $options = array()) {

  // Get the library
  $js_library = js_library_load($name);
  $types = array(
    'js' => 'scripts',
    'css' => 'stylesheets',
  );
  $files = array();

  // Loop trough the file types
  foreach ($types as $key => $type) {

    // Add the files of the default version, if exist
    if ($version !== 0 && is_array($js_library->info[$type][0])) {
      $files[$key] = $js_library->info[$type][0];
    }
    if (is_array($js_library->info[$type][$version])) {
      $files[$key] = $js_library->info[$type][$version];
    }
  }

  // Load all files using drupal_add_js and drupal_add_css
  foreach ($types as $key => $type) {
    if (!$files[$key]) {
      continue;
    }
    foreach ($files[$key] as $path) {

      //trace("$path $key");
      $args[0] = $path;
      $args = array_merge($args, $options);
      call_user_func_array("drupal_add_{$key}", $args);
    }
  }
}