registerButton

Availability: >= 3.0

Type: Object Method

Description: Registers a new button.

Syntax:

$editor->registerButtonstring $idnamestring $tooltipstring $functionstring $url [, int $width [, int $height [, string $buttonStateHandler]]] );

Parameters: 

$idname
A unique id to identify this button.

$tooltip
The tooltip to appear when the user mouses over the button. If you leave the tooltip as an empty value the editor will look in the $lang['editor'] array in the language pack for a key that matches the $idname value.

$function
JavaScript function to be called when this button is pressed. This is equivalent to what you might place in an onclick attribute.

$url
The URL of the image to be used for this button. You might find Parameter Placeholders useful here.

$width
The width of the button. 22 is the default.

$height
The height of the button. 22 is the default.

$buttonStateHandler
ID of the Button State Handler that should handle the selection state for this button.

Once a new button has been registered you can add it to the toolbar layout using addRegisteredButton

Example: 

The following example registers a new button with the id of 'cite'. The new button has been given the button state handler id of 'citehandler'. When clicked the button will insert a cite tag. We have used the addJSButtonStateHandler method to register a handler for the new button that will display the button as latched when the selection is within a cite tag.

Note that we have used Parameter Placeholders to make life easier when setting the $function and $url parameters.

// register a new button:
$editor->registerButton('cite''Citation',
'WPro.##name##.applyStyle("cite")''/shout/web/v5.6.4.M20120621/wysiwygPro/3.2.1.20091130/themes/blue/wysiwygpro/buttons/cite.gif'2222,
'citehandler');

// add the new button to the toolbar layout:
$editor->addRegisteredButton('cite''after:underline');

// register the handler for the new button:
$editor->addJSButtonStateHandler ('citehandler''function (editor,srcElement,cid,inTable,inA,range){
    var c = range.getContainerByTagName("CITE");
    if (c) {
        return "wproLatched";
    } else {
        return "wproReady";
    }
}'
);

See also:

registerMenuButton, registerSelect, registerSeparator, registerSpacer, registerTextButton, setButtonFunction