initialize = ->
$inputs = $('textarea.effective_ckeditor_text_area:not(.initialized)')
setupCkeditor($inputs)
$inputs.each (i, element) ->
element = $(element)
element.addClass('initialized')
initCkeditor(element)
# This is a one-time initialization that is done to check that all the scripts are properly set up
setupCkeditor = ($inputs) ->
return unless $inputs.length > 0
ckeditor_present = ((try CKEDITOR.version) || '').length > 0
use_effective_assets = ($inputs.first().data('input-js-options') || {})['effective_assets'] == true
$head = $('head')
unless ckeditor_present
$head.append("")
$head.append("")
if use_effective_assets
$head.append("
");
initCkeditor = (textarea) ->
CKEDITOR.replace(textarea.attr('id'),
toolbar: 'full'
effectiveRegionType: 'full'
customConfig: ''
enterMode: CKEDITOR.ENTER_P
shiftEnterMode: CKEDITOR.ENTER_BR
startupOutlineBlocks: false
startupShowBorders: true
disableNativeTableHandles: true
extraPlugins: 'effective_regions,effective_assets'
removePlugins: 'elementspath'
format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;div'
templates: 'effective_regions'
templates_files: []
templates_replaceContent: false
filebrowserWindowHeight: 600
filebrowserWindowWidth: 800
filebrowserBrowseUrl: '/effective/assets?only=images'
toolbar_full: [
{ name: 'save', items: ['NewPage'] },
{ name: 'html', items: ['Sourcedialog', '-', 'ShowBlocks'] },
{ name: 'editing', items: ['Undo', 'Redo'] },
{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'] },
{ name: 'justify', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight']}
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] },
'/',
{ name: 'definedstyles', items: ['Format'] },
{ name: 'links', items: ['Link', 'Unlink', '-', 'Anchor'] },
{ name: 'insert', items: ['Image', 'oembed', 'EffectiveAssets'] },
{ name: 'lists', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'] },
{ name: 'insert2', items: ['Table', 'EffectiveReferences', 'Blockquote', 'HorizontalRule', 'PageBreak'] }
]
)
$ -> initialize()
$(document).on 'page:change', -> initialize()
$(document).on 'cocoon:after-insert', -> initialize()