-
Notifications
You must be signed in to change notification settings - Fork 0
jWicket UI Tooltip
This is an integration of the jQuery UI tooltip widget. This Wicket Behavior will generate the JavaScript needed to provide a Wicket Component with a jQuery UI tooltip (v. 1.10.3).
- [Usage](jWicket UI Tooltip#usage)
- [Tooltip with content from
title
attribute](jWicket UI Tooltip#tooltip-with-content-from-title-attribute) - [Tooltip with content from
data-tooltip
attribute](jWicket UI Tooltip#tooltip-with-content-from-data-tooltip-attribute) - [Tooltip with dynamic content](jWicket UI Tooltip#tooltip-with-dynamic-content)
- [Tooltip with custom jQuery selector](jWicket UI Tooltip#tooltip-with-custom-jquery-selector)
- [General tooltip configuration](jWicket UI Tooltip#general-tooltip-configuration)
- [Single tooltip configuration for multiple components](jWicket UI Tooltip#single-tooltip-configuration-for-multiple-components)
- [Custom tooltip styling](jWicket UI Tooltip#custom-tooltip-styling)
- [Custom jQuery UI library](jWicket UI Tooltip#custom-jquery-ui-library)
- [License](jWicket UI Tooltip#license)
Below you can find some examples which should demonstrate the usage.
component.add(tooltip_1_10_3());
<div wicket:id="component" title="tooltip content">...</div>
$('#component1').tooltip({...});
The generated JavaScript will add a tooltip widget to the component. The component's markup id will be used as the jQuery selector. The tooltip content will be obtained from the component's title attribute. Note: The content of the title
attribute will be escaped by jQuery UI.
component.add(tooltip_1_10_3());
<div wicket:id="component" data-tooltip="<strong>tooltip content</strong>">...</div>
$('#component1').tooltip({...});
By using the data-tooltip
attribute you can provide the tooltip with markup.
There are several ways to provide dynamic content of tooltips.
content from a String
component.add(tooltip_1_10_3().setContent("content from a String"));
$('#component1').tooltip({content:'content from a String',...});
content from a JS function
component.add(tooltip_1_10_3().setContent(new JsFunction("function(){return 'content from a JS function';}")));
$('#component1').tooltip({content:function(){return 'content from a JS function';},...});
content from another component
component.add(tooltip_1_10_3().setContent(otherComponent));
$('#component1').tooltip({content:$('#markupIdOfOtherComponent').html(),...});
component.add(tooltip_1_10_3(".componentWithTooltip"));
<div wicket:id="component" class="componentWithTooltip">...</div>
$('.componentWithTooltip').tooltip({});
A selector provided to the tooltip factory method will overwrite the default selector. Use this for example if you can't use the component's markup id.
JQueryUiTooltip provides all configuration options of the jQuery UI tooltip widget. It will simply generate the JavaScript code to configure the widget. Please refer to the tooltip API documentation to learn about the configuration of this widget.
component.add(
tooltip_1_10_3()
.setPosition(new JsOption("my", "'center bottom-20'"), new JsOption("at", "'center top'"))
.setOnOpen("function(event,ui){some js code;}"));
$('#component1').tooltip({position:{my:'center bottom-20',at:'center top'},open:function(event,ui){some js code;}});
// configure tooltips globally
page.add(tooltip_1_10_3(".componentWithTooltip").setPosition(...));
// set dynamic tooltip contents
component3.add(tooltipContent("some dynamic tooltip content"));
component4.add(tooltipContent(anotherComponent));
<div wicket:id="component1" class="componentWithTooltip" title="tooltip content">...</div>
<div wicket:id="component2" class="componentWithTooltip" data-tooltip="<strong>tooltip content</strong>">...</div>
<div wicket:id="component3" class="componentWithTooltip">...</div>
<div wicket:id="component4" class="componentWithTooltip">...</div>
$('#component3').attr('data-tooltip','some dynamic tooltip content');
$('#component4').attr('data-tooltip',$('#anotherComponent1').html());
$('.componentWithTooltip').tooltip({...});
In this example the tooltip behavior is added to the page, provided with a custom selector. The tooltip configuration applies to all matching HTML elements. The tooltip contents will be obtained either from the title
attribute or from the data-tooltip
attribute. By adding a JQueryUiTooltipContent behavior to the components 3 and 4, their tooltip contents will be written to their data-tooltip
attributes.
To use a custom CSS resource for your jQuery UI tooltips you can provide them like so:
component.add(new JQueryUiTooltip().addCssResource(new CssResourceReference(getClass(), "jquery-ui-custom.css")));
You can provide a custom version of the jQuery UI tooltip library like so:
component.add(
new JQueryUiTooltip(
new JQueryResourceReference(
getClass(),
"jquery-ui-custom.tooltip.js",
JQueryResourceReferenceType.NOT_OVERRIDABLE)));
Copyright (c) 2013 Martin Knopf
Licensed under the MIT license.
As a sub project of jWicket, jWicket UI Tooltip makes use of core functionality of jWicket.