Textbox.io 2.x Documentation : editor.filters.predicate.addInput()

Create a predicate based input filter for an editor instance with editor.filters.predicate.addInput().

The predicate based input filter modifies content added to the editor with: textboxio.replace(), editor.content.set()editor.content.insertHtmlAtCursor().

Example

editor.filters.predicate.addInput(matchingFn, callback)
// A matching function identifying elements that are HTML comments and then returning those elements
var comments = function(element) {
    return element.nodeType == 8 || element.nodeName == '#comment';
};

// Create an in filter identifying comments, supplying the matching function highlights the comment text in a red span and then removes the original comment
editor.filters.predicate.addInput(comments, function(elements) {
    $(elements).each(function(index, element){
    var textContent = $(element)[0].textContent;
        $(element).after('<span style="background-color:red;">' + textContent + '</span>');
        $(element).remove();
    });
});

Parameters

matchingFnFunctionSpecify a named function that returns the elements you wish to pass to the callback function.
callbackFunctionA function to process the array of matched elements.

Returns

No return value.

See Also

Filtering Content