You are here

function beautytips_form_alter in BeautyTips 6

Implementation of hook_form_alter. Adds beautytips for textareas and textfields

File

./beautytips.module, line 296
Provides API for adding beautytips to pages. Adds Beautytips settings page and provides some built in functionality.

Code

function beautytips_form_alter(&$form, $form_state, $form_id) {

  // Show the form id for every form, if enabled.
  if (variable_get('beautytips_show_form', FALSE)) {
    drupal_set_message(t('The form_id is %form_id.  This message should be ' . l(t('turned off'), 'beautytips/settings/form_ids', array(
      'query' => drupal_get_destination(),
    )) . " when finished you're finished checking form_ids.", array(
      '%form_id' => $form_id,
    )));
  }
  $add_bt = TRUE;

  // Check if beautytips have been enabled for this form.
  if (strlen(variable_get('beautytips_form_id', ''))) {
    if (strpos(variable_get('beautytips_form_id', ''), $form_id) === FALSE) {
      $add_bt = FALSE;
    }
  }
  if (variable_get('beautytips_text_input', FALSE)) {
    if ($add_bt) {
      $path = drupal_get_path('module', 'beautytips') . '/js/bt_text_box.js';
      drupal_add_js($path);
      $options = array();
      $options['bt_text_field'] = array(
        'area' => 'input.form-text',
        'trigger' => array(
          0 => 'focus',
          1 => 'blur',
        ),
        'contentSelector' => "\$(this).next('.description').hide().html()",
        'width' => '275px',
        'positions' => array(
          0 => variable_get('beautytips_position', 'bottom'),
        ),
      );
      $options['bt_text_area'] = array(
        'area' => 'textarea.form-textarea',
        'trigger' => array(
          0 => 'focus',
          1 => 'blur',
        ),
        'contentSelector' => "\$(this).parents('.form-item').find('.description').hide().html()",
        'hideContent' => TRUE,
        'width' => '275px',
        'positions' => array(
          0 => variable_get('beautytips_position', 'bottom'),
        ),
      );
      beautytips_add_beautytips($options);
    }
  }
}