wicketstuff-minis-prototip

Prototip Behaviour

So what is it?

Prototip behaviour allows you to add tooltips based on the prototip librarywithout having to write any javascript.  The contents of the tooltip can be either a string, or any wicket component (eg a panel).

Requirements

 The prototip.js file requires both prototype and scriptaculous, neither are included so you will need to include them yourself.  It also requires wicket 1.3 and Java 5 or newer.  The actual prototip javascript and css files are included so you dont need to worry about including them.

Usage 

 The most simple usage example is that of adding a string tooltip to a label, which can be done as so:

Label toolTargetWithString = new Label("toolTargetWithString", "I am a label which has a string tooltip");
toolTargetWithString.add(new PrototipBehaviour("I am a string tooltip"));
add(toolTargetWithString);





Or to add a wicket panel as the tooltip contents:

// Label with panel as a tooltip
Label toolTargetWithPanel = new Label("toolTargetWithPanel", "I am a label which has another wicket panel as a tooltip");
add(toolTargetWithPanel);

 //This is the panel which will be added as a tooltip
 //It needs adding to the page, but does not need hiding
 Panel tooltipPanel = null;
 add(tooltipPanel = new MyToolTipPanel("toolTipPanel"));

//A panel tooltip
final PrototipBehaviour panelTip = new PrototipBehaviour(tooltipPanel);
toolTargetWithPanel.add(panelTip);





 Prototip has lots of options.  To set these create a PrototipSettings object, set the settings you require (see the prototip.js page for more info on what these mean) and add the settings to your PrototipBehaviour.

//Because prototip has lots of settings, these settings are set up in a new class,
// this allows sharing of the same setting between different tooltips
PrototipSettings settings = new PrototipSettings();
settings.setEffect("blind").setDelay("0.2");

//A string tooltip to add to the first label
final PrototipBehaviour stringTip = new PrototipBehaviour("I am a string tooltip").setSettings(settings);
toolTargetWithString.add(stringTip);





 To remove a prototip with an ajax click call the PrototipBehaviour objects remove method, passing in the AjaxRequestTarget:

add(new AjaxLink("remove"){
	@Override
	public void onClick(AjaxRequestTarget target)
	{
		System.out.println("removed both tool tips");
		stringTip.remove(target);
		panelTip.remove(target);
	}
});





 It is possible to add PrototipBehaviour to a component via ajax, even if you havent added any other PrototipBehaviour on this page, the prototip.js and prototip.css files are still referenced automatically:

// Label with no initial tool tip
final Label toolTargetWithNoTooltip = new Label("toolTargetWithNoTooltip", "I am a label which starts out without any tooltips");
add(toolTargetWithNoTooltip);
//since this it to have a tooltip added via ajax it needs a markup id
toolTargetWithNoTooltip.setOutputMarkupId(true);AjaxLink addLink = new AjaxLink("add"){
	@Override
	public void onClick(AjaxRequestTarget target)
	{
		//add the behaviour
		toolTargetWithNoTooltip.add(new PrototipBehaviour("I was added via ajax!!"));

		//add the label to the ajax request target
		target.addComponent(toolTargetWithNoTooltip);
	}
};





 If you are already using the prototip library on your page, or want to include the javascript and css files yourself then you can force the PrototipBehaviour to not contribute the javascript and css files like this:

panelTip.setOverrideHeaderContributor(true);





 There are three different versions of prototip.js included, a normal one, a minified one and a minified and gziped one.  By default the minified one is contributed to the page, you can override this like so:

PrototipBehaviour.setSelectedJsType(JS_TYPE.NORMAL);

This affects all PrototipBehaviour objects in the system.



 Questions or problems?

 Either email me at richardjohnwilkinson (at) gmail (dot) com or fix it yourself and contribute the changes


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced
- Activity

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

or Sign Up  

Other Features

Add Content