Tinymce - Limit Removeformat To A List Of Formats
Current tinyMCE version (3.5.2). Hi, I am working on a custom plugin which adds and removes custom formats. Adding a format to the current selection is simple however I couldn't fi
Solution 1:
tinymce.Formatter.remove can be called on a specific node, so:
var selection = ed.selection.getSel(),
ancestor = ed.selection.getNode(),
els = ancestor.getElementsByTagName('span'),
l = els.length,
i = 0;
if (selection.containsNode(ancestor, true) && ancestor.nodeName.toLowerCase() === 'span') {
ed.formatter.remove('demo_format_2', null, ancestor);
}
for ( ; i < l; i++) {
if (selection.containsNode(els[i], true)) {
ed.formatter.remove('demo_format_2', null, els[i]);
}
}
Update: Turns out the trouble is caused by including both inline
and selector
in the format, which marks it as "mixed" (inline + block level). If you define the format with only inline
:
demo_format_1: {
inline: "span",
classes: "demo_format_1"
}
then formatter.remove('demo_format_1')
works as you'd expect (demo).
Solution 2:
You should do the following:
- get all paragaphs touched by the user selection
- get all nodes under those paragraphs
- check if a node is touched by the selection range
- if it is: remove the 'unwanted' class from its class element
I will provide some code for this later.
Post a Comment for "Tinymce - Limit Removeformat To A List Of Formats"