PerfectlyNormal / tinymce-rails-imageupload

Image upload plugin for TinyMCE and Rails with the asset pipeline
MIT License
149 stars 153 forks source link

Error on Firefox Mac when opening the dialog #30

Closed pomartel closed 11 years ago

pomartel commented 11 years ago

I get this error when opening the dialog with the latest Firefox version on Mac OSX :

http://screencast.com/t/z9ezp00T

From what I can tell, the handleResponse method gets called when the iframe loads and a JSON parsing error occurs since the ret variable is null.

I think the same error also occurs in IE. It works fine in Chrome.

PerfectlyNormal commented 11 years ago

Yes, indeed. Looks like Firefox loads "about:blank" in the iframe, and then triggers uploadDone, which attempts to parse it as JSON in handleResponse.

I moved the event initialization

if(this.iframe.attachEvent)
  this.iframe.attachEvent('onload', UploadImageDialog.uploadDone);
else
  this.iframe.addEventListener('load', UploadImageDialog.uploadDone, false);

from the bottom of init to the top of insert and that made the error go away in Firefox and IE. IE still chokes when attaching anything real, but my test in Firefox works.

PerfectlyNormal commented 11 years ago

Also, since insert might be called several times (no file selected, error from server, …), we should probably make sure only one event handler gets attached, to avoid uploadDone being called multiple times, which some browser probably would do, and make a mess

pomartel commented 11 years ago

Yes, that's a good point. Maybe you could trying detaching the event before attaching it so it doesn't get attached twice? I'm really clueless since I usually rely on jquery for all the event binding magic!

PerfectlyNormal commented 11 years ago

Does the browser-compatibility branch help fix this? Looks like IE9 works as well, just had to really force it to clear the cache

pomartel commented 11 years ago

Yes, the Firefox bug is fixed for me too! Thanks!