addJSButtonStateHandler

Availability: >= 3.0

Type: Object Method

Description: Registers a new button state handler.

Syntax:

$editor->addJSButtonStateHandlerstring $handleridstring $function );

A button state handler is a JavaScript function that controls when a button should be displayed as ready, disabled or latched.

The ID name of a button state handler is used as the last parameter of the registerButton method. 

This function provides a convenient hook into the JavaScript API.

Parameters: 

$handlerid
The ID name of the new button state handler. This is used when registering a new button that should be controlled by this handler.

$function
The JavaScript function to control the button state. This could be the name of an existing JavaScript function or the function code itself.

Example:

The following example creates a new button that will insert a cite tag and registers a handler for the new button that will display the button as latched when the selection is within a cite tag.

// create a new button and add it to the toolbar:
$editor->registerButton('cite''Citation''WPro.##name##.applyStyle("cite")''/wysiwygPro/themes/blue/wysiwygpro/buttons/cite.gif'2222'citehandler');
$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";
    }
}'
);