【问题标题】:Add custom tool bar to CKEditor in rails在rails中将自定义工具栏添加到CKEditor
【发布时间】:2013-06-21 22:04:38
【问题描述】:

我将 CKEditor 与 CKEditor gem (https://github.com/galetahub/ckeditor) 一起使用,并且一切正常,直到我尝试添加自定义工具栏。

我看到的一些帖子建议使用 config.js 文件。但是,按照说明进行设置后,app/assets/javascripts 中没有 /ckeditor/config.js 文件。此外,如果我将 /ckeditor/config.js 添加到 javascripts 目录,文件上传功能将停止工作。即使config.js 是一个空文件,也会发生这种情况。重新启动服务器后,“上传”选项卡将变为隐藏且不起作用。

有没有一种方法可以通用地自定义工具栏?或者即使我可以将选项内联或其他有用的东西配对......

使用 Rails 3.2.11

在我的 Gemfile 中有:

gem "jquery-rails", "~> 2.2.1"
gem "ckeditor"
gem "carrierwave"
gem "mini_magick"
gem "cloudinary"

在 application.rb 我有:

config.autoload_paths += %W(#{config.root}/app/models/ckeditor)

在 application.js 我有:

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require ckeditor/init
//= require_tree ../../../vendor/assets/javascripts/.
//= require_tree .

在我的表格中,我有:

= f.cktext_area :content

我尝试使用的config.js 文件:

CKEDITOR.editorConfig = function( config ) {
  config.toolbar_Custom = [
    { name: 'document',    items : [ 'Source','-','Save','NewPage','DocProps','Preview','-','Templates' ] },
    { name: 'clipboard',   items : [ 'PasteFromWord','-','Undo','Redo' ] },
    { name: 'insert',      items : [ 'Image','Table','HorizontalRule','SpecialChar','PageBreak' ] },
    { name: 'tools',       items : [ 'Maximize', 'ShowBlocks','-','About' ] },
    '/',
    { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
    { name: 'paragraph',   items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
    { name: 'links',       items : [ 'Link','Unlink','Anchor' ] },
    '/',
    { name: 'styles',      items : [ 'Styles','Format','Font','FontSize' ] },
    { name: 'colors',      items : [ 'TextColor','BGColor' ] }
  ];

  config.toolbar = 'Custom';
};

【问题讨论】:

    标签: javascript ruby-on-rails ckeditor


    【解决方案1】:

    您必须手动创建自己的 config.js 文件。要保留 Upload 选项卡,请在 ckeditor gem repo 上关注此问题,其中说明了如何解决它:

    https://github.com/galetahub/ckeditor/issues/238

    只需将文件浏览器的引用配置 javascript 粘贴到您的 config.js 文件中,上传选项卡就会返回完整功能。

    【讨论】:

      猜你喜欢
      • 2022-01-19
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多