Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Customizing TinyMCE: Adding Setup Event

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

Page: 1
Go to End
Author Topic: 3600 Views
  • Deklin
    Avatar
    Community Member
    16 Posts

    Customizing TinyMCE: Adding Setup Event Link to this post

    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:

    tinyMCE.init({
    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+?

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Customizing TinyMCE: Adding Setup Event Link to this post

    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.

  • Deklin
    Avatar
    Community Member
    16 Posts

    Re: Customizing TinyMCE: Adding Setup Event Link to this post

    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?

    Thanks!

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Customizing TinyMCE: Adding Setup Event Link to this post

    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.

    Rich

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Customizing TinyMCE: Adding Setup Event Link to this post

    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?

  • Deklin
    Avatar
    Community Member
    16 Posts

    Re: Customizing TinyMCE: Adding Setup Event Link to this post

    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?

  • pingu
    Avatar
    Community Member
    75 Posts

    Re: Customizing TinyMCE: Adding Setup Event Link to this post

    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:
    http://tinymce.moxiecode.com/forum/viewtopic.php?pid=42558#p42558

    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?

    3600 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.