CKEditor 在 jQuery UI 重新排序上冻结
我正在尝试使用 jQuery UI 框架重新排序动态创建的 CKEditors 列表,但我遇到了编辑器释放问题。当我刚刚使用
这是 Javascript 代码:
$(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>
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.
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();
}
This is the HTML code:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尽管并不理想,但我找到了一个潜在的解决方案:
这对我有用,因为当您拖动某些内容时,所有编辑器都被销毁并重新创建是可以接受的。它可能会被调整为仅删除被拖动的项目。
Though not ideal, I have found a potential solution:
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)时,我发现如果您将数据强制返回编辑器,它会重新加载,就好像它没有一样感动。使用“ckedname”(或“CK 编辑器名称”)以便找到正确的 CKEditor 实例。假设您在单个页面上有多个可能已动态放置的编辑器。当然,如果您知道编辑器的实例名称,则可以跳过“start”和“stop”回调闭包中的前三行。 (注意:我的“textcontainer”是包含CKEditor的div类)
I came across this problem and fixed it with somewhat of a hack - here goes:
When using these two together (sortable and ckeditor), I discovered that if you force the data back into the editor, it gets reloaded as though it weren't touched. The "ckedname" (or "CK Editor Name") was used so that the proper CKEditor instance was located. The assumption is that you have multiple editors on a single page that may have been dynamically placed. Of course, if you know the instance names of your editors, you can skip the first three lines in both the "start" and "stop" callback closures. (Note: my "textcontainer" is the div class that contains the CKEditor)
好吧,我有另一个解决方案,即在拖动之前将编辑器的内容放入 div 中,然后在停止后将其放回编辑器中。
这样排序后就不需要实例化编辑器了。
这里 attribute_text 是给定 textara 的类名,它可以在可排序中拖动并存在于 .attribute_div 中
attribute_val是隐藏元素的类名,用于存储编辑器的内容。
Well i have another solutions which is about putting the contents of the editor in a div before drag and then after it stops, put it back in editor.
This way no need to instantiate the editor after sorting.
here attribute_text is the class name given the textara which is draggable inside the sortable and present inside .attribute_div
attribute_val is the class name of hidden element which is used to store the content of editor.
我遇到了同样的问题,尝试在完成重新排序后调用 ckeditor 的 init 函数。
i had the same problem, try calling the init function of ckeditor after you completed the reorder thing.
我在使用 CKEditor 和 jQuery UI Sortable 时遇到了类似的问题。就我而言,如果我同时使用两者,CKEditor 将完全没有响应。我可以使
内联编辑的唯一方法是单击 Control + 我要尝试编辑的
。
为了使这两项工作正常进行,我使用了 a
< ;span>
包含要排序的向上/向下拖动图像:I had a similar issue when using CKEditor and jQuery UI Sortable. In my case, if I was using both at the same time, CKEditor would be completely unresponsive. The only way I could make the
<div>
inline editable was by clicking Control + the<div>
that I would try to edit.To make both work, I used a
<span>
that contains an up/down drag image to sort: