Skip to content

Instantly share code, notes, and snippets.

@halilim
Created January 16, 2016 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halilim/ddae5f77aea52f7d98fd to your computer and use it in GitHub Desktop.
Save halilim/ddae5f77aea52f7d98fd to your computer and use it in GitHub Desktop.
A working CDN config for galetahub/ckeditor which doesn't copy/precompile CKEditor's own assets.
# config/initializers/assets.rb
# ...
# The last two are for the file browser
Rails.application.config.assets.precompile += %w(ckeditor/config ckeditor/application ckeditor/filebrowser/*)
# app/assets/javascripts/ckeditor.coffee.erb
# Another option is including these directly in your relevant views:
# = javascript_include_tag Ckeditor.cdn_url
# = javascript_include_tag 'ckeditor/config'
# I've chosen to implement the whole thing in JS. Going this route,
# you might experience some FOUC. If that's an issue for you, usual FOUC
# workarounds apply, e.g. you can block the relevant textareas with a
# loading animation or something.
$ = jQuery
# https://api.jquery.com/jquery.getscript/#entry-examples
jQuery.cachedScript = (url, options) ->
# Allow user to set any option except for dataType, cache, and url
options = $.extend(options or {},
dataType: 'script'
cache: true
url: url)
# Use $.ajax() since it is more flexible than $.getScript
# Return the jqXHR object so we can chain callbacks
jQuery.ajax options
$ ->
$editors = $("textarea.html-editor")
if $editors.length
$.cachedScript("<%= Ckeditor.cdn_url %>").done ->
$editors.each ->
CKEDITOR.replace(this, {
customConfig: "<%= javascript_path 'ckeditor/config' %>",
# ...
})
# config/initializers/ckeditor.rb
Ckeditor.setup do |config|
# ...
config.cdn_url = '//cdn.ckeditor.com/4.5.6/standard/ckeditor.js'
config.run_on_precompile = false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment