aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/drag_and_drop_upload.js
blob: ae373509f6f10d44033566f65a9c0d6fbd2fd09e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Drag and drop file upload */
const DragAndDropUpload = {
    bind: function(form) {
        form = form || document;

        jQuery('input[type=file]', form).change(function() {
            jQuery(this)
                .closest('form')
                .submit();
        });

        // The drag event handling is seriously messed up
        // see http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html
        jQuery(form).on('dragover dragleave', function(event) {
            jQuery(this).toggleClass('hovered', event.type === 'dragover');
            return false;
        });
    }
};

export default DragAndDropUpload;