You are here

function jquery_ui_add in jQuery UI 7

Same name and namespace in other branches
  1. 5 jquery_ui.module \jquery_ui_add()
  2. 6 jquery_ui.module \jquery_ui_add()

Add the specified jQuery UI library files to this page.

The ui.core file is always included automatically, as well as the effects.core file if any of the effects libraries are used.

Parameters

$files: An array of what additional files (other than UI core) should be loaded on the page, or a string with a single file name.

File

./jquery_ui.module, line 36
Provides the jQuery UI plug-in to other Drupal modules.

Code

function jquery_ui_add($files = array()) {
  static $loaded_files, $ui_core, $effects_core, $weight;
  $jquery_ui_path = JQUERY_UI_PATH . '/ui';
  $compression = variable_get('jquery_update_compression_type', 'mini');

  // Convert file to an array if it's not one already, to compensate for
  // lazy developers. ;)
  if (!is_array($files)) {
    $files = array(
      $files,
    );
  }
  if (!isset($weight)) {
    $weight = JS_LIBRARY + 5;
  }

  // If core hasn't been added yet, add it.
  if (!isset($ui_core)) {
    $ui_core = TRUE;
    jquery_ui_add(array(
      'ui.core',
    ));
  }

  // Loop through list of files to include and add them to the page.
  foreach ($files as $file) {

    // Any effects files require the effects core file.
    if (!isset($effects_core) && strpos($file, 'effects.') === 0) {
      $effects_core = TRUE;
      jquery_ui_add(array(
        'effects.core',
      ));
    }

    // Load other files.
    if (!isset($loaded_files[$file])) {
      switch ($compression) {
        case 'none':
          $file_path = "{$file}.js";
          break;
        case 'pack':
          $file_path = "packed/{$file}.packed.js";
          break;
        case 'mini':
        default:
          $file_path = "minified/{$file}.min.js";
          break;
      }
      $js_path = $jquery_ui_path . '/' . $file_path;
      drupal_add_js($js_path, array(
        'weight' => $weight++,
      ));
      $loaded_files[$file] = $js_path;
    }
  }
}