1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Closed Suggestions' started by cclaerhout, Dec 31, 2012.

  1. cclaerhout

    cclaerhout Well-Known Member

    It would be nice to create an official oninit function for TinyMCE
    For example:
    PHP:
                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
                
    tinyMCE.init(
                {
                <
    xen:hook name="editor_tinymce_init" params="{xen:array 'editorId={$editorId}'}">
                    
    mode'exact',
                    
    elements$editor.attr('id'),
                    
    pluginsplugins,
                    
    cleanupfalse,
                    
    theme'xenforo',
                    
    oninit mceIsReady,
     
    Adam Howard likes this.
  2. cclaerhout

    cclaerhout Well-Known Member

    Proposition of the following solution using templates Hooks until XenForo adds a new hook - see that post.

    PHP:
                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);
                              break;
                    }
                   
                          
    //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);
                       
                break;
    If some developers are interested, please tell me first so I update the MarkItUp Editor addon.
     
    Adam Howard likes this.
  3. Brogan

    Brogan XenForo Moderator Staff Member

    Redundant due to the editor change in 1.2
     

Share This Page