4

I know this question has been asked quite a lot - but all the answers I've found are quite old, and don't seem to work (for me, at least).

I'm using the following code to do a live preview from an input box

$('#attractionName').on('keyup', function() {
    $('#preview-title').html($(this).val());
});

but obviously this doesn't work when using CKEditor. I found this answer on the topic, but it doesn't seem to work for me. My textarea code is

<textarea name="tickets-TicketDescription" class="ckeditor" id="tickets-TicketDescription"></textarea>

Can anyone please can help me figure out where I'm going wrong?

Thanks.

Community
  • 1
  • 1
Dave
  • 498
  • 2
  • 7
  • 22
  • possible duplicate of [add code for event listener for keypress in ckeditor](http://stackoverflow.com/questions/6386423/add-code-for-event-listener-for-keypress-in-ckeditor) – Reinmar Sep 10 '13 at 08:53

1 Answers1

3

The CKEditor has built-in event system. You can add functions on events using "on" property in CKEditor configuration. There is an example for "key" event on CKEditor documentation page: http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-on

  • Actually, the [editor#key](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-key) event is a binding to `keydown`, so it's a little bit different. Here's more adequate way (just replace `click` with `keydown`) http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-contentDom – Reinmar Sep 10 '13 at 07:53
  • Do I place this in `$(document).ready(function()` - or is `editor.on( 'contentDom', function()` replacing that? – Dave Sep 10 '13 at 08:26
  • Good point Reinmar. The "contentDom" event is "Fired when content of the editor (its DOM structure) is ready. (...) It is also a first event fired after CKEDITOR.editable is initialized." - Tthat means you better place that code before the DOM is initialised, not in jQuery.ready(). Just put it somewhere in – Kamil Tunkiewicz Sep 10 '13 at 08:43