This is a full web page with all the trappings. It's just a little short
26 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
27 |
Another clueTip? consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
3 |
This is another clueTip. It is here for demonstration purposes only.
2 |
3 |
Did you know that jQuery has a vibrant community of web developers and designers who discuss the library and offer help to those seeking it? You can find it at forum.jquery.com.
4 |
The sticky option is really nice when you have a clueTip with a link to learningjquery.com in it (or any other site). Now, you can click the link to go somewhere else. Not that you'd want to.
13 |
14 |
15 |
Notice that this is another example of a full web page. It even has a nice photograph in it. Twice!
This clueTip won't appear unless you click to activate it. And it won't go away until you click again, or until you activate another clueTip by hovering or clicking. Only one clueTip gets to show at a time.
Below are quite a few examples of how you can add a clueTip to your page, using a wide range of options. Keep in mind that there is nothing magical about the HTML markup. You can use any jQuery selector you want to attach your clueTips. For example, if you want to attach clueTips to all links with a class of "peanuts," you would simply write in your jQuery code: $('a.peanuts').cluetip();.
30 |
Default Style
31 |
32 |
33 |
basic tip from title: This example pulls the clueTip's contents from the invoking element's title attribute via the "splitTitle" option.
34 |
View the HTML
35 |
<a class="title" href="#" title="This is the title|The first set of contents comes after the first delimiter in the title.|In this case, the delimiter is a pipe">
sticky, with arrows:This sticky clueTip has its "close" text in the title bar. It won't close until you close it, or until you hover over another clue-tipped link. It also displays an arrow on one of its sides, pointing to the invoking element. sticky clueTip with arrows
53 |
local, with arrows: This one uses local content from a hidden div element and displays an arrow that points to the invoking element: hover for local
67 |
sticky, truncated clueTip with custom hover class, close position, and close text (it also has a title). Its href is different from its rel, so if you click it, you'll go to the linked page hover for cluetip, click to visit URL
73 |
View the HTML
74 |
<a href="http://www.learningjquery.com" title="about this link:" rel="ajax6.html">
experimental mouse tracking: The clueTip will move in the direction of your mouse movement, as long as you're still hovering over the invoking element.
91 |
jTip Style clueTip, with slideDown effect and an image placed in the title for closing it, because it's sticky.
100 | New: The clueTip will close if you mouse out of it.
101 |
this sticky clueTip has a fixed height. It's generally a good idea to make fixed-height clueTips sticky as well, just in case the content requires a scrollbar to read it fully. It will be positioned below the clicked element unless there isn't enough room, in which case it will be positioned above.
135 |
Another one with rounded corners theme. This one has "bottomTop" positioning: positioned under link, unless there isn't enough room (then over). It also has "topOffset" set to 70.
188 |
Below are quite a few examples of how you can add a clueTip to your page, using a wide range of options. Keep in mind that there is nothing magical about the HTML markup. You can use any jQuery selector you want to attach your clueTips. For example, if you want to attach clueTips to all links with a class of "peanuts," you would simply write in your jQuery code: $('a.peanuts').cluetip();.
34 |
Default Style
35 |
36 |
37 |
basic tip from title: This example pulls the clueTip's contents from the invoking element's title attribute via the "splitTitle" option.
38 |
View the HTML
39 |
<a class="title" href="#" title="This is the title|The first set of contents comes after the first delimiter in the title.|In this case, the delimiter is a pipe">
sticky, with arrows:This sticky clueTip has its "close" text in the title bar. It won't close until you close it, or until you hover over another clue-tipped link. It also displays an arrow on one of its sides, pointing to the invoking element. sticky clueTip with arrows
57 |
local, with arrows: This one uses local content from a hidden div element and displays an arrow that points to the invoking element: hover for local
71 |
sticky, truncated clueTip with custom hover class, close position, and close text (it also has a title). Its href is different from its rel, so if you click it, you'll go to the linked page hover for cluetip, click to visit URL
77 |
View the HTML
78 |
<a href="http://www.learningjquery.com" title="about this link:" rel="ajax6.html">
experimental mouse tracking: The clueTip will move in the direction of your mouse movement, as long as you're still hovering over the invoking element.
95 |
jTip Style clueTip, with slideDown effect and an image placed in the title for closing it, because it's sticky.
104 | New: The clueTip will close if you mouse out of it.
105 |
this sticky clueTip has a fixed height. It's generally a good idea to make fixed-height clueTips sticky as well, just in case the content requires a scrollbar to read it fully. It will be positioned below the clicked element unless there isn't enough room, in which case it will be positioned above.
139 |
Another one with rounded corners theme. This one has "bottomTop" positioning: positioned under link, unless there isn't enough room (then over). It also has "topOffset" set to 70.
192 |
Important: This plugin is no longer being maintained.
40 |
41 |
I originally wrote clueTip back in 2006 as my first attempt at a jQuery plugin. If I were to write it now, I would do it completely differently. However, I don't have the time or energy to work on it. The good news is that you can use any one of a number of better tooltip plugins. Here are a few:
The clueTip plugin allows you to easily show a fancy tooltip when the user's mouse hovers over (or, optionally, clicks on) any element you designate in your script. If the element includes a title attribute, its text becomes the heading of the clueTip.
49 |
If you like this plugin and you're feeling generous, perhaps you'd also like to visit my amazon.com wish list?
50 |
Quick Start Guide
51 | Showing the most basic clueTip can be achieved in two easy steps.
52 |
Add HTML markup to your page for elements that you want to invoke a clueTip. By default, the clueTip plugin will use the rel attribute to load contents into the tooltip body via AHAH.
53 |
54 | <!-- use ajax/ahah to pull content from fragment.html: -->
55 | <p><a class="tips" href="fragment.html" rel="fragment.html">show me the cluetip!</a></p>
56 |
57 | <!-- use title attribute for clueTip contents, but don't include anything in the clueTip's heading -->
58 | <p><a id="houdini" href="houdini.html" title="|Houdini was an escape artist.|He was also adept at prestidigitation.">Houdini</a></p>
59 |
60 |
Include the jQuery core file and the clueTip plugin in the <head> of your document. You may optionally include the hoverIntent plugin as well. After these scripts are referenced, you can reference a custom script file to invoke your clueTips (preferred) or enter the script directly in the <head> (shown below). You should also include the clueTip stylesheet (jquery.cluetip.css) after the scripts.
61 |
62 |
<script src="jquery.js" type="text/javascript"></script>
63 | <script src="jquery.hoverIntent.js" type="text/javascript"></script> <!-- optional -->
64 | <script src="jquery.cluetip.js" type="text/javascript"></script>
65 |
66 | <script type="text/javascript">
67 | $(document).ready(function() {
68 | $('a.tips').cluetip();
69 |
70 | $('#houdini').cluetip({
71 | splitTitle: '|', // use the invoking element's title attribute to populate the clueTip...
72 | // ...and split the contents into separate divs where there is a "|"
73 | showTitle: false // hide the clueTip's heading
74 | });
75 | });
76 | </script>
77 | <link rel="stylesheet" href="jquery.cluetip.css" type="text/css" />
78 |
79 |
You can change the default style and behavior in many ways. See API / Options for details.
80 |
81 |
82 |
83 |
This plugin is no longer being maintained.
84 |
See the overview for a list of alternative tooltip plugins.
The contents of the clueTip can come from one of these sources:
97 |
98 |
a separate file, via AHAH / AJAX
99 |
an element on the same page, typically hidden
100 |
the title attribute, parsed by a user-defined delimiter (if the "splitTitle" option is set). The text before the first delimiter becomes the clueTip title, and the rest of the text parts are placed in <div class="split-body"></div> elements and appended to the clueTip body
101 |
the return value of a function referenced in the first argument of .cluetip().
102 |
103 |
104 |
105 |
Smart Positioning
106 | The clueTip Plugin has 4 positioning modes, which you can change via the "positionBy" option.
107 |
108 |
positionBy: 'auto' (default)
109 |
110 |
places the tooltip just to the right of the invoking element, but...
111 |
if there is not enough room for the tooltip to be fully visible between the right edge of the invoking element and the right edge of the browser window, switches from the right side to the left side, but...
112 |
if the invoking element is too close to the bottom edge of the browser window, adjusts the tooltip upwards until the whole tooltip is visible, but...
113 |
if the tooltip is taller than the window (i.e. the viewable area), adjusts the tooltip back down until the tooltip's top is at the top edge of the browser window, but...
114 |
position if the invoking element is so wide that the tooltip can't completely fit to the left or the right of it, places the tooltip to the right or left of the mouse, but...
115 |
if the tooltip itself can't fit to the right or left of the mouse position, places the tooltip below the mouse position (centered horizontal if enough room), but...
116 |
if (a) there isn't enough room below without being cut off, and (b) there is enough room between the top of the viewable area and the mouse, puts the tooltip above the mouse position
117 |
118 |
119 |
positionBy: 'mouse'
120 |
121 |
places the tooltip to the right of the mouse position, but...
122 |
if there is not enough room to the right, places the tooltip to the left of the mouse position, but...
123 |
if the tooltip itself can't fit to the right or left of the mouse position, places the tooltip below the mouse position (centered horizontally if enough room), but...
124 |
if (a) there isn't enough room below without being cut off, and (b) there is enough room between the top of the viewable area and the mouse, puts the tooltip above the mouse position
125 |
126 |
127 |
positionBy: 'bottomTop'
128 |
129 |
places the tooltip below the mouse position (centered horizontally if enough room), but...
130 |
if (a) there isn't enough room below without being cut off, and (b) there is enough room between the top of the viewable area and the mouse, puts the tooltip above the mouse position
131 |
132 |
133 |
positionBy: 'fixed'
134 |
135 |
places the tooltip in the same location relative to the invoking element, regardless of where it appears on the page.
136 |
the fixed position can be adjusted by modifying the number of pixels in the topOffset and leftOffset options
137 |
138 |
139 |
140 |
141 |
142 |
Flexible Behavior
143 |
144 |
The clueTip takes advantage of Brian Cherne's hoverIntent plugin if it's available. (Just include it in a <script> tag if you want the clueTip to use it.)
145 |
It can be activated on hover or on click.
146 |
It can fade in, slide down, etc.
147 |
It can close when the invoking element is moused out or when the tooltip is moused out or when the user clicks a "close" link.
148 |
It can cache the results of ajax requests—or not.
149 |
It can be turned off
150 |
151 |
152 |
153 |
Variety of Styles
154 |
The clueTip Plugin comes with three themes: default, jTip, and rounded corners. Additional themes can be created by following the naming patterns in the stylesheet, jquery.cluetip.css. To apply one of the alternative themes, just indicate it in the cluetipClass option as 'jtip' or 'rounded'.
155 |
The "loading" image comes from this rule in the stylesheet:
It can be turned off with the following option: waitImage: false
163 |
Other options that affect the visual appearance include hoverClass, arrows, dropShadow, and dropShadowSteps. Please see API / Options for more information.
164 |
165 |
166 |
167 |
168 |
This plugin is no longer being maintained.
169 |
See the overview for a list of alternative tooltip plugins.
170 |
171 |
clueTip Plugin API / Options
172 | The clueTip Plugin API provides two methods, with many options. It also provides a custom event for closing the tooltip programmatically
173 |
174 |
$.cluetip.setup(options)
175 |
Global defaults for clueTips. Will apply to all calls to the clueTip plugin.
176 |
177 |
{
178 | insertionType: 'appendTo', // how the clueTip is inserted into the DOM
179 | // possible values: 'appendTo', 'prependTo', 'insertBefore', 'insertAfter'
180 | insertionElement: 'body' // where in the DOM the clueTip is to be inserted
181 | }
182 |
183 |
.cluetip(options)
184 |
Displays a highly customizable tooltip via ajax (default) or local content or the title attribute of the invoking element
185 |
186 |
$.fn.cluetip.defaults = { // default options; override as needed
187 | multiple: false, // Allow a new tooltip to be created for each .cluetip() call
188 | width: 275, // The width of the clueTip
189 | height: 'auto', // The height of the clueTip. more info below [1]
190 | cluezIndex: 97, // Sets the z-index style property of the clueTip
191 | positionBy: 'auto', // Sets the type of positioning. more info below [2]
192 | topOffset: 15, // Number of px to offset clueTip from top of invoking element. more info below [3]
193 | leftOffset: 15, // Number of px to offset clueTip from left of invoking element. more info below [4]
194 | local: false, // Whether to use content from the same page for the clueTip's body
195 | // (treats the attribute used for accessing the tip as a jQuery selector,
196 | // but only selects the first element if the selector matches more than one). more info below [5]
197 | hideLocal: true, // If local option is set to true, this determines whether local content
198 | // to be shown in clueTip should be hidden at its original location
199 | localPrefix: null, // string to be prepended to the tip attribute if local is true
200 | localIdSuffix: null, // string to be appended to the cluetip content element's id if local is true
201 | attribute: 'rel', // the attribute to be used for fetching the clueTip's body content
202 | titleAttribute: 'title', // the attribute to be used for fetching the clueTip's title
203 | splitTitle: '', // A character used to split the title attribute into the clueTip title and divs
204 | // within the clueTip body. more info below [6]
205 | escapeTitle: false, // whether to html escape the title attribute
206 | showTitle: true, // show title bar of the clueTip, even if title attribute not set
207 | cluetipClass: 'default',// class added to outermost clueTip div in the form of 'cluetip-' + clueTipClass. more info below [7]
208 | hoverClass: '', // class applied to the invoking element onmouseover and removed onmouseout
209 | waitImage: true, // whether to show a "loading" img, which is set in jquery.cluetip.css
210 | cursor: 'help',
211 | arrows: false, // if true, displays arrow on appropriate side of clueTip. more info below [8]
212 | dropShadow: true, // set to false if you don't want the drop-shadow effect on the clueTip
213 | dropShadowSteps: 6, // adjusts the size of the drop shadow
214 | sticky: false, // keep visible until manually closed
215 | mouseOutClose: false, // close when clueTip is moused out: false, 'cluetip', 'link', 'both'
216 | delayedClose: 50, // close clueTip on a timed delay
217 | activation: 'hover', // set to 'click' to force user to click to show clueTip
218 | clickThrough: true, // if true, and activation is not 'click', then clicking on a clueTipped link will take user to
219 | // the link's href, even if href and tipAttribute are equal
220 | tracking: false, // if true, clueTip will track mouse movement (experimental)
221 | closePosition: 'top', // location of close text for sticky cluetips; can be 'top' or 'bottom' or 'title'
222 | closeText: 'Close', // text (or HTML) to to be clicked to close sticky clueTips
223 | truncate: 0, // number of characters to truncate clueTip's contents. if 0, no truncation occurs
224 |
225 | // effect and speed for opening clueTips
226 | fx: {
227 | open: 'show', // can be 'show' or 'slideDown' or 'fadeIn'
228 | openSpeed: ''
229 | },
230 |
231 | // settings for when hoverIntent plugin is used
232 | hoverIntent: {
233 | sensitivity: 3,
234 | interval: 50,
235 | timeout: 0
236 | },
237 |
238 | // function to run just before clueTip is shown.
239 | // If the function returns false, the clueTip is NOT shown
240 | // It can take a single argument: the event object
241 | // Inside the function, this refers to the element that invoked the clueTip
242 | onActivate: function(event) {return true;},
243 |
244 | // function to run just after clueTip is shown. It can take two arguments:
245 | // the first is a jQuery object representing the clueTip element;
246 | // the second a jQuery object represeting the clueTip inner div.
247 | // Inside the function, this refers to the element that invoked the clueTip
248 | onShow: function(ct, ci){},
249 |
250 | // function to run just after clueTip is hidden. It can take two arguments:
251 | // the first is a jQuery object representing the clueTip element;
252 | // the second a jQuery object represeting the clueTip inner div.
253 | // Inside the function, this refers to the element that invoked the clueTip
254 | onHide: function(ct, ci){},
255 |
256 | // whether to cache results of ajax request to avoid unnecessary hits to server
257 | ajaxCache: true,
258 |
259 | // process data retrieved via xhr before it's displayed
260 | ajaxProcess: function(data) {
261 | data = data.replace(/<(script|style|title)[^<]+<\/(script|style|title)>/gm, '').replace(/<(link|meta)[^>]+>/g,'');
262 | return data;
263 | },
264 | // can pass in standard $.ajax() parameters. Callback functions, such as beforeSend,
265 | // will be queued first within the default callbacks.
266 | ajaxSettings: {
267 | // error: function(ct, ci) { /* override default error callback */ },
268 | // beforeSend: function(ct, ci) { /* called first within default beforeSend callback */ },
269 | dataType: 'html'
270 | }
271 | };
272 |
273 |
$(document).trigger('hideCluetip')
274 |
Hides any currently visible cluetip.
275 |
276 | // example for how you might do this with touch devices
277 | $('body').bind('touchstart', function(event) {
278 | event = event.originalEvent;
279 | var tgt = event.touches[0] && event.touches[0].target,
280 | $tgt = $(tgt);
281 |
282 | if (tgt.nodeName !== 'A' && !$tgt.closest('div.cluetip').length ) {
283 | $(document).trigger('hideCluetip');
284 | }
285 | });
286 |
Triggers the cluetip to be shown for a particular element on which .cluetip() has already been called.
289 |
290 |
291 |
292 |
height: Setting a specific height also sets <div id="cluetip-outer"> to "overflow:auto"
293 |
positionBy: Available options are 'auto', 'mouse', 'bottomTop', 'topBottom', fixed'. Change to 'mouse' if you want to override positioning by element and position the clueTip based on where the mouse is instead. Change to 'bottomTop' if you want positioning to begin below the mouse when there is room or above if not (and 'topBottom' for vice versa) — rather than right or left of the elemnent and flush with element's top. Change to 'fixed' if you want the clueTip to appear in exactly the same location relative to the linked element no matter where it appears on the page. Use 'fixed' at your own risk.
294 |
topOffset:For all but positionBy: 'fixed', the number will be added to the clueTip's "top" value if the clueTip appears below the invoking element and subtracted from it if the clueTip appears above. For positionBy "fixed", the number will always be added to the "top" value, offsetting the clueTip from the top of the invoking element.
295 |
leftOffset: For all but positionBy: 'fixed', the number will be added to clueTip's "left" value if the clueTip appears to the right of the invoking element and subtracted if the clueTip appears to the left. For positionBy "fixed", the number will always be added to the "left" value of the clueTip, offsetting it from the right side of the invoking element.
296 |
local: for example, using the default tip attribute, "rel", you could have a link — <a href="somewhere.htm" rel="#someID"> — that would show the contents of the element in the DOM that has an ID of "someID."
297 |
Important: If you use any selector other than a simple ID, the plugin will match the index of the element with the index of the invoking element among all selected elements. For example, if you call $('a').cluetip({local: true}) and you have two links with rel="div.foo", the first link will display the contents of the first div class="foo" and the second link will display the contents of the second div class="foo".
298 |
299 |
300 |
splitTitle: if used, the clueTip will be populated only by the title attribute
301 |
cluetipClass: this is also used for a "directional" class on the same div, depending on where the clueTip is in relation to the invoking element. The class appears in the form of 'cluetip-' + direction + cluetipClass. this allows you to create your own clueTip theme in a separate CSS file or use one of the three pre-packaged themes: default, jtip, or rounded.
302 |
arrows: UPDATE: this option displays a div containing an arrow background image. Arrow images are set using the background-image property in the CSS. The direction of the arrow changes depending on which side of the invoking element the clueTip appears. The arrows option sets the background-position of the cluetip div so that the arrow will accurately point to the invoking element, regardless of where it appears in relation to it.
303 |
304 |
305 |
306 |
307 |
Frequently Asked Questions
308 |
309 |
Is clueTip still being maintained?
310 |
No. It had a good run, but it's old and tired and in need of rest. Take a look at the overview for a list of alternative tooltip plugins.
311 |
312 |
How is clueTip licensed?
313 |
314 |
The clueTip plugin is licensed the same way as the jQuery core file: under the MIT license. The top of the jquery.cluetip.js file has this notice:
315 |
Licensed under the MIT license:
316 | * http://www.opensource.org/licenses/mit-license.php
317 |
318 |
What versions of jQuery is the clueTip Plugin compatible with?
319 |
As of clueTip version 1.06, the plugin is compatible with version 1.3.2 or later. Previous clueTip versions are compatible with jQuery 1.2.6, though 1.3.2 or later is recommended.
320 |
Does the clueTip Plugin have any dependencies on other plugins?
321 |
No. However, optional plugins that can be used in conjunction with the clueTip plugin include hoverIntent and bgIframe.
322 |
How do I get clueTip to work on elements that have been inserted via ajax after the page loads?
323 |
You can call the .cluetip() method on those elements from within the ajax method's callback function. For example:
324 |
How do I get clueTip to show ajaxed content that has changed on the server?
331 |
There are a number of options available for working with dynamic content. By default, the ajaxCache function is set to true. This reduces the number of http requests made to the server. However, it doesn't account for possible changes to the ajaxed data. If the contents of a particular clueTip will be updated on the server between invocations, you may want to set ajaxCache: false.
332 |
333 |
How do I programmatically close (hide) a clueTip?
334 |
If you want to trigger a clueTip to close, based on some other interaction, you can use the following code: $(document).trigger('hideCluetip');
335 |
Why don't the styles that I've applied to my local content carry over once they're inside a clueTip?
336 |
When using an element on the same page to populate the clueTip's content, the plugin clones that element. Because of potential problems caused by duplicate IDs within a page, the plugin also, by default, adds a suffix to the ID of the cloned element. If you have tied styles to the original ID, they won't be carried over. You can either give the localIdSuffix an empty string ( '' ) for its value or add the ID to your stylesheet rule.
337 |
Why don't form elements within a clueTip update when I tell them to?
338 |
If you attempt to update an element based on its ID,
339 |
How do I add a delay before showing or closing the clueTip?
340 |
While the clueTip plugin itself doesn't have a mechanism for delaying responses, it can take advantage of the optional hoverIntent plugin. To delay the showing of a clueTip, use the interval property of the hoverIntent option; to delay its hiding, use the timeout property. Both properties are measured in milliseconds. For example, the following sets both the show and the hide delays to 750 milliseconds (3/4 second):
341 |
Why are the clueTips hidden behind my Flash elements?
351 |
This is a common problem when trying to layer a DOM element over a Flash object. To avoid it, you need to set <param name="wmode" value="transparent" /> inside the <object></object> tags and/or wmode="transparent" as an attribute of the <embed /> tag. For example, your HTML might look like this:
'].join(''),
21 |
22 | /* clueTip setup
23 | * the setup options are applied each time .cluetip() is called,
24 | * BUT only if
is not already in the document
25 | */
26 | setup: {
27 | // method to be used for inserting the clueTip into the DOM.
28 | // Permitted values are 'appendTo', 'prependTo', 'insertBefore', and 'insertAfter'
29 | insertionType: 'appendTo',
30 | // element in the DOM the plugin will reference when inserting the clueTip.
31 | insertionElement: 'body'
32 | },
33 |
34 | /*
35 | * clueTip options
36 | *
37 | * each one can be explicitly overridden by changing its value.
38 | * for example: $.cluetip.defaults.width = 200;
39 | * or: $.fn.cluetip.defaults.width = 200; // for compatibility with previous clueTip versions
40 | * would change the default width for all clueTips to 200.
41 | *
42 | * each one can also be overridden by passing an options map to the cluetip method.
43 | * for example: $('a.example').cluetip({width: 200});
44 | * would change the default width to 200 for clueTips invoked by a link with class of "example"
45 | *
46 | */
47 | defaults: {
48 | multiple: false, // Allow a new tooltip to be created for each .cluetip() call
49 | width: 275, // The width of the clueTip
50 | height: 'auto', // The height of the clueTip
51 | cluezIndex: 97, // Sets the z-index style property of the clueTip
52 | positionBy: 'auto', // Sets the type of positioning: 'auto', 'mouse','bottomTop', 'topBottom', fixed'
53 | topOffset: 15, // Number of px to offset clueTip from top of invoking element
54 | leftOffset: 15, // Number of px to offset clueTip from left of invoking element
55 | snapToEdge: false, // For bottomTop and topBottom, snap to the top or bottom of the element.
56 | local: false, // Whether to use content from the same page for the clueTip's body
57 | localPrefix: null, // string to be prepended to the tip attribute if local is true
58 | localIdSuffix: null, // string to be appended to the cluetip content element's id if local is true
59 | hideLocal: true, // If local option is set to true, this determines whether local content
60 | // to be shown in clueTip should be hidden at its original location
61 | attribute: 'rel', // the attribute to be used for fetching the clueTip's body content
62 | titleAttribute: 'title', // the attribute to be used for fetching the clueTip's title
63 | splitTitle: '', // A character used to split the title attribute into the clueTip title and divs
64 | // within the clueTip body. more info below [6]
65 | escapeTitle: false, // whether to html escape the title attribute
66 | showTitle: true, // show title bar of the clueTip, even if title attribute not set
67 | cluetipClass: 'default',// class added to outermost clueTip div in the form of 'cluetip-' + clueTipClass.
68 | hoverClass: '', // class applied to the invoking element onmouseover and removed onmouseout
69 | waitImage: true, // whether to show a "loading" img, which is set in jquery.cluetip.css
70 | cursor: 'help',
71 | arrows: false, // if true, displays arrow on appropriate side of clueTip
72 | dropShadow: true, // set to false if you don't want the drop-shadow effect on the clueTip
73 | dropShadowSteps: 6, // adjusts the size of the drop shadow
74 | sticky: false, // keep visible until manually closed
75 | mouseOutClose: false, // close when clueTip is moused out: false, 'cluetip', 'link', 'both'
76 | delayedClose: 50, // close clueTip on a timed delay
77 | activation: 'hover', // set to 'click' to force user to click to show clueTip
78 | // set to 'focus' to show on focus of a form element and hide on blur
79 | clickThrough: true, // if true, and activation is not 'click', then clicking on link will take user to the link's href,
80 | // even if href and tipAttribute are equal
81 | tracking: false, // if true, clueTip will track mouse movement (experimental)
82 | closePosition: 'top', // location of close text for sticky cluetips; can be 'top', 'bottom', 'title' or 'none'
83 | closeText: 'Close', // text (or HTML) to to be clicked to close sticky clueTips
84 | truncate: 0, // number of characters to truncate clueTip's contents. if 0, no truncation occurs
85 |
86 | // effect and speed for opening clueTips
87 | fx: {
88 | open: 'show', // can be 'show' or 'slideDown' or 'fadeIn'
89 | openSpeed: ''
90 | },
91 |
92 | // settings for when hoverIntent plugin is used
93 | hoverIntent: {
94 | sensitivity: 3,
95 | interval: 50,
96 | timeout: 0
97 | },
98 |
99 | // short-circuit function to run just before clueTip is shown.
100 | onActivate: function(e) {return true;},
101 | // function to run just after clueTip is shown.
102 | onShow: function(ct, ci){},
103 | // function to run just after clueTip is hidden.
104 | onHide: function(ct, ci){},
105 | // whether to cache results of ajax request to avoid unnecessary hits to server
106 | ajaxCache: true,
107 |
108 | // process data retrieved via xhr before it's displayed
109 | ajaxProcess: function(data) {
110 | data = data.replace(/<(script|style|title)[^<]+<\/(script|style|title)>/gm, '').replace(/<(link|meta)[^>]+>/g,'');
111 | return data;
112 | },
113 |
114 | // can pass in standard $.ajax() parameters. Callback functions, such as beforeSend,
115 | // will be queued first within the default callbacks.
116 | // The only exception is error, which overrides the default
117 | ajaxSettings: {
118 | // error: function(ct, ci) { /* override default error callback */ },
119 | // beforeSend: function(ct, ci) { /* called first within default beforeSend callback */ },
120 | dataType: 'html'
121 | },
122 | debug: false
123 |
124 | }
125 | };
126 | var $cluetipWait,
127 | standardClasses = 'cluetip ui-widget ui-widget-content ui-cluetip',
128 | caches = {},
129 | counter = 0,
130 | imgCount = 0;
131 |
132 | var encodeString = function(str) {
133 | return str.replace(/&/g,'&').replace(/>/g,'>').replace(/
");ee(n)}else if(j.local||0===O.indexOf("#")){if(j.local){var P=t(O+(/^#\S+$/.test(O)?"":":eq("+a+")")).clone(!0).show();j.localIdSuffix&&P.attr("id",P[0].id+j.localIdSuffix),d.html(P),ee(n)}}else if(/\.(jpe?g|tiff?|gif|png)(?:\?.*)?$/i.test(O))d.html(''),ee(n);else{var A=j.ajaxSettings.beforeSend,X=j.ajaxSettings.error,R=j.ajaxSettings.success,J=j.ajaxSettings.complete;v=u(O,j.ajaxSettings.data);var te={cache:j.ajaxCache,url:O,beforeSend:function(t,i){A&&A.call(T,t,p,d,i),f.children().empty(),j.waitImage&&e.css({top:D+20,left:q+20,zIndex:k.data("cluetip").zIndex-1}).show()},error:function(t,e){c.ajaxCache&&!o[v]&&(o[v]={status:"error",textStatus:e,xhr:t}),z&&(X?X.call(T,t,e,p,d):d.html("sorry, the contents could not be loaded"))},success:function(t,e,i){c.ajaxCache&&!o[v]&&(o[v]={status:"success",data:t,textStatus:e,xhr:i}),B=j.ajaxProcess.call(T,t),"object"==typeof B&&null!==B&&(_=B.title,B=B.content),z&&(R&&R.call(T,t,e,p,d),d.html(B))},complete:function(i,o){J&&J.call(T,i,o,p,d);var a=d[0].getElementsByTagName("img");l=a.length;for(var s=0,c=a.length;c>s;s++)a[s].complete&&l--;l?t(a).bind("load.ct error.ct",function(){l--,0===l&&(e.hide(),t(a).unbind(".ct"),z&&ee(n))}):(e.hide(),z&&ee(n))}};r=t.extend(!0,{},j.ajaxSettings,te),o[v]?y(o[v],r):t.ajax(r)}};k.unbind("showCluetip.cluetip",te).bind("showCluetip.cluetip",te);var ee=function(e){var o,a,l,n=_||j.showTitle&&" ",s="",c="",u=!1,g={bottom:function(t){t.appendTo(d)},top:function(t){t.prependTo(d)},title:function(t){t.prependTo(h)}};if(p.addClass("cluetip-"+M),j.truncate){var b=d.text().slice(0,j.truncate)+"...";d.html(b)}n?h.show().html(n):h.hide(),j.sticky&&(g[j.closePosition]&&(o=t('
'].join('')
14 | });
15 | })(jQuery);
16 |
--------------------------------------------------------------------------------
/lib/jquery.hoverIntent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * hoverIntent is similar to jQuery's built-in "hover" function except that
3 | * instead of firing the onMouseOver event immediately, hoverIntent checks
4 | * to see if the user's mouse has slowed down (beneath the sensitivity
5 | * threshold) before firing the onMouseOver event.
6 | *
7 | * hoverIntent r5 // 2007.03.27 // jQuery 1.1.2
8 | *
9 | *
10 | * hoverIntent is currently available for use in all personal or commercial
11 | * projects under both MIT and GPL licenses. This means that you can choose
12 | * the license that best suits your project, and use it accordingly.
13 | *
14 | * // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
15 | * $("ul li").hoverIntent( showNav , hideNav );
16 | *
17 | * // advanced usage receives configuration object only
18 | * $("ul li").hoverIntent({
19 | * sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
20 | * interval: 50, // number = milliseconds of polling interval
21 | * over: showNav, // function = onMouseOver callback (required)
22 | * timeout: 100, // number = milliseconds delay before onMouseOut function call
23 | * out: hideNav // function = onMouseOut callback (required)
24 | * });
25 | *
26 | * @param f onMouseOver function || An object with configuration options
27 | * @param g onMouseOut function || Nothing (use configuration options object)
28 | * @return The object (aka "this") that called hoverIntent, and the event object
29 | * @author Brian Cherne
30 | *
31 | * modified by Karl Swedberg. Namespaced events in order to work better with clueTip plugin
32 | */
33 | (function($) {
34 | $.fn.hoverIntent = function(f,g) {
35 | // default configuration options
36 | var cfg = {
37 | sensitivity: 7,
38 | interval: 100,
39 | timeout: 0
40 | };
41 | // override configuration options with user supplied object
42 | cfg = $.extend(cfg, g ? { over: f, out: g } : f );
43 |
44 | // instantiate variables
45 | // cX, cY = current X and Y position of mouse, updated by mousemove event
46 | // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
47 | var cX, cY, pX, pY;
48 |
49 | // A private function for getting mouse position
50 | var track = function(ev) {
51 | cX = ev.pageX;
52 | cY = ev.pageY;
53 | };
54 |
55 | // A private function for comparing current and previous mouse position
56 | var compare = function(ev,ob) {
57 | ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
58 | // compare mouse positions to see if they've crossed the threshold
59 | if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
60 | $(ob).unbind("mousemove",track);
61 | // set hoverIntent state to true (so mouseOut can be called)
62 | ob.hoverIntent_s = 1;
63 | return cfg.over.apply(ob,[ev]);
64 | } else {
65 | // set previous coordinates for next time
66 | pX = cX; pY = cY;
67 | // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
68 | ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
69 | }
70 | };
71 |
72 | // A private function for delaying the mouseOut function
73 | var delay = function(ev,ob) {
74 | ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
75 | ob.hoverIntent_s = 0;
76 | return cfg.out.apply(ob,[ev]);
77 | };
78 |
79 | // A private function for handling mouse 'hovering'
80 | var handleHover = function(e) {
81 | // next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
82 | var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
83 | while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
84 | if ( p == this ) { return false; }
85 |
86 | // copy objects to be passed into t (required for event object to be passed in IE)
87 | var ev = jQuery.extend({},e);
88 | var ob = this;
89 |
90 | // cancel hoverIntent timer if it exists
91 | if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
92 |
93 | // else e.type == "onmouseover"
94 | if (e.type == "mouseover") {
95 | // set "previous" X and Y position based on initial entry point
96 | pX = ev.pageX; pY = ev.pageY;
97 | // update "current" X and Y position based on mousemove
98 | $(ob).bind("mousemove.cluetip",track);
99 | // start polling interval (self-calling timeout) to compare mouse coordinates over time
100 | if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
101 |
102 | // else e.type == "onmouseout"
103 | } else {
104 | // unbind expensive mousemove event
105 | $(ob).unbind("mousemove.cluetip",track);
106 | // if hoverIntent state is true, then call the mouseOut function after the specified delay
107 | if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
108 | }
109 | };
110 |
111 | // bind the function to the two event listeners
112 | return this.bind('mouseover.cluetip', handleHover).bind('mouseout.cluetip', handleHover);
113 | };
114 | })(jQuery);
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cluetip",
3 | "title": "jQuery clueTip plugin",
4 | "version": "1.2.10",
5 | "description": "Displays a highly customizable tooltip when the user interacts with the matched element.",
6 | "main": "jquery.cluetip.js",
7 | "devDependencies": {
8 | "grunt": "~0.4.0",
9 | "grunt-contrib-jshint": "~0.1.1",
10 | "grunt-contrib-uglify": "~0.1.1",
11 | "grunt-contrib-concat": "~0.1.2",
12 | "grunt-shell": "~0.2",
13 | "grunt-version": "~0.1.1"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git://github.com/kswedberg/jquery-cluetip.git"
18 | },
19 | "keywords": [
20 | "jQuery",
21 | "plugin",
22 | "tooltip"
23 | ],
24 | "author": {
25 | "name": "Karl Swedberg",
26 | "email": "kswedberg@gmail.com"
27 | },
28 | "licenses": [
29 | {
30 | "type": "MIT",
31 | "url": "http://www.opensource.org/licenses/mit-license.php"
32 | }
33 | ],
34 | "readmeFilename": "readme.md"
35 | }
36 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # jQuery clueTip Plugin
2 |
3 | ## Important: This plugin is no longer being maintained.
4 |
5 | I originally wrote clueTip back in 2006 as my first attempt at a jQuery plugin. If I were to write it now, I would do it completely differently. However, I don't have the time or energy to work on it. The good news is that you can use any one of a number of better tooltip plugins. Here are a few:
6 |
7 | * [jQuery UI Tooltip](http://jqueryui.com/tooltip/)
8 | * [Tooltipster](http://iamceege.github.io/tooltipster/)
9 | * [qTip2](http://qtip2.com/)
10 |
11 | ## License
12 |
13 | Dual licensed under the MIT license:
14 |
15 | * http://www.opensource.org/licenses/mit-license.php
16 |
17 | Copyright Karl Swedberg
18 |
19 | ## Requirements
20 |
21 | * jQuery v1.3+
22 |
23 | ## Description
24 |
25 | Displays a highly customizable tooltip when the user interacts with the matched element. As of clueTip version 1.1, this plugin is [ThemeRoller Ready][1].
26 |
27 | * **Full documentation**: [http://plugins.learningjquery.com/cluetip/]
28 | * **Demos**: [http://plugins.learningjquery.com/cluetip/demo/]
29 |
30 | ## Known Issues
31 |
32 | * When `.cluetip()` is invoked from an image map `` element, the plugin ignores the `postionBy` option. Positioning the tooltip by the `coords` is beyond the scope of the plugin, so it instead falls back to positioning according to the mouse's position (`event.pageX` and `event.pageY`) when it enters the ``.
33 |
34 | ## Important clueTip 1.2 Change
35 |
36 | Version 1.2 of the clueTip plugin changes the HTML structure of the tooltip. It uses classes instead of IDs for the elements within the clueTip. This allows multiple tooltips to be visible at the same time (one per call to the .cluetip() method) if the `multiple` option is set to `true`.
37 |
38 | The plugin may not work as expected if you update jquery.cluetip.js to version 1.2+ and you don't also update the jquery.cluetip.css stylesheet.
39 |
40 | If you have a lot invested in the old clueTip's structure with the IDs, you can get it back by:
41 |
42 | 1. adding the lib/jquery.compat.cluetip.js file immediately after jquery.cluetip.js, AND
43 | 2. replacing lib/jquery.cluetip.css with jquery.compat.cluetip.css.
44 |
45 | ## Features
46 |
47 | ### Options
48 |
49 | The clueTip plugin allows for (too?) many options. For a complete list, check out the [plugin's homepage][2]
50 |
51 | ### Content via ajax
52 |
53 | By default, the clueTip plugin loads a page indicated by the "rel" attribute via ajax and displays its contents. However, *the attribute to be used for both the body and the heading of the clueTip is user-configurable*.
54 | If a "title" attribute is specified, its value is used as the clueTip's heading.
55 |
56 | ### Content from HTML element
57 |
58 | Optionally, the clueTip's body can display content from an element on the same page.
59 |
60 | Just indicate the element's id (e.g. "#some-id") in the rel attribute.
61 |
62 | ### Content from title attribute
63 |
64 | Optionally, the clueTip's body can display content from the title attribute, when a delimiter is indicated.
65 |
66 | * The string before the first instance of the delimiter is set as the clueTip's heading.
67 | * All subsequent strings are wrapped in separate DIVs and placed in the clueTip's body.
68 |
69 | ## Examples
70 |
71 | ### Basic
72 |
73 | This is the most basic clueTip. It displays a 275px-wide clueTip on mouseover of the element with an ID of "tip." On mouseout of the element, the clueTip is hidden.
74 |
75 | ```javascript
76 | $('#tip').cluetip();
77 | ```
78 |
79 | ### Setting Multiple Options
80 | The following displays a clueTip on mouseover of all `` elements with class="clue". The hovered element gets a class of "highlight" added to it (so that it can be styled appropriately. This may be useful for non-anchor elements in older browsers such as IE6.). The clueTip is "sticky," which means that it will not be hidden until the user either clicks on its "close" text/graphic or displays another clueTip. The "close" text/graphic is set to display at the bottom of the clueTip (default is top) and display an image rather than the default "Close" text. Moreover, the body of the clueTip is truncated to the first 60 characters, which are followed by an ellipsis (...). Finally, the clueTip retrieves the content with a `POST` request rather than the default `GET`.
81 |
82 | ```javascript
83 | $('a.clue').cluetip({
84 | hoverClass: 'highlight',
85 | sticky: true,
86 | closePosition: 'bottom',
87 | closeText: '',
88 | truncate: 60,
89 | ajaxSettings: {
90 | type: 'POST'
91 | }
92 | });
93 | ```
94 |
95 | ### Triggering the `hideCluetip` event (useful for touch devices)
96 |
97 | You can programmatically hide (close) a clueTip by triggering the "hideCluetip" custom event. On a touch-enabled device, for example, you could hide any visible clueTips when the user touches anywhere in the body except on a link or on the clueTip itself:
98 |
99 | ```javascript
100 | $('body').bind('touchstart', function(event) {
101 | event = event.originalEvent;
102 | var tgt = event.touches[0] && event.touches[0].target,
103 | $tgt = $(tgt);
104 |
105 | if (tgt.nodeName !== 'A' && !$tgt.closest('div.cluetip').length ) {
106 | $(document).trigger('hideCluetip');
107 | }
108 | });
109 | ```
110 |
111 | More examples can be found at [http://plugins.learningjquery.com/cluetip/demo/](http://plugins.learningjquery.com/cluetip/demo/)
112 |
113 |
114 | ## Credits
115 |
116 | * Originally inspired by Cody Lindley's jTip (http://www.codylindley.com)
117 | * Huge thanks to Jonathan Chaffer, Glen Lipka, Shelane Enos, Hector Santos, Torben Schreiter, Dan G. Switzer, Jörn Zaefferer, and the many others who helped report and fix bugs and suggest features.
118 |
119 | [1]: http://jqueryui.com/themeroller/
120 | [2]: http://plugins.learningjquery.com/cluetip/
121 |
--------------------------------------------------------------------------------
/test/demo:
--------------------------------------------------------------------------------
1 | ../demo
--------------------------------------------------------------------------------
/test/demo.css:
--------------------------------------------------------------------------------
1 | ../demo/demo.css
--------------------------------------------------------------------------------
/test/demo.html:
--------------------------------------------------------------------------------
1 | ../demo/index.html
--------------------------------------------------------------------------------
/test/demo.js:
--------------------------------------------------------------------------------
1 | ../demo/demo.js
--------------------------------------------------------------------------------
/test/files/ajax1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | some page
6 |
7 |
8 |