TinyMce common oninit function (with a hook or a template)


Well-known member
It would be nice to create an official oninit function for TinyMCE
For example:
            function mceIsReady() {
                //insert a hook here or include a template to manage TinyMCE once it has been loaded in the dom

            tinyMCE.dom.Event._pageInit(window); // for ajax loads
            <xen:hook name="editor_tinymce_init" params="{xen:array 'editorId={$editorId}'}">
                mode: 'exact',
                elements: $editor.attr('id'),
                plugins: plugins,
                cleanup: false,
                theme: 'xenforo',
                oninit : mceIsReady,
Upvote 1
Proposition of the following solution using templates Hooks until XenForo adds a new hook - see that post.

            case 'editor_js_setup':
                //Check if the TinyMCE function oninit has been already activated with the function name "mceIsReady"
                if(!preg_match('#mceIsReady#i', $contents))
                    //Activate the TinyMCE hook "onInit" and link it to the function "mceIsReady"
                          $search[] = "#([ \t]*?)theme:\s*?'xenforo',#i";
                          $replace[] = "$0\n$1oninit : mceIsReady,";
                          //Create the mceIsReady function
                          $search[] = "#([ \t]*?)tinyMCE.init\(#i";
                          $replace[] = "
                          function mceIsReady() {
                              //Write your Js Code here
                          } \n$0";
                          $contents = preg_replace($search, $replace, $contents);
                      //The function mceIsReady() already exists, it then just need to be modified
                      $search[] = "#function mceIsReady() {\s*#i";
                      $replace[] = "$0
                              //Write your Js Code here                   
                      $contents = preg_replace($search, $replace, $contents);

If some developers are interested, please tell me first so I update the MarkItUp Editor addon.
Top Bottom