Quick and Easy Beauty Tips
On a recent project I wanted to use the jQuery BeautyTips module to help me convey more information to the user while saving space on the page.
This plugin was created by Jeff Robbins of Lullabot fame and has a project page at this link.
You have probably seen the video about how to enhance drupal views with BeautyTips at this link. While that method works well, I think mine is easier. Feel free to let me know what you think.
I use the Views Customfield module to help be build the text for the BeautyTip. This is an awesome little module that lets you add a custom field to your views. There are 3 types of custom fields you can add; PHP, Markup, and Rownumber. The PHP field is very powerful on its own but this method of building quick BeautyTips uses the Markup field. The Markup field as described on the project page is a "Field that allows usage of custom text and the input filter system."
So let's say you have a content-type for customers. The node title is the customer name and you have added a field for phone number, address, and picture. You want to create a view that lists the customers by name but when you roll the cursor over the name you get a fancy BeautyTip popup showing their information.
I'm going to assume you know how to work with views and already have a content-type called customer.
Create a new view and add a page display for the list. Filter by the usual "node - is published" and "node-type - customer".
Add the following fields;
Content: Phone - check 'Exclude from display'
Content: Address - check 'Exclude from display'
Content: Customer Logo - check 'Exclude from display'
Customfield: Markup - check 'Exclude from display'
Node: Title
The Fields section of your view should look like the image above.
Note that the order is important here. If you click on the "Customfield: Markup" field and check the box that says 'Rewrite the output of this field', a textbox and some other information will appear. Look at where it says "Fields" and you will see a list of all the fields you have previously added. If you have been following along with this, it should look as follows
* [field_phone_value] == Content: Phone (field_phone)
* [field_address_value] == Content: Address (field_address)
* [field_customer_logo_fid] == Content: Customer Logo (field_customer_logo)
* [markup] == Customfield: Markup
What this means is that you have available to you the values of all the fields listed here. Any field that comes after the customfield will not have its values available to the customfield, so that is why order is important.
In the box labled 'Text:' enter the following:
<div>[field_customer_logo_fid]</div> <strong>Phone:</strong> [field_phone_value]<br> <strong>Address:</strong> [field_address_value]
Click update to save your field settings.
Now click on the Node:title field, check 'Rewrite the output of this field' and type the following in the text box:
<span class='btytp' title='[markup]'>[title]</span>
What we are doing here is simply rewriting the output of this field in order to put the value of '[markup]' into the title attribute of the span element. And the value of [markup] is the logo, phone number, and address in html format.
Under 'Basic settings' click on Header and type the following in the text box.
<?php drupal_add_js ( '$(document).ready(function() { $(".btytp").bt(); }); ', 'inline'); ?>
Be sure to choose PHP as the input format.
This is the BeautyTips jQuery code that will find all the elements with a class name of 'btytp' and attach the BeautyTips ballon to it.
One thing to keep in mind here is that the BeautyTip ballon will not work in Views Live Preview, at least it didn't for me. I had to add a page display and give it a path, then I could test my new BeautyTips. But if you put your cursor over the views output in Live Preview you should get the normal 'Tool Tip' that will show you the value of the title attribute.
If all goes well you should have something like you see in the images here.
This trick came about while I was working on a recent website redesign which I covered in detail in a case study. I used this BeautyTips trick in several places, but in particular you can see how I used the Customfield PHP Code field type in this section.
- Development:
- Version:








Comments
php tag around drupal_add_js
Just a small comment on this excellent post,
don't forget to put the php tag around drupal_add_js
Elie Cohen
You're right! Thanks for
You're right! Thanks for pointing that out. I added it to my post.
Tim
displaying forms in beautytips
Is there a way to have a form inside a beautytip? I can display a form in a beautytip but cannot fill in text fields etc. because when I move the mouse from the link (triggered by hover), the tip disappears. Is there a way to freeze the tip and release it via user action? Say the tip should freeze if the mouse moves into the region of the beautytip. Else it may disappear. Furthermore, in a tip that is frozen, can a 'close' link be placed so that the user may close the tip?
Loading ASP pages into the tip with Ajax
hi Tim
excellent post. I do have one possibly unrelated question. Are you able to load PHP pages into the tip using the Ajax component of BeautyTips? I ask because I've been having trouble getting .asp or .inc files to load, when using IE7+ as my browser. With other browsers, of course it works fine, but with IE I can only load static .html files into the tip. I was wondering if you might've had the same issue with PHP. Any help would be appreciated. Thanks...
Can this be used for redirecting?
Hi,
I'm trying to construct a view where:
1. If there are no arguments, all nodes of a certain type are presented.
2. If there's a specific argument, it will always result in zero or one nodes appearing (never more).
In the second case, I would like the view to automatically redirect the user to the node's page. I was trying to add a "window.location.href" script to send the user off to the other page, but have been failing utterly.
Can you help me with a solution to this? Note that the code must identify whether one node is displayed or the entire list...
Thanks!
does this work on blocks?
I followed your very helpful tutorial to the T but for some reason, the tooltip does not show up on my comment block titles. Any pointers? I get the full
<div>blah blah</div>on rollover but its not showing up as a tooltip. View source reveals the and the java in the header. Is it a problem with views blocks?Its working for me in the
Its working for me in the live preview of a view but not on the actual page.
In the live preview I get only a facebook style balloon with no text in it. Whereas on the actual page, I get nothing.
Beauty Tips display in HTML
Following the instructions above, my beautytips pop up okay, but they look like the Views Live Preview version you mentioned (even in the page view). i.e. It displays the raw html not the formatted html view. I even changed the site setting to default to full html but can't get the beauty tip to not have the html in the text. Any suggestions greatly appreciated. Great instructions up to that point - thanks!
QUICK AND EASY BEAUTY TIPS
This site is an amazing reference for graphic designer quick and easy beauty tips like myself who were not formally trained. It gives access to the best education you can get which is personal experience and wisdom from those who have already walked the path. Thank you.
Great Tutorial
Works great, just wanted to add: views has a custom field by default that works just fine for this purpose, but if your pop up content is dynamic and may not have a value for some fileds, i found it best to create the wrappers and labels for each individual field and check the hide if empty box.
then use a custom field to list all my field tokens
Linking Beautytips to Image and HTML Filter
Great tutorial. I have been looking for something like this.
I still have two problems.
1)How do I link the balloon to an image I am displaying instead?
I am displaying my filter contents in a grid as a node, which includes an image from the node. I have tried to link this to an image, but it does not work.
2)Like the previous person's comment. How do I get the balloon to filter HTML code before outputting it. I have a cck field that I have styled with HTML and it is showing raw HTML rather than filtered HTML.
I can be contacted at chompzer[at]gmail.com
Thank you. You are awesome.
Followed Your Tutorial, But Still Not Working
Hi again, I tried out the tutorial following the instructions verbatim, but the balloons are not displaying filtered html. The balloon is displaying the html code.
Is there a global setting I should change, so it filters the html?
Could you post a screen shot of your Views UI edit page?
I still have not been able to link the balloon to an image.
Thank you.