CKEditor冻结在jQuery UI重新排序 [英] CKEditor freezes on jQuery UI Reorder

查看:310
本文介绍了CKEditor冻结在jQuery UI重新排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用jQuery UI框架重新排序CKEditors的动态创建列表,但我有一个与编辑器释放的问题。当我只是使用< textarea> 时,它工作得很好,但现在,在拖动操作完成后,它不让用户写任何文本。

I am attempting to reorder a dynamically created list of CKEditors using the jQuery UI framework, but I am having an issue with the editor freeing. It worked perfectly when I was just using a <textarea>, but now, after the dragging action completes, it doesn't let the user write any text.

这是Javascript代码:

This is the Javascript code:

$(function() {
    $("#list").sortable({
        placeholder: 'ui-state-highlight'
    });
    $("#list").disableSelection();

    for (i=0;i<10;i++)
    {
        addEditor();
    }
});

function addEditor()
{
    alert("Hello");
    var editor_fields = document.editors.elements["editor[]"];

    var editorAmount = 0;

    if (editor_fields.length)
    {
        editorAmount = editor_fields.length;
    }
    else
    {
        editorAmount = 1;
    }

    var newElem = $('#editor_container' + editorAmount).clone().attr('id', 'editor_container' + (editorAmount + 1));

    newElem.html("<textarea class='editor' name='editor[]' id='editor" + (editorAmount + 1) + "' rows='4' cols='30'></textarea>");

    $("#editor_container" + editorAmount).after(newElem);

    $("#editor" + (editorAmount + 1)).ckeditor();
}

这是HTML代码:

<form name="editors">
    <ul id="list">
        <li name="editor_container1" id="editor_container1"><textarea name='editor[]' id='editor1' rows='4' cols='30'></textarea></li>
    </ul>
</form>


推荐答案

虽然不太理想,

 $(function () {
        $("#list").sortable({
            placeholder: 'ui-state-highlight',
            start: function () {
                $('.editor').each(function () {
                    $(this).ckeditorGet().destroy();
                });
            },
            stop: createckeditor()
        });
        $("#list").disableSelection();

        for (i = 0; i < 10; i++) {
            createckeditor()
        }
    });

    function createckeditor() {
        $(".editor").ckeditor();
    }

这对我有用,因为所有的编辑都可以接受销毁和重新创建时,你拖动的东西。它可能被调整为只删除正在拖动的项目。

This worked for me, since it is acceptable for all of the editors to be destroyed and re-created when you drag something. It could probably be tweaked to only remove the item being dragged.

这篇关于CKEditor冻结在jQuery UI重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆