Skip to content

Files

Latest commit

 

History

History
190 lines (173 loc) · 6.47 KB

drag-and-drop.md

File metadata and controls

190 lines (173 loc) · 6.47 KB

File Drag and Drop Module

Note: This module is aimed at FineUploaderBasic mode integrators only. If you are running the library in FineUploader mode, have a look at the dragAndDrop options instead.

If you are integrating Fine Uploader and utilizing FineUploaderBasic mode, you are likely building you own UI entirely. In case you want to support drag and drop of folders and files, you probably don't want to re-invent the wheel, since Fine Uploader already has code to handle this in FineUploader mode. Fine Uploader's drag & drop code has been moved into a standalone module, so it can be easily integrated into your FineUploaderBasic mode app (or even any non-Fine Uploader app). This document will explain how to utilize this module.


### Non-jQuery Example ### If you are not utilizing jQuery, you can use the plain javascript DnD module. Here is a simple example: ```javascript var dragAndDropModule = new qq.DragAndDrop({ dropZoneElements: [document.getElementById('myDropZone')], classes: { dropActive: "cssClassToAddToDropZoneOnEnter" }, callbacks: { processingDroppedFiles: function() { //TODO: display some sort of a "processing" or spinner graphic }, processingDroppedFilesComplete: function(files) { //TODO: hide spinner/processing graphic
        fineUploaderBasicInstance.addFiles(files); //this submits the dropped files to Fine Uploader
      }
    }
  }),

fineUploaderBasicInstance = new qq.FineUploaderBasic({ request: { endpoint: "server/uploadHandler" } });


<br/>
### jQuery Plug-in Wrapper Notes & Example ###
For jQuery users, a jQuery-wrapped DnD module is also available in the combined and minified Fine Uplpoader javascript file.
This jQuery wrapper follows the same conventions as the jQuery plug-in that wraps the uploader library.  To read more
about these conventions, please see the [Using jQuery plug-in](using-jquery-plugin.md) readme document.

There are a couple things to be aware of when using the DnD standalone module via the jQuery plug-in wrapper:
* The only API method available is `dispose`.  This restriction is in place since the other API functions don't really make sense in the context of a jQuery plug-in.
* The target of your plug-in instance takes the place of the `dropZoneElements` option.  Do not pass a `dropZoneElements` option, it will be ignored.

Here is the above example rewritten using the jQuery plug-in wrappers:
```javascript
$('#myDropZone').fineUploaderDnd({
    classes: {
        dropActive: "cssClassToAddToDropZoneOnEnter"
    }
})
    .on('processingDroppedFiles', function(event) {
        //TODO: display some sort of a "processing" or spinner graphic
    })
    .on('processingDroppedFilesComplete', function(event, files) {
        //TODO: hide spinner/processing graphic

        $('#fineUploaderBasicContainer').fineUploader('addFiles', files); //this submits the dropped files to Fine Uploader
    });

$('#fineUploaderBasicContainer').fineUploader({
    request: {
        endpoint: "server/uploadHandler"
    }
});

### Options ###
Name Type Default Note
dropZoneElements array of HTML elements [] Use this option to specify all container elements that should be treated as drop zones by the module.
hideDropZonesBeforeEnter boolean false Set this to true if you would like to ensure that the contents of all drop zones are only revealed when a file has entered the drop zone.
allowMultipleItems boolean true Set this to false if you would like to prevent a user from dropping more than one item at once.

classes option

Name Type Default Note
dropActive string null Specify a CSS class you would like the module to assign to the drop zone when a file has entered the drop zone.

callbacks option

Name arguments Note
processingDroppedFiles none Invoked when the module has started processing the set of dropped files.
processingDroppedFilesComplete array of File objects Invoked when the module has finished processing the set of dropped files. The parameter passed to this callback represents all files parsed by the module from the associated drop event.
dropError errorCode, errorRelatedData Invoked when processing the drop fails for some reason.
dropLog message, logLevel Invoked when a message is logged.

### API ###
Function Name arguments Note
setupExtraDropzone element Call this to add an additional drop zone to the DnD instance. Not available if using the jQuery plug-in wrapper.
removeDropzone element Call this to remove a drop zone from the DnD instance. Not available if using the jQuery plug-in wrapper.
dispose none Tears down all drop zones associated with the dnd instance.