This GwtQuery plugin allows you adding easily tooltip to any widget or dom element.
You have just to hover the links in the paragraph below to display the tooltip.
//apply the plugin on all elements with an attribute rel="tooltip" $("[rel='tooltip']").as(Tooltip.Tooltip).tooltip();
Integer dignissim posuere nibh nec venenatis. Nullamalesuada augueid tortor vulputate a luctus libero imperdiet. Curabitur adipiscing elit sodales nisi ullamcorper vel malesuada lacus euismod. Praesent sollicitudin felis eget libero gravida auctor.Nunc facilisis, diam eu porta sollicitudin, metus nisl bibendum magna, nec scelerisque dui mauris et lacus. Aliquam accumsan lorem nunc. Proin nunc enim, malesuada eget tempor non, rhoncus in elit. In sollicitudin condimentum lacus, non ullamcorper ipsum suscipit id. Morbi vitae risus ligula, vita e sodales eros. Curabitur at purus eget neque sagittis consequat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur nec felis vel massa dictum venenatis a tristique nunc. blop
Here are the RichTextArea
and RichTextToolbar
widgets used in the
GWT showcase
We just enhance the RichTextToolbar
by adding nice tooltip for the icons.
//apply tooltip plugin on element of the toolbar defining a title $("[title]", toolbar).as(Tooltip).tooltip();
TBC
The plugin is configurable. You just need to pass an instance of the TooltipOptions
class when you call the plugin :
TooltipOptions options = new TooltipOptions().withDelayHide(100).withDelayShow(200).withPlacement(TooltipPlacement.LEFT); $("[title]", toolbar).as(Tooltip).tooltip(options);
Often, your tooltip will use always the same options. In order to avoid passing a same instance
of TooltipOptions
when you call the plugin, you can define the default options used
by the plugins by calling static methods defined in the TooltipOptions
class:
TooltipOptions.setGlobalDelayHide(100); TooltipOptions.setGlobalDelayShow(200); TooltipOptions.setGlobalPlacement(TooltipPlacement.LEFT); ... //no need anymore to pass an instance of TooltipOptions. $("[title]", toolbar).as(Tooltip).tooltip();
A third way to configure the tooltip plugin is to specify data-* attributes on the element:
<div id="tooltipable" data-tooltip-placement="LEFT" data-tooltip-delayShow="200" title="my tooltip is fantastic">tooltipable element</div> //with a widget $(myWidget).data("tooltip-placement", "LEFT").data("tooltip-delayShow", "200");
Name | Type | Default | Description | Example |
---|---|---|---|---|
animation | boolean | true | apply a css fade transition to the tooltip | without animation - with animation |
html | boolean | false | Insert html into the tooltip. If false, the content of the tooltip will be inserted as innerText and the content will be escaped. Use false if you're worried about XSS attacks. | |
placement | TooltipPlacement TooltipPlacementProvider |
TooltipPlacement.TOP |
How to position the tooltip - top | bottom | left | right The TooltipPlacementProvider allows you providing the placement of the tooltip
dynamically.
|
Tooltip on top Tooltip on left Tooltip on right Tooltip on bottom Placement change every time |
selector | String | false | If a selector is provided, tooltip objects will be delegated to the specified targets. | Check this example |
content | String TooltipContentProvider |
null | You have three different ways to provide the content of the tooltip :
- use the title attribute of the element
- provide a TooltipContentProvider object:
new TooltipOptions().withContent(new TooltipContentProvider() { private int counter = 0; @Override public String getContent(Element element) { counter++; return "This tooltip has been displayed "+counter+ (counter > 1 ? " times" : " time"); } });- provide a simple String : new TooltipOptions().withContent("My tooltip is fantastic"); |
Tooltip with dynamic content |
trigger | TooltipTrigger | TooltipTrigger.HOVER | how tooltip is triggered - click | hover | focus | manual | Click to display the tooltip |
autoClose | boolean | false | Determine if the tooltip should be closed when the user clicks outside of the tooltip. This option is only useful when the tooltip is triggered by click (trigger == TooltipTrigger.CLICK) | Click to display the tooltip |
delay | int | 0 |
delay showing and hiding the tooltip in ms - does not apply to manual trigger type |
delay = 500 ms |
delayShow | int | 0 |
delay showing the tooltip in ms - does not apply to manual trigger type |
delayShow = 500 ms |
delayHide | int | 0 |
delay hiding the tooltip in ms - does not apply to manual trigger type |
delayHide = 500 ms |
container | String | "body" |
Css selector defining the container where the tooltip will be appended. |
Set the container to 'element', if you want that the user can hover the tooltip |
offset | Offset | null |
Offset to apply to the tooltip position. |
Simulate top right placement of your tooltip by using the offset option: |
In some cases, you might want to have more complex widgets shown in your tooltip. You can use the TooltipWidgetContentProvider to provide a widget for the content that triggers the tooltip. The more common use case is when you want to show a toolbar on a CellTable. Hover on a row to view an example