Skip to content Skip to sidebar Skip to footer

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]);
    }
}

Demo


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:

  1. get all paragaphs touched by the user selection
  2. get all nodes under those paragraphs
  3. check if a node is touched by the selection range
  4. 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"