addJSHTMLFilter

Availability: >= 3.0

Type: Object Method

Description: Allows you to set up HTML filters from the PHP API.

Syntax:

$editor->addJSHTMLFilterstring $filternamestring $function );

This method provides a convenient hook into the JavaScript API.

HTML filters are JavaScript functions that can be used to alter the HTML code generated by the editor.

They can be used to alter the format of code generated by the editor or to parse basic placeholder tags. 

Parameters:

$filtername
The name of the filter event that should call this function.

$function
The JavaScript function that will perform the filter. This could be the name of an existing JavaScript function or the function code itself.

Example:
In the following example the first filter converts the template tag {site_url} to a URL when switching to design view so that images do not appear as broken images. The second filter converts the URL back into the {site_url} tag when generating source code.

// Design view filter
$editor->addJSHTMLFilter('design''function (editor, html) {
    return html.replace(/{site_url}/gi, "http://www.wysiwygpro.com");
}'
);

// Source view filter
$editor->addJSHTMLFilter('source''function (editor, html) {
    return html.replace(/http://www.wysiwygpro.com/gi, "{site_url}");
}'
);


To add filters for template tags you should use the templateFilter plugin.