首页 文章

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

提问于
浏览
6

按照以下说明操作: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>

对于包含在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);

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

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

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

1 回答

  • 10

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

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

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

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

相关问题