View source
<?php
define('QTIP_VERSION', '2.0.0pre');
define('QTIP_PATH', drupal_get_path('module', 'qtip') . '/library/');
define('QTIP_FILE', 'jquery.qtip-' . QTIP_VERSION . '.js');
function qtip_init() {
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';
}
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_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');
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');
if (request_uri() == base_path() . 'admin/settings/qtip') {
drupal_add_js(drupal_get_path('module', 'qtip') . '/js/qtip.admin.js');
}
}
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;
}
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;
}
}
function qtip_filter_tips($delta, $format, $long = FALSE) {
return 'Generate stylish tooltips. Format: [qtip:Tooltip Link|Tooltip Header(optional)|Tooltip content]';
}
function qtip_replacement($text) {
if (preg_match_all("/\\[qtip:([^\\|\\]]+)\\|?([^\\]]*)?\\]/i", $text, $match)) {
$delta = 0;
foreach ($match[2] as $key => $value) {
$link = $match[1][$key];
$tip = $match[2][$key];
$header = '';
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;
}