CF Tooltip
Wednesday, May 6th, 2009By Alex
Let’s look at something handy today, Tool-Tips. These are the supplementary information displayed in a small “hover box” when mouse-over certain elements within the web page. We would usually use this feature for explanation of terms, or larger view of thumbnails.
Traditionally, these “boxes” are coded through javascripts and may not be as flexible as we want them to be.
Introduced in ColdFusion 8, we now have, who would have guessed, CFTOOLTIP! This tag allows you to wrap it around almost any visible element within the page. Being a ColdFusion tag, you will be able to manipulate it in any way ‘coldfusioningly’ possible.
Here’s how you use it.
In its simplest form, to display a single line of explanatory text above an element, this is all we need to do:
<cftooltip tooltip=”ColdFusion is a tag-based programming language that was developed by the Jeremy Allaire in 1995″ >
ColdFusion
</cftooltip>
Taking this a step further, instead of feeding text, you may also feed in HTML tags to achieve your necessary formatting.
In a slightly more advance level, what I personally like best about this tag is the ability to tool-tip from html source.
Here is how you could do it:
Album_thumbnails.cfm
<cfset tiptext = “large_photo_caption.cfm?photo_id=candy_&_seet”>
<cftooltip sourceForTooltip = URLEncodedFormat(tiptext)>
Photo : <img xsrc=”img/candy_&_seet_thumbnail.jpg” />
</cftooltip>
large_photo_caption.cfm
<cfset large_pic = daoPhoto.getPhotoByID(URL.photo_id)>
<cfset large_pic_url = ExpandPath(large_pic.location)><cfimage action=”read” source=”#large_pic_url#” name=”pic”>
<cfset ImageScaleToFit(pic, 240, 180)>
<cfimage action=”writeToBrowser” source=”pic”>
<br>
<cfoutput>#large_pic.caption#</cfoutput>
Do take note that while the first instance of mouseover loads the html from source, subsequent mouseovers will read from cache until the entire page is reloaded.
For more controls, this tag also allows you to pass in the ‘autoDismissDelay’, ‘hideDelay’, ‘preventOverlap’ and ’showDelay’as parameters. However for most scenarios, the default settings are ususally more than sufficient. You may also find out more about this tag from their official documentation.
