当前位置: 动力学知识库 > 问答 > 编程问答 >

tinymce 4 - Tinymce4 Remove background-color from text with colorpicker

问题描述:

When the user marks a text, he can define a backgroundcolor with the colorpicker (textcolor.plugin).

Once saved he can change the background-color but not get rid of it.

background-color:white is no solution as the bodycolor can be RGB or even a picture.

How is the colorpicker to configure to remove the style-tag or at least insert a background-color:none?

网友答案:

Found a solution changing the plugin (textcolor). If there is a better way please be free to post it.

I added additional colors to the colorpicker. The Color #FFFFFe (near White) i marked as NO COLOR and changed the plugin as shown.

function onPanelClick(e) {
    var buttonCtrl = this.parent(), value;

    if ((value = e.target.getAttribute('data-mce-color'))) {
        buttonCtrl.hidePanel();
        value = '#' + value;
        buttonCtrl.color(value);
        if (value == '#FFFFFe') {  //Changing the value to -1 causes deletion :-)
            value = -1;
        }
        editor.execCommand(buttonCtrl.settings.selectcmd, false, value);
    }
}
网友答案:

Researched a bit more since the given answer did not work in my version 4.5.0 of tinymce.

The textcolor plugin uses 'editor.formatter.remove(...)' to remove text color or background color upon selecting 'x' in the last option of the color palette for 'no color'. While that function is used elsewhere successfully in tinymce (e.g. when removing italics from text), in the context of the textcolor plugin it does not remove color formatting.


Solution:

Replace the following in the textcolor's plugin.js:

editor.formatter.remove(format, {value: null}, null, true);

with:

editor.dom.removeAllAttribs(editor.selection.getNode());



...or in the minified version plugin.min.js:

a.formatter.remove(b,{value:null},null,!0),

with:

a.dom.removeAllAttribs(a.selection.getNode()),



...and things start working as intended.

分享给朋友:
您可能感兴趣的文章:
随机阅读: