Login

Integrate Wymeditor with filebrowser plugin

Author:
jonasvp
Posted:
November 18, 2008
Language:
JavaScript
Version:
Not specified
Tags:
javascript images wymeditor filebrowser
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

  1. A dict template tag by Batiste 7 years, 2 months ago
  2. FCKEditor replace all vLargeTextField in admin by aronchi 6 years, 8 months ago
  3. Middleware to move tags <script> to the bottom by marinho 4 years, 12 months ago
  4. Simple "html email with images" sender by andres_torres_marroquin 4 years, 4 months ago
  5. Unobtrusvie Foldable Admin Interface by whiteinge 7 years, 5 months ago

Comments

Please login first before commenting.