Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE execCommand return undefined

I'm trying to remove tinyMCE from a specific textarea that I have created earlier but the following command kept on producing "undefined" error (checked using firebug console):

tinyMCE.execCommand('mceFocus', false, 'textarea-plainText');
tinyMCE.execCommand('mceRemoveControl', false, 'textarea-plainText')

I have initialized the TinyMCE for that particular text area using jQuery:

$('textarea#textarea-plainText').tinymce({
                script_url : '<?php echo base_url(); ?>/assets/js/tinymce/tinymce.min.js',
                oninit: function() {
                            $("textarea#textarea-plainText").tinymce().setContent("");
                            $("textarea#textarea-plainText").tinymce().setContent(noteSecContent.html[0].notesec_content);
                        }
            });

I have also try to add tinyMCE using the following command but it also return undefined although I have a textarea with "textarea-plainText" ID:

$.getScript('<?php echo base_url(); ?>assets/js/tinymce/tinymce.min.js', function() {
            window.tinymce.dom.Event.domLoaded = true;
            tinyMCE.init({
                mode: 'none'
            });
            tinyMCE.execCommand('mceAddControl', false, 'textarea-plainText');
        });

In short, I can only initialize either using the jquery method or exact method. But not using tinyMCE.execCommand. Somehow the "exeCommand" command just wont work.

HTML for the textarea:

<div id="plainTextModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="plainTextLabel" aria-hidden="true">
  <div class="modal-body">
   <textarea id='textarea-plainText'></textarea>
  </div>
  <div class="modal-footer">
    <button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <a href="" id="confirm-delete-note-section" class="btn btn-primary">Save</a>
    <a href="" id="confirm-delete-note-section" class="btn btn-info">Save &amp; Close</a>
  </div>
</div>

It's a modal, so it is initially hidden until the modal is called.

I'm using TinyMCE 4.0b1 by the way.

like image 634
svenbit Avatar asked Apr 17 '13 06:04

svenbit


1 Answers

You get undefined because in 4.x they removed mceRemoveControl and mceAddControl (I'm not sure about mceFocus) so use mceAddEditor and mceRemoveEditor instead.

Because these codes did the same stuff they removed mceRemoveControl and mceAddControl in the cleanup.

And also don't forget you need to use tinymce in lower case from now.

like image 200
Nergal Avatar answered Nov 17 '22 18:11

Nergal