caktus/django-file-picker — pull request #16 by aetius (2013-07-05 19:05:53+00:00)
Title: possible fix for "stacking" of django-file-picker buttons when applied multiple wymeditor instances

This is Matt over at Capstrat - I'm requesting this as a fix to an issue on Cotton University though it should be useful for anyone using django-file-picker with multiple wymeditor instances. The symptoms of the problem were:

1) Sometimes wymeditor instances would have the "upload image" button's original file-picker dialog exposed when clicking the "upload image" button, instead of the django-file-picker modal
2) Multiple instances of the django-file-picker paperclip buttons would stack up on one of the wymeditor instances (usually the first or last instance); this placement would change sometimes on page refresh.
3) Even if the wymeditor "upload image" button displayed the correct django-file-picker modal, the behavior of the modal was unpredictable; sometimes uploaded images would appear in a different wymeditor instance.

I think the issue was an interaction between $box and jQuery's .getJSON in jquery.wymeditor.filepicker.js. Because $box was a callable (not sure on correct terminology in javascript) instead of a variable, the asynchronous .getJSON calls would use whatever $box ended up being at the time they executed instead of the value that was established in the function.