| 1 |
<?php
|
| 2 |
// $Id: jtooltips.module,v 1.1.2.6 2007/09/22 12:22:52 psicomante Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Configurable javascript tooltips over jQuery/SweetTitles
|
| 7 |
*
|
| 8 |
* Adds a tooltip (by default over <a> tags), built over jQuery or SweetTitles. The code is configurable is using jQuery Tooltips.
|
| 9 |
* @author Psicomante - psicomante(AT)katapekkia(.)net
|
| 10 |
* @author Tooltips - http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
|
| 11 |
* @author Sweettitles - http://www.dustindiaz.com/sweet-titles-finalized
|
| 12 |
*/
|
| 13 |
|
| 14 |
define('JQUERY_TOOLTIP', 1);
|
| 15 |
define('SWEETTITLES_TOOLTIP', 0);
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Adds CSS and JS to the top of pages.
|
| 19 |
*/
|
| 20 |
function jtooltips_init() {
|
| 21 |
if (arg(0) != 'admin' && arg(0) != 'img_assist' && arg(1) != 'add' && arg(2) != 'edit') {
|
| 22 |
$jtooltips_path = drupal_get_path('module', 'jtooltips');
|
| 23 |
|
| 24 |
if (variable_get('jtooltips_jstiptype', JQUERY_TOOLTIP)) {
|
| 25 |
drupal_add_css($jtooltips_path .'/jtooltips.css');
|
| 26 |
drupal_add_js($jtooltips_path .'/js/jquery.tooltip.pack.js');
|
| 27 |
drupal_add_js(_jtooltips_get_javascript(), 'inline', 'footer');
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
drupal_add_css($jtooltips_path .'/sweettitles.css');
|
| 31 |
drupal_add_js($jtooltips_path .'/js/addEvent.js');
|
| 32 |
drupal_add_js($jtooltips_path .'/js/sweettitles.js');
|
| 33 |
}
|
| 34 |
}
|
| 35 |
}
|
| 36 |
|
| 37 |
/**
|
| 38 |
* Menu hook for the module. If may_cache, returns an array of menu_items, otherwise return the right css and js added to the header.
|
| 39 |
* @params $may_cache A boolean indicating whether cacheable menu items should be returned.
|
| 40 |
* @return An array of menu items.
|
| 41 |
*/
|
| 42 |
|
| 43 |
function jtooltips_menu() {
|
| 44 |
$items = array();
|
| 45 |
$items['admin/settings/jtooltips'] = array (
|
| 46 |
'title' => 'JQuery tooltips',
|
| 47 |
'description' => 'Show tooltips over links and other components. it supports Jquery tooltips and sweettitles',
|
| 48 |
'page callback' => 'drupal_get_form',
|
| 49 |
'page arguments' => array('jtooltips_admin_settings'),
|
| 50 |
'access callback' => 'user_access',
|
| 51 |
'access arguments' => array('access administration pages'),
|
| 52 |
'type' => MENU_NORMAL_ITEM,
|
| 53 |
);
|
| 54 |
|
| 55 |
return $items;
|
| 56 |
}
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Admin menu. Callback function called by jtooltips_menu
|
| 60 |
* @returns An array of form items, presented in the classic hook_form.
|
| 61 |
*/
|
| 62 |
|
| 63 |
function jtooltips_admin_settings(){
|
| 64 |
$form = array();
|
| 65 |
|
| 66 |
$form['jtooltips_form'] = array(
|
| 67 |
'#type' => 'fieldset',
|
| 68 |
'#collapsible' => false,
|
| 69 |
'#collapsed' => false,
|
| 70 |
'#title' => t('jTooltips configuration')
|
| 71 |
);
|
| 72 |
|
| 73 |
$options = array(JQUERY_TOOLTIP => t('jQuery Tooltip'));
|
| 74 |
$jtooltips_path = drupal_get_path('module', 'jtooltips') .'/js/';
|
| 75 |
if (file_exists($jtooltips_path .'addEvent.js') && file_exists($jtooltips_path .'sweettitles.js')) {
|
| 76 |
$options += array(SWEETTITLES_TOOLTIP => t('sweetTitles'));
|
| 77 |
}
|
| 78 |
unset($jtooltips_path);
|
| 79 |
|
| 80 |
$form['jtooltips_form']['jtooltips_jstiptype'] = array(
|
| 81 |
'#type' => 'radios',
|
| 82 |
'#title' => t('Tooltip type'),
|
| 83 |
'#default_value' => variable_get('jtooltips_jstiptype', 1),
|
| 84 |
'#options' => $options,
|
| 85 |
'#description' => t('jQuery Tooltip: builded around jQuery, more versatile, but does not support fading<br />sweetTitles: uses a internal engine and supports fading')
|
| 86 |
);
|
| 87 |
if (variable_get('jtooltips_jstiptype', JQUERY_TOOLTIP)) {
|
| 88 |
$form['jtooltips_form']['advanced'] = array(
|
| 89 |
'#type' => 'fieldset',
|
| 90 |
'#title' => t('Advanced jQuery tooltip configuration'),
|
| 91 |
'#collapsible' => true,
|
| 92 |
'#collapsed' => true
|
| 93 |
);
|
| 94 |
$form['jtooltips_form']['advanced']['jtooltips_javascript'] = array(
|
| 95 |
'#type' => 'textarea',
|
| 96 |
'#title' => t('Javascript to initialize jquery tooltips'),
|
| 97 |
'#description' => t('The script here will be included in every page, except admin pages and add and edit nodes pages.'),
|
| 98 |
'#default_value' => _jtooltips_get_javascript(),
|
| 99 |
);
|
| 100 |
}
|
| 101 |
return system_settings_form($form);
|
| 102 |
}
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Saves and retrieves the javascript to inclue in the header in cachabel pages.
|
| 106 |
* @returns value of variable_get of jtooltips_javscript.
|
| 107 |
*/
|
| 108 |
function _jtooltips_get_javascript() {
|
| 109 |
$default =<<<END
|
| 110 |
if (Drupal.jsEnabled) {
|
| 111 |
$(document).ready(function () {
|
| 112 |
$('a').Tooltip({
|
| 113 |
delay: 0,
|
| 114 |
track: true,
|
| 115 |
showURL: false,
|
| 116 |
showBody: "; "
|
| 117 |
});
|
| 118 |
});
|
| 119 |
}
|
| 120 |
END;
|
| 121 |
return variable_get('jtooltips_javascript', $default);
|
| 122 |
}
|