darklow / django-suit-redactor

Imperavi Readactor (WYSIWYG editor) integration app for Django admin
26 stars 21 forks source link

Failed initialisation if other app provides jquery after redactor.min.js is included #5

Closed dzerrenner closed 8 years ago

dzerrenner commented 10 years ago

In some cases, when you use an app thet provides an own version of jquery, the redactor widget fails to initialize. The line

$('#textarea').redactor(...)

Throws an exception: Uncaught TypeError: undefined is not a function

You could solve this by ovveriding the change_form.html admin template:

{% extends "admin/change_form.html" %}

{% block extrahead %}{{ block.super }}
<!-- append redactor js to the end of the head segment -->
<script type="text/javascript" src="/static/suit-redactor/redactor/redactor.min.js"></script>
{% endblock %}

The caveat of that is that the js is included in the template twice (and possibly interpreted twice), but it makes things work again.

Or if there is the possibility to tell other apps to abstain from adding its own jquery, you could do that. In my specific example, this is the case for https://github.com/asyncee/django-easy-select2. There you can set the option

SELECT2_USE_BUNDLED_JQUERY = False

The issue is caused because django-admins jquery is loaded before redactor.min.js and the other apps jquery after redactor.min.js, wich overrides that binding.

This is not really a bug, but worth a mention in the docs.

darklow commented 8 years ago

Fixed in recent version.