You are here

function jquery_ui_add in jQuery UI 6

Same name and namespace in other branches
  1. 5 jquery_ui.module \jquery_ui_add()
  2. 7 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 22
Provides the jQuery UI plug-in to other Drupal modules.

Code

function jquery_ui_add($files = array()) {
  static $loaded_files, $ui_core, $effects_core;
  $jquery_ui_path = jquery_ui_get_path();
  if ($jquery_ui_path === FALSE) {
    return FALSE;
  }
  $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 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);
      $loaded_files[$file] = $js_path;
    }
  }
}