A working CDN config for galetahub/ckeditor which doesn't copy/precompile CKEditor's own assets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/assets.rb | |
# ... | |
# The last two are for the file browser | |
Rails.application.config.assets.precompile += %w(ckeditor/config ckeditor/application ckeditor/filebrowser/*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' %>", | |
# ... | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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