Tuesday, March 22, 2016

turbolinks 5 and ckeditor

turbolinks 5 gives some pretty neat features.
it no longer needs turbolinks-jquery.

but in some way, it doesnt work properly due to cache within turbolinks.
a work around this issue would be calling:

#coffeescripts:
jQuery(document).on('turbolinks:load', (e)->
    #do your initialize here
    if Turbolinks
        Turbolinks.Cache()
)

calling turbolinks cache helps to keep the rendered form intact.
but for some reason, this doesn't work with ckeditor.

the work around is to add this in the turbolinks:load function

$('textarea.ckeditor').each(->
    if $(this).css('visibility') != 'hidden'
      # console.log(this)
      CKEDITOR.replace(this)
  )

hope it helps :)