You are here

jquery_ui.module in jQuery UI 5

Same filename and directory in other branches
  1. 8 jquery_ui.module
  2. 6 jquery_ui.module
  3. 7 jquery_ui.module

Provides the jQuery UI plug-in to other Drupal modules.

This module doesn't do too much, but it is a central location for any other modules that implement the JQuery UI library. It ensures that multiple modules will all include the same library script just once on any given page.

File

jquery_ui.module
View source
<?php

/**
 * @file
 * Provides the jQuery UI plug-in to other Drupal modules.
 *
 * This module doesn't do too much, but it is a central location for any other
 * modules that implement the JQuery UI library. It ensures that multiple
 * modules will all include the same library script just once on any given page.
 */

/**
 * Path to jQuery UI library.
 *
 * During site installation, JQUERY_UI_PATH is the absolute path to the
 * jQuery UI library.  At all other times JQUERY_UI_PATH is relative, and
 * safe for use in URLs.
 */
if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
  define('JQUERY_UI_PATH', dirname(__FILE__) . '/jquery.ui');
}
else {
  define('JQUERY_UI_PATH', drupal_get_path('module', 'jquery_ui') . '/jquery.ui');
}

/**
 * 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.
 *
 * @param $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.
 */
function jquery_ui_add($files = array()) {
  static $loaded_files, $ui_core, $effects_core;
  $jquery_ui_path = JQUERY_UI_PATH . '/ui';
  $compression = variable_get('jquery_ui_compression_type', 'minified');

  // 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 'packed':
          $file_path = "packed/{$file}.packed.js";
          break;
        case 'minified':
        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;
    }
  }
}

/**
 * Implementation of hook_menu().
 */
function jquery_ui_menu() {
  $items = array();
  $items[] = array(
    'path' => 'admin/settings/jquery_ui',
    'title' => t('jQuery UI'),
    'description' => t('Configure settings for jQuery UI module.'),
    'callback' => 'drupal_get_form',
    'callback arguments' => array(
      'jquery_ui_admin_settings',
    ),
    'access' => user_access('administer site configuration'),
  );
  return $items;
}

/**
 * Admin settings form.
 */
function jquery_ui_admin_settings() {
  $form['jquery_ui_compression_type'] = array(
    '#type' => 'radios',
    '#title' => t('jQuery UI compression type'),
    '#options' => drupal_map_assoc(array(
      'packed',
      'minified',
      'none',
    )),
    '#default_value' => variable_get('jquery_ui_compression_type', 'minified'),
    '#description' => t("Type of compression to use. 'Packed' uses Dean Edward's packer to make the file size as small as possible, but may require more browser processing. 'Minified' takes out all comments, whitespace, etc. to reduce the file size to a lesser degree, maintaining performance. 'None' leaves the full source intact."),
  );
  return system_settings_form($form);
}

/**
 * Return the version of jQuery UI installed.
 */
function jquery_ui_get_version() {
  $version = 0;
  if (file_exists(JQUERY_UI_PATH . '/version.txt')) {
    $version = file_get_contents(JQUERY_UI_PATH . '/version.txt');
  }
  return $version;
}

Functions

Namesort descending Description
jquery_ui_add Add the specified jQuery UI library files to this page.
jquery_ui_admin_settings Admin settings form.
jquery_ui_get_version Return the version of jQuery UI installed.
jquery_ui_menu Implementation of hook_menu().