[wp-trac] [WordPress Trac] #19173: Issues with wp_editor() when used inside of a meta box.

WordPress Trac noreply at wordpress.org
Thu Dec 13 17:01:04 UTC 2012


#19173: Issues with wp_editor() when used inside of a meta box.
--------------------------+-------------------------
 Reporter:  goto10        |       Owner:  azaozz
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Editor        |     Version:  3.3
 Severity:  normal        |  Resolution:  maybelater
 Keywords:                |
--------------------------+-------------------------

Comment (by devesine):

 Replying to [comment:5 azaozz]:
 > Another possibility would be to get the content of the editor and then
 destroy the instance on dragstart. Then on dragend initialize it again and
 set the content. Such code should go in postboxes.js inside the
 UI.sortable, will run some tests with that too.

 (Since we just addressed this, I thought I'd post what information we
 have.)

 We're using the following code to do this in WP 3.5, and it seems to be
 working well and robustly (with multiple metaboxes containing multiple
 TinyMCE editors).  The selectors could probably be refined a bit.

 {{{
 // TinyMCE doesn't handle being moved in the DOM.  Destroy the
 // editor instances at the start of a sort and recreate
 // them afterwards.
 var _triggerAllEditors = function(event, creatingEditor) {
         var postbox, textarea;

         postbox = $(event.target);
         textarea = postbox.find('textarea.wp-editor-area');

         textarea.each(function(index, element) {
                 var editor;
                 editor = tinyMCE.EditorManager.get(element.id);
                 if (creatingEditor) {
                         if (!editor) {
                                 tinyMCE.execCommand('mceAddControl', true,
 element.id);
                         }
                 }
                 else {
                         if (editor) {
                                 editor.save();
                                 tinyMCE.execCommand('mceRemoveControl',
 true, element.id);
                         }
                 }
         });
 };
 $('#poststuff').on('sortstart', function(event) {
         _triggerAllEditors(event, false);
 }).on('sortstop', function(event) {
         _triggerAllEditors(event, true);
 });
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19173#comment:17>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list