Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript TinyMCE/jQuery race condition on firefox
    primarykey
    data
    text
    <p>I have a website with a form that uses TinyMCE; independently, I use jQuery. When I load the form from staging server on Firefox 3 (MacOS X, Linux), TinyMCE doesn't finish loading. There is an error in Firefox console, saying that <code>t.getBody()</code> returned <code>null</code>. <code>t.getBody()</code>, as far as I understand from TinyMCE docs, is a function that returns document's body element to be inspected for some features. Problem doesn't occur when I use Safari, nor when I use Firefox with the same site running from localhost.</p> <p>Original, failing JavaScript-related code looked like this:</p> <pre><code>&lt;script type="text/javascript" src="http://static.alfa.foo.pl/json2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://static.alfa.foo.pl/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://static.alfa.foo.pl/jquery.ui.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://static.alfa.foo.pl/tiny_mce/tiny_mce.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; tinyMCE.init({ mode:"specific_textareas", editor_selector:"mce", theme:"simple", language:"pl" }); &lt;/script&gt; &lt;script type="text/javascript" src="http://static.alfa.foo.pl/jquery.jeditable.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://static.alfa.foo.pl/jquery.tinymce.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" charset="utf-8" src="http://static.alfa.foo.pl/foo.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ /* jQuery initialization */ }); &lt;/script&gt; </code></pre> <p>I tried changing script loading order, moving <code>tinyMCE.init()<code> call to the <code>&lt;script/&gt;</code> tag containing <code>$(document).ready()</code> call—before, after, and inside this call. No result. When <code>tinyMCE.init()<code> was called from within <code>$(document).ready()</code> handler, the browser did hang on request—looks like it was too late to call the init function.</p> <p>Then, after googling a bit about using TinyMCE together with jQuery, I changed <code>tinyMCE.init()</code> call to:</p> <pre><code>tinyMCE.init({ mode:"none", theme:"simple", language:"pl" }); </code></pre> <p>and added following jQuery call to the <code>$(document).ready()</code> handler:</p> <pre><code>$(".mce").each( function(i) { tinyMCE.execCommand("mceAddControl",true,this.id); }); </code></pre> <p>Still the same error. But, and here's where things start to look like real voodoo, when I added alert(i);</code> before the tinyMCE.execCommand()</code> call, alerts were given, and TinyMCE textareas were initialized correctly. I figured this can be a matter of delay introduced by waiting for user dismissing the alert, so I introduced a second of delay by changing the call, still within the $(document).ready()</code> handler, to following:</p> <pre>setTimeout('$(".mce").each( function(i) { tinyMCE.execCommand("mceAddControl",true,this.id); });',1000); </code></pre> <p>With the timeout, TinyMCE textareas initialize correctly, but it's duct taping around the real problem. The problem looks like an evident race condition (especially when I consider that on the same browser, but when server is on localhost, problem doesn't occur). But isn't JavaScript execution single-threaded? Could anybody please enlighten me as to what's going on here, where is the actual problem, and what can I do to have it actually fixed?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload