2011-05-04 19 views
6

以下的說明: http://www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/jQuery的UI與TinyMCE的編輯div的排序導致文本消失

我在我的metaboxes得到了一些不錯的所見即所得的編輯器

我的標記看起來像:

<div class="sortable"> 
<div class="sortme"> 
<?php $mb->the_field('extra_content2'); ?> 
     <div class="customEditor"><textarea name="<?php $mb->the_name(); ?>"><?php echo wp_richedit_pre($mb->get_the_value()); ?></textarea></div> 
</div> 
<div class="sortme" 
<?php $mb->the_field('extra_content3'); ?> 
     <div class="customEditor"><textarea name="<?php $mb->the_name(); ?>"><?php echo wp_richedit_pre($mb->get_the_value()); ?></textarea></div> 
</div> 
</div> 

這僅僅是WP_alchemy(也來自farinspace.com),用於包裹在一個div

一個textarea和腳本第在告訴tinymce踢:

function my_admin_print_footer_scripts() 
{ 
    ?><script type="text/javascript">/* <![CDATA[ */ 

     jQuery(function($) 
     { 
      var i=1; 
      $('.customEditor textarea').each(function(e) 
      { 
       var id = $(this).attr('id'); 

       if (!id) 
       { 
        id = 'customEditor-' + i++; 
        $(this).attr('id',id); 
       } 
       tinyMCE.execCommand('mceAddControl', false, id); 

      }); 
     }); 
    /* ]]> */</script><?php 
} 

// important: note the priority of 99, the js needs to be placed after tinymce loads 
add_action('admin_print_footer_scripts','my_admin_print_footer_scripts',99); 

該部分工作正常。但是當我嘗試在jQueryUI的排序踢:

$('.sortable').sortable(); 

它讓我多.sortme div的排序,但在編輯器中的內容消失。我怎樣才能使文本持久?它在沒有tinymce編輯器的情況下工作得很好,所以我認爲這是一個衝突w /不知何故。

+0

看似重複http://stackoverflow.com/questions/3919928/tinymce的-instances-jQuery排序 – 2015-08-11 18:09:34

回答

10

這($('.sortable').sortable();)將不會與tinymce編輯。 Tinymce不喜歡被拖到dom周圍。爲了讓它工作,你首先需要排序關閉TinyMCE的

tinyMCE.execCommand('mceRemoveControl', false, id); 

然後再重新初始化它們

tinyMCE.execCommand('mceAddControl', false, id); 
+0

所以我挖入可排序的事件,並有事件的開始和停止。所以開始我mceRemoveControl和結束我mceAddControl。似乎工作。謝謝! – helgatheviking 2011-05-05 20:25:31

+0

這是要走的路,*豎起大拇指* – Thariama 2011-05-06 08:11:39

+0

感謝您的答案! – hasentopf 2012-03-20 21:17:36