Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Customizing TinyMCE: Adding Setup Event

Go to End

7 Posts   6035 Views


Community Member, 16 Posts

14 July 2010 at 1:04pm

TinyMCE allows you to create a JavaScript function to be executed when the editor first loads. Here is an example of how to do this with TinyMCE:

      mode : "textareas",
      theme : "simple",
      setup : function() { alert('This function runs when TinyMCE has fully loaded.') );

In older versions of TinyMCE I could accomplish this by hacking cms/javascript/tinymce.template.js but now that file seems to be replaced with a dynamic alternative.

How can I add a setup : function() to TinyMCE in SilverStripe version 2.4+?


Community Member, 181 Posts

14 July 2010 at 2:04pm

Edited: 14/07/2010 2:09pm

I've had mixed results configuring TinyMCE in the CMS but you should be able to add options via HtmlConfigEditor in your _config.php e.g.

 HtmlEditorConfig::get('cms')->setOption('setup', 'yourSetupFunction');
and include your javascript file with the setup function using LeftAndMain::require_javascript()

The main issues I've had are mostly to do with the version of TinyMCE but that should work. take a look at _config.php in cms for the setup of the default editor profile.


Community Member, 16 Posts

14 July 2010 at 11:54pm

This does not work. It gives a JavaScript error: "F is undefined"

HtmlEditorConfig::get('cms')->setOption('setup', "window.onload = function() {alert('Editor Loaded')}");

Am I doing anything wrong? Is this a TinyMCE bug?



Community Member, 181 Posts

15 July 2010 at 9:33am

Well, it sounds like the option is being set at least.

At this point I think you'll need to look at the javascript with firebug or similar. It's possible that there's already a window.onload already being called and you can't have more than one AFAIK or some other syntax conflict, try something else so you can test it's being called correctly. There's a LOT of javascript in the CMS.

Beyond that, I'm afraid I won't be of much more help.



Community Member, 181 Posts

15 July 2010 at 10:00am

Okay, so I've tried it quickly myself.

"setup" is definitely being set, however, you're correct that as soon as you have any value in there it produces two errors in the CMS;
f is undefined - tiny_mce_src.js Line 9365
tree.setCurrentByIdx is not a function - LeftAndMain_left.js Line 26

So, it could be a conflict between TinyMCE and one of the many other scripts, and that's way beyond me, sorry.

Perhaps there's a better place to fire a setup event?


Community Member, 16 Posts

15 July 2010 at 10:54am

Thanks for the help. Yes, the JavaScript is definitely being set however it seems to destroy TinyMCE in the process.

Does anyone else have any experience with this?


Community Member, 75 Posts

17 January 2011 at 4:56pm

I also need to do this - I need to add a character count to TinyMCE, and I was hoping to do it using this code snippet:

Does anyone have any tips on how I can create a setup event, or if there are better ways of adding a character count to TinyMCE?