Integrating jQuery Fancybox and Tooltips plugins

In the process of adding the lightbox plugin at fancybox.net to a client’s website, it became necessary to integrate it with the jquery tooltip plugin that was already in place and in use on the site to create styled tooltip hovers on certain of the images there.

sample image showing tooltip plugin - image copyright Nancy Carol Willis, all rights reservedsample image showing lightbox with title overlay - image copyright Nancy Carol Willis, all rights reserved
images copyright by Nancy Carol Willis, all rights reserved

As the method of adding tooltips to the images conflicted with how the rel="" attribute was used by the lightbox for grouping sets of images, this required a bit of alteration to the lightbox plugin.

It occurred to me that rev="" as a method of grouping, would be more appropriate, seeing as rev is a backwards link (into the group) whereas rel, being a forwards link to the hidden tag’s content information for the tooltip was appropriate there.

The first step was converting the lightbox plugin to use rev instead of rel, which was fairly easily accomplished. (the following is the output from diff which may be used to patch your copy of jquery.fancybox.*.js)

With that out of the way, the next step was simple. Take the existing jquery code that sets up the tooltips, and add the fancybox call. Except, that didn’t quite work as expected. What I wanted was to be able to pull that same tooltip info (html-styled) in as the title info overlay when the larger image was displayed in the lightbox. I couldn’t simply add it back as a title="" since that would then override the fancy jquery tooltip. Whoops.

With a little assist from the #jquery channel on freenode, I was clued into one of fancybox’s callbacks, titleFormat, and I was soon off and runnning again once I figured out how to index into the id’d element and re-extract the necessary info to add as the title. The problem was, I couldn’t use the existing bodyHandler from the tooltip() call, because by the time we’re within the fancybox() function call internals, “$(this)” didn’t point to the same thing. Double-whoops.

Voila! Fancy tooltips and integration of the tip into the lightbox as a title overlay, with the rel attribute holding the link to the element containing the info describing each image, and the rev attribute holding the grouping information for the mini-gallery to enable users to slide back and forth among each grouping of images on the page.

The finished implementation may be viewed at the top of the page here: Nancy Carol Willis, Writings and Illustration

Shortened URL: http://bit.ly/JDcEMH