Cannot apply basic style to non editable elements
See original GitHub issueI use TinyMce with the noneditable plugin.
I want to be able to wrap non editable elements with basic styling tags.
For example if I have :
Hello <span class="mceNonEditable">user_name</span> how are you today ?
If I click on user_name
to select the non editable span and click on the TinyMce Bold button.
I would like the result to be :
Hello <b> <span class="mceNonEditable">user_name</span> </b> how are you today ?
But instead of this, nothing happens. When I click the TinyMce Blod button, the code doesn’t change.
I created a small jsFiddle to demonstrate this : https://jsfiddle.net/timotheejeannin/2hhpenm5/
I tried to use the data-mce-contenteditable
attribute to override the non editable behavior when a button is clicked. It looks like it’s used in DOMUtils.js line 1739 to determine if the element is editable or not.
I think the issue comes from the fact that Formatter.js line 715 just returns instead of doing work if a non editable element is found.
I posted a StackOverflow question here : http://stackoverflow.com/questions/40885928/apply-basic-style-to-non-editable-elements-in-tinymce
How can I solve this ? Is this a bug ?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:24
- Comments:21 (2 by maintainers)
This isn’t a bug but rather by design. However we have seen people wanting this behavior so maybe we should change the code to allow elements to be styled.
I figured out a “slightly” less hacky way to do this. Essentially, I register a “BeforeExecCommand” event that, for certain events, removes the contenteditable attribute, allows the command to run, and readds the contenteditable false attribute in the “ExecCommand” event. Doing so allowed me to avoid having to custom handle the various possible events that I have seen in other proposed solutions. I have forked your original example to demonstrate the solution (and added a couple of additional formatting options and a “Variables” feature) which can be found here: https://jsfiddle.net/hunterae/8fsnv3h6/40/
Here are the most relevant pieces of the solution: