You are here

qtip.module in qTip (Stylish jQuery Tooltips) 6

Same filename and directory in other branches
  1. 6.2 qtip.module
  2. 7.2 qtip.module
  3. 7 qtip.module

File

qtip.module
View source
<?php

/**
 * Define constants for qTip module
 */
define('QTIP_VERSION', '2.0.0pre');
define('QTIP_PATH', drupal_get_path('module', 'qtip') . '/library/');

//define('QTIP_FILE', 'jquery.qtip-' . QTIP_VERSION . (variable_get('qtip_use_uncompressed_js', 0) == 1 ? '' : '.min') . '.js');
define('QTIP_FILE', 'jquery.qtip-' . QTIP_VERSION . '.js');

/**
 * Implements of hook_init().
 */
function qtip_init() {

  // We have to get the right setting for the tooltip
  switch (variable_get('qtip_target_position', 'top_right')) {
    case 'top_left':
      $tooltip_position = 'bottom_right';
      break;
    case 'top_center':
      $tooltip_position = 'bottom_center';
      break;
    case 'top_right':
      $tooltip_position = 'bottom_left';
      break;
    case 'right_center':
      $tooltip_position = 'left_center';
      break;
    case 'bottom_right':
      $tooltip_position = 'top_left';
      break;
    case 'bottom_center':
      $tooltip_position = 'top_center';
      break;
    case 'bottom_left':
      $tooltip_position = 'top_right';
      break;
    case 'left_center':
      $tooltip_position = 'right_center';
  }

  // Settings set by the administrator to send to qtip.js
  drupal_add_js(array(
    'qtip' => array(
      'target_position' => variable_get('qtip_target_position', 'top_right'),
      'tooltip_position' => $tooltip_position,
      'show_speech_bubble_tip' => variable_get('qtip_show_speech_bubble_tip', TRUE),
      'show_speech_bubble_tip_side' => variable_get('qtip_show_speech_bubble_tip_side', FALSE),
      'speech_bubble_size' => variable_get('qtip_speech_bubble_tip_size', 12),
      'show_speech_bubble_tip_solid' => variable_get('qtip_show_speech_bubble_tip_solid', FALSE),
      'show_shadow' => variable_get('qtip_show_shadow', FALSE),
      'rounded_corners' => variable_get('qtip_rounded_corners', FALSE),
      'color' => variable_get('qtip_color', ''),
      'custom_color' => variable_get('qtip_custom_color', ''),
      'show_event_type' => variable_get('qtip_show_event_type', 'mouseenter'),
      'hide_event_type' => variable_get('qtip_hide_event_type', 'mouseleave'),
      //      'show_solo' => variable_get('qtip_show_solo', TRUE),
      'show_webform_descriptions' => variable_get('qtip_show_webform_descriptions', FALSE),
      'additional_elements' => variable_get('qtip_additional_elements', ''),
    ),
  ), 'setting');
  drupal_add_css(drupal_get_path('module', 'qtip') . '/library/jquery.qtip.css');
  drupal_add_css(drupal_get_path('module', 'qtip') . '/css/qtip.css');

  // Check to see if qtip library is in sites/all/libraries/qtip first...
  if (file_exists(QTIP_PATH . QTIP_FILE)) {
    drupal_add_js(QTIP_PATH . QTIP_FILE);
  }
  drupal_add_js(drupal_get_path('module', 'qtip') . '/js/qtip.js');

  // Only load qtip.admin.js file if currently viewing qTip settings page
  if (request_uri() == base_path() . 'admin/settings/qtip') {
    drupal_add_js(drupal_get_path('module', 'qtip') . '/js/qtip.admin.js');
  }
}

/**
 * Implements of hook_menu().
 */
function qtip_menu() {
  $items = array();
  $items['admin/settings/qtip'] = array(
    'title' => t('qTip'),
    'description' => t('Control how qTips (tooltips) will be displayed by default on each page'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'qtip_settings_form',
    ),
    'access arguments' => array(
      '',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'qtip.admin.inc',
  );
  return $items;
}

/**
 * Implementation of hook_filter()
 */
function qtip_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(
        0 => t('qTips'),
      );
    case 'description':
      return t("Generate stylish tooltips. Format: [qtip:Tooltip Link|Tooltip Header(optional)|Tooltip content]");
    case 'prepare':
      return $text;
    case 'process':
      $text = qtip_replacement($text);
      return $text;
    default:
      return $text;
  }
}

/**
 * Implementation of hook_filter_tips().
 */
function qtip_filter_tips($delta, $format, $long = FALSE) {
  return 'Generate stylish tooltips. Format: [qtip:Tooltip Link|Tooltip Header(optional)|Tooltip content]';
}

/**
 * Private functions
 */
function qtip_replacement($text) {
  if (preg_match_all("/\\[qtip:([^\\|\\]]+)\\|?([^\\]]*)?\\]/i", $text, $match)) {

    // Set the default delta value to be used in the foreach statement below for <span> ids
    $delta = 0;
    foreach ($match[2] as $key => $value) {
      $link = $match[1][$key];
      $tip = $match[2][$key];

      // We need to set $header to nothing by default, in case the user didn't specify any header text
      $header = '';

      // If the user also added header text to the filter
      if (strstr($tip, '|')) {
        $tip_splitter = explode('|', $tip);
        $header = '<span class="qtip-header">' . $tip_splitter[0] . '</span>';
        $tip = $tip_splitter[1];
      }
      $search[] = $match[0][$key];
      $replace[] = '<span id="qtip-link-' . $delta . '" class="qtip-link ' . ($delta % 2 ? 'qtip-link-even' : 'qtip-link-odd') . '" title="' . $tip . '">' . $header . $link . '</span>';
      $delta++;
    }
    return str_replace($search, $replace, $text);
  }
  return $text;
}

Functions

Namesort descending Description
qtip_filter Implementation of hook_filter()
qtip_filter_tips Implementation of hook_filter_tips().
qtip_init Implements of hook_init().
qtip_menu Implements of hook_menu().
qtip_replacement Private functions

Constants

Namesort descending Description
QTIP_FILE
QTIP_PATH
QTIP_VERSION Define constants for qTip module