jquery-ui使用TinyMCE编辑器对div进行排序会导致文本消失

hel*_*ing 6 tinymce jquery-ui-sortable meta-boxes

按照以下说明操作:http: //www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/

我的metaboxes中有一些不错的WYSIWYG编辑器

我的标记看起来像:

 <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>
Run Code Online (Sandbox Code Playgroud)

对于包含在div中的textarea,这只是WP_alchemy(也来自farinspace.com)

和告诉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);
Run Code Online (Sandbox Code Playgroud)

那部分工作正常.但是当我尝试jqueryUI可以排序时:

$('.sortable').sortable();
Run Code Online (Sandbox Code Playgroud)

它让我可以对多个.sortme div进行排序,但编辑器中的内容会消失.我怎样才能使文字持续存在?它对于tinymce编辑器工作得很好,所以我认为这是一种冲突,不知何故.

Tha*_*ama 10

这个($('.sortable').sortable();)不适用于tinymce编辑器.Tinymce不喜欢被拖到dom周围.为了使它工作,你首先需要关闭Tinymce

tinyMCE.execCommand('mceRemoveControl', false, id);
Run Code Online (Sandbox Code Playgroud)

然后排序然后重新初始化它们

tinyMCE.execCommand('mceAddControl', false, id);
Run Code Online (Sandbox Code Playgroud)

  • 我不能让这个工作.即使在开始和结束时添加此内容,我的内容仍会被删除 (3认同)