0

I am tried to add A tinyMCE editor on an ajax facebox popup window but it doesn't show up. I referred to this link http://www.tinymce.com/forum/viewtopic.php?id=27754 but its not working in my code. I am using CodeIgniter platform.

my code is this

<script type="text/javascript">

jQuery(document).ready(function($) {

      tinyMCE.init({
      mode: "textareas",
              theme : "simple",
      editor_selector :"mceEditor"
  });   

      $('a[rel*=facebox1]').facebox({
        loadingImage : '<?php echo site_url();?>images/loading.gif',
        closeImage   : '<?php echo site_url();?>images/closelabel.png',
  })


    $('.edit_id').click(function(){

        var news_id = $(this).attr('id');

        $.ajax({
        type:"POST",
        url:"<?php echo base_url();?>news/GetnewsAjax/",
        data:"id="+news_id, 
        success:function(msg){
        //alert(msg);
        $('#demo').html(msg);
        tinyMCE.execCommand('mceAddControl', false, "news_article");
        $(".myclass").trigger("click"); 
        }


   });

});

});
</script>

Please anyone help me to solve this problem

Asciiom
  • 9,867
  • 7
  • 38
  • 57

1 Answers1

0

use the magic.

function removeTinyMCE(ID) {
        if ((tinyMCE==undefined)||(tinyMCE==null)) {
            return false;
        }
        if (tinyMCE.getInstanceById(ID))
        {
            tinyMCE.execCommand('mceFocus', false, ID);                    
            tinyMCE.execCommand('mceRemoveControl', false, ID);
        }
    }
  • ID is an id of target textarea on that editor must be created – Max Tatarchenko Sep 14 '12 at 10:44
  • Thanks can you please specify were this function is calling?? – Sajeev Krishnan Sep 14 '12 at 10:50
  • i am trying to add a function removeTinyMCE('news_article') inside the success:function(msg) and place the function on inside the $(document).ready(function()) but its not working – Sajeev Krishnan Sep 14 '12 at 11:07
  • look how it works. MCE has a bug. It breaks or blocks on hide/show. You do it so 1) show a popup with textarea 2) init MCE on it 3) on close popup delete MCE. The thick is to avoid MCE being hidden. You have to add it to visible element and delete from element, that is still visible, and only then hide it. – Max Tatarchenko Sep 14 '12 at 11:21
  • Thanks for your suggestion but my problem is that loading the facebox at first time also text area not display tiny editor – Sajeev Krishnan Sep 14 '12 at 11:42
  • try to init mce after facebox is shown. jQuery('textarea selector').tinymce({mode: "textarea",script_url : '/js/jquery/tinymce3.5/tiny_mce.js',theme : "advanced"}); – Max Tatarchenko Sep 14 '12 at 12:03