When you use multiple instance of CKEditor in the same page, the variable "Drupal.settings.ckeditor.theme" is an Array instead of a String. It seems to be a Bug since the "marinelli" CSS fix is affected. If you try to compare that variable with a String, it will join all elements in the array to make a String with it, so you will get something like "marinelli,marinelli" or "mytheme,mytheme". I wrote a little fix for that:

var themeName = Drupal.settings.ckeditor.theme;
  if (typeof Drupal.settings.ckeditor.theme == "object") {
  themeName = Drupal.settings.ckeditor.theme[0];
}

After that, you can use the themeName variable instead of the String/Array stuff:

if (themeName == "marinelli") {
  config.bodyClass = 'singlepage';
  config.bodyId = 'primary';
}
if (themeName == "mytheme") {
  config.bodyClass = 'singlepage';
  config.bodyId = 'primary';
}

I can submit a patch if you need one.

Comments

gaellafond’s picture

Title: Drupal.settings.ckeditor.theme not a String when using multiple instances » "Drupal.settings.ckeditor.theme" is not a String when using multiple instances
savgoran’s picture

Title: "Drupal.settings.ckeditor.theme" is not a String when using multiple instances » Accessing CKEditor content from Javascript is immposible

Suppose you have form element defined like this:

$form['private_content']['message'] = array(
    '#title' => 'Message',
    '#type' => 'textarea',
    '#description' => 'Enter message.',
    '#rows' => 10,
    '#weight' => 0,
  );
$form['private_content']['format'] = filter_form($node->format);

This will produce following html:

<textarea class="form-textarea resizable textarea-processed" id="edit-message" name="Message" rows="10" cols="60" style=""></textarea>

Take attention on id of this element, it is prefixed with edit-.

When page is loaded, CKEDITOR.instances object will contain edit-message object, firebug can prove it, but that object is inaccessible because object and function names in javascript can contain only alphanumeric and underscores. So, every attempt to write in javascript something like this:

var text = Drupal.wysiwyg.instances.edit-message.getData();

will fail, because object edit-message is undefined.

gaellafond’s picture

Title: Accessing CKEditor content from Javascript is immposible » "Drupal.settings.ckeditor.theme" is not a String when using multiple instances

@savgoran
Thanks for your input, but it seems to be a different issues. I don't know exactly what you are doing, but I think you should try something like this:

var text = CKEDITOR.instances["edit-message"].getData();;

If it doesn't work, feel free to open a new issues for it.

My issues is about having multiple instances of CKEditor in a Node. It cause problems when I try to use the CSS fix (http://drupal.ckeditor.com/tricks).

It should work if I add something like that to ckeditor.config.js

if (Drupal.settings.ckeditor.theme == "mytheme") {
  [...]
}

But, in fact, since I have multiple instance of CKEditor with some nodes, I have to add this as well:

if (Drupal.settings.ckeditor.theme == "mytheme,mytheme") {
  [...]
}

My little fix in the description of the issue can solve that.

dczepierga’s picture

Status: Active » Postponed
Issue tags: +6.x-1.3

I mark is as a fix to next CKEditor module release.

dczepierga’s picture

Status: Postponed » Fixed
Issue tags: -6.x-1.3

I fix it and commit to GIT.

Please check the latest dev release and let me know if you notice any poblems with it. Remember to clear Drupal cache and browsers cache before testing.

Greetings

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.