last day (14 days later) » 

11:47 AM
1
A: How can I change color of tinymce background onchange using query

kmsdevTo change the body background color you can use: tinymce.activeEditor.contentDocument.body.style.backgroundColor = '#f0f0f0'; To get the active editor as a jQuery element, just use: $(tinymce.activeEditor) Edit: You have to handle events separately, because textarea elements are replaced b...

 
That's a very useful start thanks. It changes the background color. But I can't work out how to call it using myscript. At present I'm monitoring for changes to textarea, input & select I also need to check when the tinymce changes
 
The textarea input is your tinymce editor, so I think you can do something like $(tinymce.activeEditor).on('change', function(){ ... });
 
I tried that - not working :(
 
Let me to understand it correctly. You have some form-type elements. One of these are a tinymce textarea. And you want, if some of this elements are changed, change background color of the element changed? Is it correct?
 
that's exactly right. whenever a form element has been changed i want the background color of that element to change
 
11:47 AM
I edited the answer. I think you can solve it with that piece of code 👍
 
sorry tried your solution it doesnt work for me
I tried both tinymce.activeEditor.on('change', function(){ - js error and $(tinymce.activeEditor).on('change', function(){
 
I'm working right now, so maybe I couldn't answer you as fast as I want. Let's see. What version of tinymce are you using?
My tests were with v4
Try yourself. Open tinymce example page, open the console and paste the piece of code: tinymce.activeEditor.on('change', function(){ this.contentDocument.body.style.backgroundColor = '#f0f0f0' });
 
majorVersion:"3",minorVersion:"5.10",releaseDate:"2013-10-24"
using your code on the tinymc demo page works
if i put it into mt script i get the following js error: TypeError: tinymce.activeEditor is null
Really appreciate your help
 
12:03 PM
I told you the event for v4 version, that's the reason which it is not working. I'll check v3 events to give you a solution.
It's ok, I usually learn a lot helping others, and is a good way to practice some things which are close to be forgotten .)
I got it. Try with this code: tinymce.activeEditor.onChange.add(function(){ this.contentDocument.body.style.backgroundColor = '#f0f0f0' });
 
that still gives me the error TypeError: tinymce.activeEditor is null
 
Uhm.. This editor... Try with tinyMCE instead of tinymce
 
12:19 PM
i should have spotted that
tried with tinyMCE still getting error TypeError: tinyMCE.activeEditor is null
 
Are you sure you are loading the editor? I mean, open the console and start typing tinymce, then type a dot and a popup will appear showing internal objects. Check if activeEditor is there. If it isn't, something else is wrong.
I thought activeEditor is in all tinymce versions
You can check it as before at http://www.tinymce.com/tryit/3_x/full.php (v3 example). Open console and type tinymce.activeEditor.onChange.add(function(){ this.contentDocument.body.style.backgroundColor = '#f0f0f0' });. You will see that it works as expected.
I go to lunch. See you in two hours, hope you can obtain more info about the issue 👍
 
did what you said typed in tinymce. activeEditor is there
might be getting somewhere
putting tinyMCE.activeEditor.onChange.add(function(){ this.contentDocument.body.style.backgroundColor = '#f0f0f0' }); in my script gives me js error
but typing it into console and it works
weird
 
 
1 hour later…
1:46 PM
got it working
$( window ).load(function() {
tinyMCE.activeEditor.onChange.add(function(){ this.contentDocument.body.style.backgroundColor = '#D6FFD6' });
});
Thanks for all your help
 
2:05 PM
So... the window didn't load yet! Well, solved. I'll edit my answer with updated info. I am glad that we finally achieve it 👍
 

last day (14 days later) »