Skip to content

Commit

Permalink
Added the ability to do codemirror true on a text field and have a co…
Browse files Browse the repository at this point in the history
…demirror.js instances how up. Also added custom install location options for CKEDITOR

forgot to add in codemirror commits"
  • Loading branch information
rovermicrover committed May 26, 2012
1 parent 8d7d7bc commit 61a7e0e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
14 changes: 13 additions & 1 deletion app/assets/javascripts/rails_admin/ra.widgets.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,23 @@ $(document).live 'rails_admin.dom_ready', ->
# ckeditor

$('form [data-richtext=ckeditor]').not('.ckeditored').each ->
window.CKEDITOR_BASEPATH = '/assets/ckeditor/'
options = $(this).data('options')
window.CKEDITOR_BASEPATH = options['base_location']
if not window.CKEDITOR
$(window.document).append('<script src="' + options['jspath'] + '"><\/script>')
if instance = window.CKEDITOR.instances[this.id]
instance.destroy(true)
window.CKEDITOR.replace(this, options['options'])
$(this).addClass('ckeditored')

#codemirror

$('form [data-richtext=codemirror]').not('.codemirrored').each ->
options = $(this).data('options')
if not window.CodeMirror
$(window.document).append('<script src="' + options['jspath'] + '" type="text\/javascript"><\/script>')
$('head').append('<script src="' + options['locations']['mode'] + '" type="text\/javascript"><\/script>')
$('head').append('<link href="' + options['csspath'] + '" rel="stylesheet" media="all" type="text\/css">')
$('head').append('<link href="' + options['locations']['theme'] + '" rel="stylesheet" media="all" type="text\/css">')
CodeMirror.fromTextArea(this,{mode:options['options']['mode'],theme:options['options']['theme']})
$(this).addClass('codemirrored')
1 change: 0 additions & 1 deletion app/assets/stylesheets/rails_admin/imports.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@import "bootstrap/grid";
@import "bootstrap/layouts";
@import "bootstrap/type";
@import "bootstrap/code";
@import "bootstrap/forms";
@import "bootstrap/tables";
@import "bootstrap/sprites";
Expand Down
11 changes: 10 additions & 1 deletion app/views/rails_admin/main/_form_text.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
if field.ckeditor
richtext = 'ckeditor'
js_data = {
:jspath => '/assets/ckeditor/ckeditor.js',
:jspath => field.ckeditor_location,
:base_location => field.ckeditor_base_location,
:options => {
:customConfig => field.ckeditor_config_js
}
}
elsif field.codemirror
richtext = 'codemirror'
js_data = {
:csspath => field.codemirror_css_location,
:jspath => field.codemirror_js_location,
:options => field.codemirror_config,
:locations => field.codemirror_assets
}
else
richtext = false
js_data = {}
Expand Down
41 changes: 41 additions & 0 deletions lib/rails_admin/config/fields/types/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,47 @@ class Text < RailsAdmin::Config::Fields::Base
"/assets/ckeditor/config.js"
end

#Use this if you want to point to a cloud instances of CKeditor
register_instance_option(:ckeditor_location) do
'/assets/ckeditor/ckeditor.js'
end

#Use this if you want to point to a cloud instances of the base CKeditor
register_instance_option(:ckeditor_base_location) do
'/assets/ckeditor/'
end

# Codemirror is disabled by default and CKEditor takes precedence
register_instance_option(:codemirror) do
false
end

#Pass the theme and mode for Codemirror
register_instance_option(:codemirror_config) do
{
:mode => 'css',
:theme => 'night'
}
end

#Pass the location of the theme and mode for Codemirror
register_instance_option(:codemirror_assets) do
{
:mode => '/assets/codemirror/modes/css.js',
:theme => '/assets/codemirror/themes/night.css'
}
end

#Use this if you want to point to a cloud instances of CodeMirror
register_instance_option(:codemirror_js_location) do
'/assets/codemirror.js'
end

#Use this if you want to point to a cloud instances of CodeMirror
register_instance_option(:codemirror_css_location) do
'/assets/codemirror.css'
end

register_instance_option(:html_attributes) do
{
:cols => "48",
Expand Down

0 comments on commit 61a7e0e

Please sign in to comment.