I am improving TinyMCE editor and want to add buttons Default color in forecolor and backcolor. This is how I get selected text with random style of background colors:
outer = tinyMCE.activeEditor.selection.getNode().outerHTML;
For example, there could be something like this:
<p style="font-size: 18px;">
sadasdasdsasdasda
<span style="background-color: rgb(0, 255, 0);" data-mce-style="background-color: #00ff00;">sdasdasda</span>
<span style="background-color: rgb(255, 0, 0);" data-mce-style="background-color: #ff0000;">
<span style="background-color: rgb(0, 255, 0);">sdasd</span>
asdasdasdas
</span>
dasdasd
</p>
I already tried .each
in jQuery, but not worked. This is that actual code:
$(outer).each(function() {
$(this).css({'background-color': 'transparent'});
});
I am not master in Javascript, neither in jQuery. What could I do to remove all background-color
from outer
?
Use like this
$("*").each(function () {
$(this).css('background-color', 'transparent');
});
Edit
var a='<p style="font-size: 18px;">sadasdasdsasdasda<span style="background-color: rgb(0, 255, 0);" data-mce-style="background-color: #00ff00;">sdasdasda</span><span style="background-color: rgb(255, 0, 0);" data-mce-style="background-color: #ff0000;"><span style="background-color: rgb(0, 255, 0);">sdasd</span>asdasdasdas</span>dasdasd</p>';
var outer=$(a);
outer.find("*").css('background-color','transparent');
$("div").append(outer);
All to need is edit function in plugin ( plugins/textcolor/plugin.js
). Then result will be:
function onPanelClick(e) {
var buttonCtrl = this.parent(), value;
if ((value = e.target.getAttribute('data-mce-color'))) {
buttonCtrl.hidePanel();
buttonCtrl.color(value););
if (value == 'transparent') {
tinyMCE.execCommand("RemoveFormat");
} else {
editor.execCommand(buttonCtrl.settings.selectcmd, false, value);
}
}
}
After that, edit tinymce.js
is required too. All to need is editor removeformat
, for example:
removeformat: [
{selector: 'span', styles: ['background-color'], remove: 'empty', split: true, expand: false, deep: true}
]
( FOR OTHER USERS ) to add new color to panel, insert this code in function renderColorPicker()
, recommended before loop:
function renderColorPicker() {
...
html += '<tr>';
html += (
'<td colspan="' + cols + '">' +
'<div id="' + ctrl._id + '-00" class="color-box"' +
' data-mce-color="transparent"' +
' role="option"' +
' tabIndex="-1"' +
' style="background-color: transparent"' +
' title="Default color">' +
'<span>Default color</span></div>' +
'</td>'
);
html += '</tr>';
for (y = 0; y < rows; y++){
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.