如何用Javascript加载CKEditor? [英] How do I load CKEditor with Javascript?

查看:90
本文介绍了如何用Javascript加载CKEditor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将CKEditor集成到我的博客评论系统中,并且在加载新页面时可以正常显示。

I have integrated CKEditor into my commenting system for my blog, and it shows up fine when I load a new page.

但是,对于回复评论,我有一个javascript操作,可从每个评论下方的回复此评论链接中打开一个新评论表单。在这种情况下,不会加载CKEditor(我只是得到了一个基本的非CKEditor文本区域)。我需要添加一些内容到我的javascript文件中,以便CKeditor正确加载吗?

However, for reply comments, I have a javascript action that opens a new comment form from a "reply to this comment" link below each comment. In this case, the CKEditor doesn't load (I just get a basic non-CKEditor text-area). Do I need to add something to my javascript file so that the CKeditor loads correctly?

posts / show.html.erb

<%= @post.content %>
<%= render 'comments/form' %> #this CKEditor form renders fine when the page loads
<%= @post.comments %>

comments / _form.html.erb

<%= simple_form_for(@comment, remote: true) do |f| %>
  <%= f.hidden_field :parent_id %>
  <%= f.cktext_area :content, :input_html => { :ckeditor => { :toolbar => 'Basic' } }, :class => "comment_input" %>
<%= f.button :submit %>

comments / new.js.erb

$('#comment_<%= @comment.parent.id %>').append("<%= escape_javascript(render 'form') %>");

comments / _comment.html.erb

<div id="comment_<%= comment.id %>">
  <%= comment.content.try(:html_safe) %>
  <%= link_to "reply to this comment", new_comment_path(:parent_id => comment), remote: true %>
</div>


推荐答案

您必须创建新的Editor实例。在comments / new.js.erb中附加表格后:

You have to create new instance of editor. After appending form in comments/new.js.erb:

CKEDITOR.replace('id_of_textarea',{
    :toolbar => 'Basic'
});

我不确定是否可以使用任何选择器代替 id_of_textarea。如果不是,则textarea必须具有唯一的ID。
还有另一种方法来创建编辑器实例,但是我没有尝试过我自己

I'm not sure is it possible to use any selector instead of 'id_of_textarea'. If not then textarea must have unique id. There is also another way to create editor instances but I have not tried it myself

这篇关于如何用Javascript加载CKEditor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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