Index: wysiwyg.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.js,v
retrieving revision 1.22
diff -u -p -r1.22 wysiwyg.js
--- wysiwyg.js	6 Jan 2011 00:11:48 -0000	1.22
+++ wysiwyg.js	23 Jan 2011 03:43:59 -0000
@@ -46,11 +46,11 @@ Drupal.behaviors.attachWysiwyg = {
     }
 
     $('.wysiwyg', context).once('wysiwyg', function() {
-      if (!this.id || typeof Drupal.settings.wysiwyg.triggers[this.id] === 'undefined') {
+      if (!this.id || typeof settings.wysiwyg.triggers[this.id] === 'undefined') {
         return;
       }
       var $this = $(this);
-      var params = Drupal.settings.wysiwyg.triggers[this.id];
+      var params = settings.wysiwyg.triggers[this.id];
       for (var format in params) {
         params[format].format = format;
         params[format].trigger = this.id;
@@ -60,7 +60,7 @@ Drupal.behaviors.attachWysiwyg = {
       // Directly attach this editor, if the input format is enabled or there is
       // only one input format at all.
       if ($this.is(':input')) {
-        Drupal.wysiwygAttach(context, params[format]);
+        Drupal.wysiwygAttach(context, params[format], settings);
       }
       // Attach onChange handlers to input format selector elements.
       if ($this.is('select')) {
@@ -68,7 +68,7 @@ Drupal.behaviors.attachWysiwyg = {
           // If not disabled, detach the current and attach a new editor.
           Drupal.wysiwygDetach(context, params[format]);
           format = 'format' + this.value;
-          Drupal.wysiwygAttach(context, params[format]);
+          Drupal.wysiwygAttach(context, params[format], settings);
         });
       }
       // Detach any editor when the containing form is submitted.
@@ -96,7 +96,9 @@ Drupal.behaviors.attachWysiwyg = {
  * @param params
  *   An object containing input format parameters.
  */
-Drupal.wysiwygAttach = function(context, params) {
+Drupal.wysiwygAttach = function(context, params, settings) {
+  $.debug(params, 'wysiwygAttach');
+  $.debug(Drupal.wysiwyg.editor.attach);
   if (typeof Drupal.wysiwyg.editor.attach[params.editor] == 'function') {
     // (Re-)initialize field instance.
     Drupal.wysiwyg.instances[params.field] = {};
@@ -118,6 +120,8 @@ Drupal.wysiwygAttach = function(context,
     else {
       $('#wysiwyg-toggle-' + params.field).hide();
     }
+    $.debug(params);
+    $.debug(settings.wysiwyg.configs[params.editor]);
     // Attach editor, if enabled by default or last state was enabled.
     if (params.status) {
       Drupal.wysiwyg.editor.attach[params.editor](context, params, (Drupal.settings.wysiwyg.configs[params.editor] ? jQuery.extend(true, {}, Drupal.settings.wysiwyg.configs[params.editor][params.format]) : {}));
@@ -139,6 +143,9 @@ Drupal.wysiwygAttach = function(context,
  *   An object containing input format parameters.
  */
 Drupal.wysiwygDetach = function(context, params) {
+  if (typeof Drupal.wysiwyg.instances[params.field] == 'undefined') {
+    return;
+  }
   var editor = Drupal.wysiwyg.instances[params.field].editor;
   if (jQuery.isFunction(Drupal.wysiwyg.editor.detach[editor])) {
     Drupal.wysiwyg.editor.detach[editor](context, params);
Index: wysiwyg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.module,v
retrieving revision 1.53
diff -u -p -r1.53 wysiwyg.module
--- wysiwyg.module	23 Jan 2011 01:58:34 -0000	1.53
+++ wysiwyg.module	23 Jan 2011 03:41:37 -0000
@@ -365,7 +365,7 @@ function wysiwyg_load_editor($profile) {
 
     // The 'none' editor is a special editor implementation, allowing us to
     // attach and detach regular Drupal behaviors just like any other editor.
-    drupal_add_js($path . '/editors/js/none.js');
+    #drupal_add_js($path . '/editors/js/none.js');
 
     // Add wysiwyg.js to the footer to ensure it's executed after the
     // Drupal.settings array has been rendered and populated. Also, since editor
Index: editors/js/ckeditor-3.0.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/js/ckeditor-3.0.js,v
retrieving revision 1.11
diff -u -p -r1.11 ckeditor-3.0.js
--- editors/js/ckeditor-3.0.js	29 Dec 2010 20:02:10 -0000	1.11
+++ editors/js/ckeditor-3.0.js	23 Jan 2011 04:17:01 -0000
@@ -2,6 +2,12 @@
 (function($) {
 
 Drupal.wysiwyg.editor.init.ckeditor = function(settings) {
+  $.debug('inited');
+  $.debug(settings);
+  window.CKEDITOR_BASEPATH = settings.global.editorBasePath + '/';
+  CKEDITOR.basePath = window.CKEDITOR_BASEPATH;
+//  Drupal.wysiwyg.editor['initialized']['ckeditor'] = true;
+
   // Plugins must only be loaded once. Only the settings from the first format
   // will be used but they're identical anyway.
   var registeredPlugins = {};
@@ -32,6 +38,11 @@ Drupal.wysiwyg.editor.init.ckeditor = fu
  * Attach this editor to a target element.
  */
 Drupal.wysiwyg.editor.attach.ckeditor = function(context, params, settings) {
+  $.debug('attach');
+//  if (typeof Drupal.wysiwyg.editor.initialized.ckeditor == 'undefined') {
+//    Drupal.wysiwyg.editor.init.ckeditor(settings);
+//  }
+
   // Apply editor instance settings.
   CKEDITOR.config.customConfig = '';
 
Index: editors/js/none.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/js/none.js,v
retrieving revision 1.8
diff -u -p -r1.8 none.js
--- editors/js/none.js	20 Mar 2010 14:54:29 -0000	1.8
+++ editors/js/none.js	23 Jan 2011 03:14:31 -0000
@@ -15,6 +15,7 @@
  *   An object containing editor settings for all enabled editor themes.
  */
 Drupal.wysiwyg.editor.attach.none = function(context, params, settings) {
+  $.debug('attach.none');
   if (params.resizable) {
     var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first');
     $wrapper.addClass('resizable');
Index: tests/wysiwyg_test.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/tests/wysiwyg_test.module,v
retrieving revision 1.1
diff -u -p -r1.1 wysiwyg_test.module
--- tests/wysiwyg_test.module	23 Jan 2011 01:58:34 -0000	1.1
+++ tests/wysiwyg_test.module	23 Jan 2011 02:14:54 -0000
@@ -6,3 +6,47 @@
  * Testing functionality for Wysiwyg module.
  */
 
+/**
+ * Implements hook_menu().
+ */
+function wysiwyg_test_menu() {
+  $items['wysiwyg-test/ajax'] = array(
+    'title' => 'Ajaxified form',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('wysiwyg_test_ajax_form'),
+    'access callback' => TRUE,
+  );
+  return $items;
+}
+
+/**
+ * Form constructor for an ajaxified form lazy-loading a textarea.
+ */
+function wysiwyg_test_ajax_form($form, &$form_state) {
+  $form['enable'] = array(
+    '#type' => 'checkbox',
+    '#title' => 'Load textarea',
+    '#ajax' => array(
+      'callback' => 'wysiwyg_test_ajax_form_callback',
+      'wrapper' => 'ajax-wrapper',
+    ),
+  );
+  $form['wrapper'] = array(
+    '#type' => 'container',
+    '#id' => 'ajax-wrapper',
+  );
+  return $form;
+}
+
+/**
+ * #ajax callback for wysiwyg_test_ajax_form().
+ */
+function wysiwyg_test_ajax_form_callback($form, &$form_state) {
+  $form['body'] = array(
+    '#type' => 'text_format',
+    '#default_value' => '',
+  );
+  form_builder($form['form_id']['#value'], $form, $form_state);
+  return $form['body'];
+}
+
