stephenmcd/filebrowser-safe — pull request #23 by excieve (2013-07-05 17:58:34+00:00)
Title: Refactored filebrowser-popup.js to use iframe

Generic filebrowser popup is currently the only way to insert files in a 3rd party editor but it's not quite there to be usable.

The current state of generic filebrowser popup is that it loads full filebrowser page (including `` and ``) into another page that calls it and makes a dialog out of it. This isn't exactly a great idea as it isn't valid HTML, it's just that browsers don't happen to choke on it in certain fortunate settings. Besides, it loads all the CSS and JS from filebrowser page which renders things unusable:
* If you try calling this popup in Django admin it will break all jQ plugins (due to jQ being loaded the second time)
* On Mezzanine's default frontend (by loading in inline editor) it will mess up styles and jQ plugins as well. Obviously, this doesn't apply to default theme solely but to any other custom theme that might collide as well.

This kind of stuff is what iframe element is there for. Unless there's some very peculiar reason not to use it, I've no idea why this was done in such a way, which also imposes limits on what can be done inside that popup and implements its own navigation. This should be completely unnecessary.

So my change basically rewrites generic popup functionality to load filebrowser page dynamically into an iframe and removes limitations on uploading and deleting files in the popup. Also removes ajax navigation code from the popup as browser will be able to do it on it's own now.

Additionally cleaned up the code a little bit and replaced hardcoded filebrowser URL with `window.__filebrowser_url`.

This has been tested on Firefox and Chromium, but should also work everywhere else.