You are here

function _hierarchical_select_setup_js in Hierarchical Select 6.3

Same name and namespace in other branches
  1. 5.3 hierarchical_select.module \_hierarchical_select_setup_js()

Helper function to add the required Javascript files and settings.

Parameters

$form_state: A form state array. Necessary to set the callback URL for Hierarchical Select through _hierarchical_select_add_js_settings().

3 calls to _hierarchical_select_setup_js()
hierarchical_select_process in ./hierarchical_select.module
Hierarchical select form element type #process callback.
hs_taxonomy_views_form_alter in modules/hs_taxonomy_views.module
Implementation of hook_form_alter().
hs_taxonomy_views_handler_filter_term_node_tid::init in modules/hs_taxonomy_views_handler_filter_term_node_tid.inc

File

./hierarchical_select.module, line 1312
This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.

Code

function _hierarchical_select_setup_js(&$form_state = NULL) {
  global $language;
  static $ran_once;
  static $js_settings_added;
  $jquery_ui_components = array(
    'effects.core',
    'effects.drop',
  );
  if (!$js_settings_added && isset($form_state)) {
    $url = base_path();
    $url .= variable_get('clean_url', 0) ? '' : 'index.php?q=';

    // Prefix URL with language path when i18n is enabled and when path-based
    // negotiation is being used.
    $negotiation = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
    if (module_exists('i18n') && $language->prefix != '' && ($negotiation == LANGUAGE_NEGOTIATION_PATH_DEFAULT || $negotiation == LANGUAGE_NEGOTIATION_PATH)) {
      $url .= $language->prefix . '/';
    }
    if (module_exists('purl')) {
      $options = array();
      purl_url_outbound_alter($url, $options, '');
      $url = str_replace('//', '/', '/' . $url);
    }
    _hierarchical_select_add_js_settings(array(
      'HierarchicalSelect' => array(
        'basePath' => $url,
        'getArguments' => drupal_query_string_encode($_GET, array(
          'q',
        )),
      ),
    ), $form_state);
    $js_settings_added = TRUE;
  }
  if (!$ran_once) {
    $ran_once = TRUE;

    // Add the CSS and JS, set the URL that should be used by all hierarchical
    // selects.
    drupal_add_css(drupal_get_path('module', 'hierarchical_select') . '/hierarchical_select.css');
    drupal_add_js(drupal_get_path('module', 'hierarchical_select') . '/hierarchical_select.js');
    if (variable_get('hierarchical_select_js_cache_system', 0) == 1) {
      drupal_add_js(drupal_get_path('module', 'hierarchical_select') . '/hierarchical_select_cache.js');
    }
    if (!module_exists('jquery_form')) {
      drupal_add_js(drupal_get_path('module', 'hierarchical_select') . '/hierarchical_select_formtoarray.js');
    }
    else {
      jquery_form_add();
    }
    if (!module_exists('jquery_ui')) {
      foreach ($jquery_ui_components as $component) {
        drupal_add_js(drupal_get_path('module', 'hierarchical_select') . "/js/jquery.ui/{$component}.js");
      }
    }
    else {
      jquery_ui_add($jquery_ui_components);
    }
  }
}