Changed TinyMCE init to run only on demand. Highly experimental.
authorDan
Wed, 05 Mar 2008 23:10:26 -0500
changeset 474 3d751a6f2b05
parent 473 518bc2b214f1
child 475 51386f1852b8
Changed TinyMCE init to run only on demand. Highly experimental.
includes/clientside/static/dynano.js
includes/clientside/static/editor.js
--- a/includes/clientside/static/dynano.js	Sun Mar 02 22:52:23 2008 -0500
+++ b/includes/clientside/static/dynano.js	Wed Mar 05 23:10:26 2008 -0500
@@ -89,21 +89,30 @@
 
 function DN_switchToMCE(performWikiTransform)
 {
-  //if ( this.object.dn_is_mce )
-  //  return this;
   if ( !this.object.id )
     this.object.id = 'textarea_' + Math.floor(Math.random() * 1000000);
   if ( !this.object.name )
     this.object.name = 'textarea_' + Math.floor(Math.random() * 1000000);
-  // TinyMCE 2.x
-  // tinyMCE.addMCEControl(this.object, this.object.name, document);
-  // TinyMCE 3.x
+  // Updated for TinyMCE 3.x
   if ( performWikiTransform )
   {
     this.object.value = DN_WikitextToXHTML(this.object.value);
   }
-  tinyMCE.execCommand("mceAddControl", true, this.object.id);
-  this.object.dnIsMCE = 'yes';
+  // If tinyMCE init hasn't been called yet, do it now.
+  if ( !tinymce_initted )
+  {
+    enano_tinymce_options.mode = 'exact';
+    enano_tinymce_options.elements = this.object.name;
+    console.debug(enano_tinymce_options);
+    initTinyMCE();
+    this.object.dnIsMCE = 'yes';
+    return true;
+  }
+  else
+  {
+    tinyMCE.execCommand("mceAddControl", true, this.object.id);
+    this.object.dnIsMCE = 'yes';
+  }
   return this;
 }
 
--- a/includes/clientside/static/editor.js	Sun Mar 02 22:52:23 2008 -0500
+++ b/includes/clientside/static/editor.js	Wed Mar 05 23:10:26 2008 -0500
@@ -16,6 +16,7 @@
 // Idle time required for autosave, in seconds
 var AUTOSAVE_TIMEOUT = 15;
 var AutosaveTimeoutObj = null;
+var tinymce_initted = false;
 
 var enano_tinymce_options = {
   mode : "none",
@@ -35,7 +36,7 @@
 };
 
 // Check tinyMCE to make sure its init is finished
-function tinymce_init_check()
+function tinymce_preinit_check()
 {
   if ( typeof(tinyMCE.init) != 'function' )
     return false;
@@ -52,16 +53,17 @@
   {
     if ( !KILL_SWITCH && !DISABLE_MCE )
     {
-      if ( !tinymce_init_check() )
+      if ( !tinymce_preinit_check() && !force )
       {
-        setTimeout('initTinyMCE();', 200);
+        setTimeout('initTinyMCE(false);', 200);
         return false;
       }
       tinyMCE.init(enano_tinymce_options);
+      tinymce_initted = true;
     }
   }
 }
-addOnloadHook(initTinyMCE);
+// addOnloadHook(initTinyMCE);
 
 var editor_open = false;
 
@@ -515,14 +517,15 @@
     textarea.setAttribute('readonly', 'readonly');
   }
   
+  $dynano('ajaxEditArea').object.focus();
+  $dynano('ajaxEditArea').object._edTimestamp = timestamp;
+  $dynano('ajaxEditArea').setContent(content);
+  
   // If the editor preference is tinymce, switch the editor to TinyMCE now
   if ( readCookie('enano_editor_mode') == 'tinymce' && allow_wysiwyg )
   {
     $dynano('ajaxEditArea').switchToMCE();
   }
-  $dynano('ajaxEditArea').object.focus();
-  $dynano('ajaxEditArea').object._edTimestamp = timestamp;
-  $dynano('ajaxEditArea').setContent(content);
   
   if ( allow_wysiwyg )
   {