I am creating an application with a TinyMCE editor embedded inside it. I want the controls for my application to update when the selection inside the tinyMCE editor changes, so the font, size and color menus show the font, size and color of the selection. Font and color work fine, but I can't figure out how to get the color. Here is the code I am using:
myTinyMCESettings.handle_node_change_callback = function(editor_id,node,undo_index,undo_levels,visual_aid,any_selection){
var editor = tinyMCE.get(editor_id);
selectionChanged(editor,!any_selection);
};
tinyMCE.init(myTinyMCESettings);
function selectionChanged(ed,selection){
var fontName = ed.queryCommandValue('FontName');
var size = parseInt(ed.queryCommandValue('FontSize'));
var color = ed.queryCommandValue('ForeColor');
}
But color === false
. How can I get the foreground color of the selected text or the text at the insertion point within tinyMCE?
EDIT: Tracking this down further, on line 12377 of tiny_mce_prototype_src.js
I see:
// Registred commands
o = t.editorCommands.queryCommandValue(c);
When I walk through this in my debugger, t.editorCommands.queryCommandValue(c);
returns false.
This plugin adds the forecolor/backcolor button controls that enable you to pick colors from a color picker and apply these to text. It adds a toolbar button to enable this functionality.
The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.
These content CSS files can be enabled in the editor using the content_css configuration option. Copied! These content CSS files can also be used as a template for creating a custom content CSS file for the editor. For the CSS files, see: tinymce-dist GitHub Repository - Content CSS files.
I would try to do it in another way (did not check it) - taking computed style:
myTinyMCESettings.handle_node_change_callback = function(editor_id,node,undo_index,undo_levels,visual_aid,any_selection){
var editor = tinyMCE.get(editor_id);
var color = tinyMCE.DOM.getStyle(node, 'color', true); // computes current color
selectionChanged(editor,!any_selection);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With