Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom tool bar to CKEditor in rails

I'm using CKEditor with the CKEditor gem (https://github.com/galetahub/ckeditor) and everything is working correctly, until I try to add a custom tool bar.

Some posts I've seen suggest using a config.js file. However, with the setup per the instructions, there is no /ckeditor/config.js file in app/assets/javascripts. Additionally, if I add /ckeditor/config.js to the javascripts directory, the file upload functionality stops working. This happens even if config.js is an empty file. The "Upload" tab becomes hidden and non-functional with a reboot of the server.

Is there a way I can universally customize the tool bar? Or even if I can just pair down the options inline or something that would be helpful...

Using Rails 3.2.11

In my Gemfile I have:

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

In application.rb I have:

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

In application.js I have:

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

In my form I have:

= f.cktext_area :content

config.js file I attempted to use:

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';
};
like image 289
Eric Norcross Avatar asked Jun 21 '13 22:06

Eric Norcross


1 Answers

You have to create your own config.js file manually. To preserve the Upload tab, follow this issue on the ckeditor gem repo, which explains how to solve it:

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

Just paste the referenced config javascript for the filebrowser into your config.js file and the Upload tab will return with full functionality.

like image 108
Robert Strohmeyer Avatar answered Sep 20 '22 23:09

Robert Strohmeyer