8

On a multi-tab page, some tabs submit process changes the content of other tabs through an ajaxSubmit. If the other tab contains active tinyMCE edits what should I do to that tab before replacing it's content and what should I do (if anything) after the replacement?

Currently the code performs tinyMCE.execCommand("mceRemoveControl", true, ed_id); on all editors in the target tab and relies on the normal functionality of the system to bring them back after the change. Is that all that is necessary? I am experiencing obscure exceptions within the tinyMCE code after the change but it is difficult to discover the cause.

The error itself is SCRIPT5022: IndexSizeError - tiny_mce.js (1,78075) but I doubt that is specifically relevant.

TinyMCE v3.4.5

OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
  • https://stackoverflow.com/a/10096122/1544886 – K Scandrett Jul 21 '17 at 10:00
  • I don't know if it makes a difference but I'd use `tinyMCE.execCommand("mceRemoveControl", false, ed_id);` anyway – K Scandrett Jul 21 '17 at 10:02
  • @KScandrett - Why - what is the difference? A quick poke around in the code suggests that the `remove` method ignores the 2nd parameter. Thanks for the interest anyway. – OldCurmudgeon Jul 21 '17 at 10:45
  • I don't know. I did look into that but couldn't get a definitive answer. I see both values used, so yeah I don't expect it makes a difference, but wanted to throw it out there just in case. The "mceRemoveControl" examples however on the tinymce official site pass `false`. – K Scandrett Jul 21 '17 at 11:00
  • TinyMCE does not play nice with AJAX I have spending along time trying to hack it to work nice and effectivly i gave up and started using CKEditor you just need to remove CKEditor before changes then re initialise it when you have finished or the AJAX has returned – Barkermn01 Jul 25 '17 at 16:52

1 Answers1

4

As i said in my Comments TinyMCE does not play well with AJAX there are loads of problems with it i have tried many times to get it to work.

In the end i switched to CKEditor so if you would like to try and use it you can here is the code you need for the ajaxSubmit() options

beforeSubmit:function{
   for(var instanceName in CKEDITOR.instances) {
        try{
            CKEDITOR.instances[instanceName].destroy();
        }catch(e){
        }
    }
}

the above code will remove CKEditor cleanly before you submit the following is how to re-inistialize CKEditor when your ajax has finished again this is a option for ajaxSubmit():

success:function(){
    // do what you need to update your DOM and then final call is
    $("editorSelector").ckeditor(options);
}
Barkermn01
  • 6,781
  • 33
  • 83