/* makes sure javascript loading is not interrupted by ckeditor jquery adapter
 * throwing an error about the environment being incompatible. */
CKEDITOR.env.origIsCompatible = CKEDITOR.env.isCompatible;
CKEDITOR.env.isCompatible = true;

$(document).ready( function() {
  if (CKEDITOR.env.origIsCompatible == false) {
    /* bail out if ckeditor advertised itself as not supported */
    return;
  }
  if (typeof($().ckeditor) === 'undefined') {
    /* the jquery adapter couldn't be loaded, don't bother failing further down */
    return;
  }
  $('div.WysiwygTextWidget textarea').each(function(idx, textarea) {
    var config = $(textarea).data('config');
    $(textarea).ckeditor(config);
  });
  $(document).on('wcs:dialog-loaded', function(e, dialog) {
    var $textarea = $(dialog).find('div.WysiwygTextWidget textarea');
    $textarea.ckeditor($textarea.data('config'));
  });
});
