- Author:
 - jonasvp
 - Posted:
 - November 18, 2008
 - Language:
 - JavaScript
 - Version:
 - Not specified
 - Score:
 - 0 (after 0 ratings)
 
In order to integrate Wymeditor with the Django filebrowser, put the code in a file, set the fb_url variable to point to your filebrowser instance and add the file to your Javascript headers:
<script type="text/javascript" src="/media/wymeditor/plugins/jquery.wymeditor.filebrowser.js"></script>
or in your admin.py:
class Media: js = ('/media/wymeditor/plugins/jquery.wymeditor.filebrowser.js',)
Add the postInitDialog parameter to the Wymeditor initialization:
$('textarea').wymeditor({ postInitDialog: wymeditor_filebrowser });
If you already have a postInitDialog function, you need to put a call to wymeditor_filebrowser inside that function. Then you should be able to click on the Filebrowser link to select an image.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  | wymeditor_filebrowser = function(wym, wdw) {
  // the URL to the Django filebrowser, depends on your URLconf
  var fb_url = '/admin/filebrowser/';
  
  var dlg = jQuery(wdw.document.body);
  if (dlg.hasClass('wym_dialog_image')) {
    // this is an image dialog
    dlg.find('.wym_src').css('width', '200px').attr('id', 'filebrowser')
      .after('<a id="fb_link" title="Filebrowser" href="#">Filebrowser</a>');
    dlg.find('fieldset')
      .append('<a id="link_filebrowser"><img id="image_filebrowser" /></a>' +
              '<br /><span id="help_filebrowser"></span>');
    dlg.find('#fb_link')
      .click(function() {
        fb_window = wdw.open(fb_url + '?pop=1', 'filebrowser', 'height=600,width=840,resizable=yes,scrollbars=yes');
        fb_window.focus();
        return false;
      });
  }
}
 | 
More like this
- Django Collapsed Stacked Inlines by applecat 2 years, 8 months ago
 - Django Collapsed Stacked Inlines by mkarajohn 4 years, 9 months ago
 - Dynamically adding forms to a formset. OOP version. by halfnibble 10 years, 5 months ago
 - Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 12 years, 6 months ago
 - Django admin inline ordering - javascript only implementation by ojhilt 12 years, 10 months ago
 
Comments
Please login first before commenting.