tags:

views:

743

answers:

3

I'm having a problem with TinyMCE and Django. I'm using the TinyMCE module for basic Form field support.

The problem comes when TinyMCE wants to use a popup:

In my development environment, static pages are served from

static.wdw.ms.local:8888

and Django pages are served from wdw.ms.local:8000

(In production, the .local:XXXX is dropped)

If I click on the edit in html button, (or spellcheck, or anything that has a popup), the popup fails. Firebug tells me that "tinymce." is null (the tinymce object)

I've edited the tiny_mce_popup.js and have tried these settings

document.domain = 'wdw.ms.local:8000'; as well as 'wdw.ms.local', 'static.wdw.ms.local', 'static.wdw.ms:8888'

They all give this error (as seen in Firebug):

Permission denied for <http://wdw.ms.local:8000&gt; to get property Window.tinymce from     <http://wdw.ms.local:8000&gt;.
[Break on this error] var tinymce=null,tinyMCEPopup,tinyMCE;ti...nyMCEPopup.init();    
tinyMCEPopup._wait();\ntiny_mce_popup.js (line 5)

Any ideas on how to get this to work?

(Similar questions have been asked here before, but all the solutions involved changing that document.domain setting, which doesn't work for me. If you look in the comments on these similar questions, you'll notice that many other people have been unable to get this to work)

A: 

For the development server, you have to serve static content on the same domain (wdw.ms.local) as your django pages if you want tinymce to work (I had a similar problem with another JS library that creates popup windows called greybox). Use something like this in url.py:

(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/static'}),
Gabriel Ross
But how is this possible if, for development, I use the django development server, but use a local Apache to serve the static content? Do I need to use the django dev server to serve the static content to make this work? (Which causes its own problems because of its single-threadedness, etc)
ראובן
It's a security thing, the browser won't allow it. You're not allowed to open a windows or iframe whose address is on a different domain.
Gabriel Ross
Yes, the django server has to serve the static content.
Gabriel Ross
A: 

Add it to before the tinyMCE.init call on your page:

document.domain = 'mydomain.com';
tinyMCE.init({
   ...
});

And then change the value in: tiny_mce_popup.js to:

document.domain = 'mydomain.com';

Note: this solution works for me with a Django website.

Reference: http://wiki.moxiecode.com/index.php/TinyMCE%3ACross%5Fdomain%5Floading

semente
A: 

Change the document.domain setting will only work if you're using subdomains, not different root domains or different ports. So server1.mydomain.com and server2.mydomain.com can be used if you set document.domain to mydomain.com but you can't ever get server1.com and server2.com to work together, similarly you can't get mydomain.com:8888 and mydomain.com:8000 to work together.

What you can do though, is use mod_proxy with Apache to forward specific requests over to the django development server while serving other requests directly. This could be done with name based virtual hosts so that you can then use the same port but map two subdomains onto the same domain, or even just redirect/don't redirect specific directories.

The definitive reference on mod_proxy is http://httpd.apache.org/docs/2.0/mod/mod_proxy.html but I've also written up how I was using mod_proxy to pass some but not all requests on from Apache to IBM Portal at http://www.symphonious.net/2008/07/08/creating-clean-urls-with-ibm-wcm/ (it includes some URL rewriting stuff that hopefully you won't need).

Regards,

Adrian Sutton
http://tinymce.ephox.com

ajsutton