drupal_add_library

Versions
mediamosa-21
drupal_add_library($module, $name)

Adds multiple JavaScript or CSS files at the same time.

A library defines a set of JavaScript and/or CSS files, optionally using settings, and optionally requiring another library. For example, a library can be a jQuery plugin, a JavaScript framework, or a CSS framework. This function allows modules to load a library defined/shipped by itself or a depending module; without having to add all files of the library separately. Each library is only loaded once.

See also

drupal_get_library()

@see hook_library()

See also

hook_library_alter()

Parameters

$module The name of the module that registered the library.

$name The name of the library to add.

Return value

TRUE when the library was successfully added or FALSE if the library or one of its dependencies could not be added.

▾ 4 functions call drupal_add_library()

drupal_add_js in includes/common.inc
Add a JavaScript file, setting or inline code to the page.
drupal_process_attached in includes/common.inc
Add to the page all structures attached to a render() structure.
overlay_set_mode in modules/overlay/overlay.module
Set overlay mode and add proper JavaScript and styles to the page.
theme_vertical_tabs in includes/form.inc
Makes the element's children fieldsets be vertical tabs.

Code

includes/common.inc, line 3894

<?php
function drupal_add_library($module, $name) {
  $added = &drupal_static(__FUNCTION__, array());

  // Only process the library if it exists and it was not added already.
  if (!isset($added[$module][$name])) {
    if ($library = drupal_get_library($module, $name)) {
      // Add all components within the library.
      $elements['#attached'] = array(
        'library' => $library['dependencies'],
        'js' => $library['js'],
        'css' => $library['css'],
      );
      $added[$module][$name] = drupal_process_attached($elements, JS_LIBRARY, TRUE);
    }
    else {
      // Requested library does not exist.
      $added[$module][$name] = FALSE;
    }
  }

  return $added[$module][$name];
}
?>