Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/progerxp/filedrop
Self-contained cross-browser pure JavaScript class for Drag & Drop and AJAX (multi) file upload.
https://github.com/progerxp/filedrop
Last synced: 5 days ago
JSON representation
Self-contained cross-browser pure JavaScript class for Drag & Drop and AJAX (multi) file upload.
- Host: GitHub
- URL: https://github.com/progerxp/filedrop
- Owner: ProgerXP
- License: unlicense
- Created: 2013-02-15T10:19:35.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-04-17T18:54:49.000Z (over 1 year ago)
- Last Synced: 2024-03-23T14:02:52.495Z (10 months ago)
- Language: JavaScript
- Homepage: filedropjs.org
- Size: 337 KB
- Stars: 264
- Watchers: 15
- Forks: 61
- Open Issues: 41
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# FileDrop Revamped
#### Self-contained cross-browser HTML5, legacy, AJAX, drag & drop JavaScript file upload**FileDrop** is a lightweight JavaScript class for easy-to-use file uploading that works out of the box and supports even most legacy browsers.
[ [Documentation](http://filedropjs.org) | [Demo page](http://filedropjs.org/demo/) ]
## Features
* **Cross-browser** – supports Firefox 3.6, Internet Explorer 6, Google Chrome 7, Apple Safari 5 and Opera 11.61.
* **No JS dependencies**, Flash or Java applets
* 900 lines of code, 1300 lines of comments
* **16 KiB minified**, 6 KiB gzipped
* **HTML5, drag & drop** for modern browsers
* **IFrame fallback** for legacy agents (IE 6+)
* Flexible **event system** with over 15 callbacks
* Multiple **independent FileDrops** on one page
* Ready for **jQuery**, PHP, ASP.net and others
* 500+ lines of **unit tests** ([tests.html](http://filedropjs.org/demo/tests.html))## Basic example
[Live demo](http://filedropjs.org/demo/basic.html) →
```HTML
Basic FileDrop example
/***
Styles below are only required if you're using <iframe> fallback in
addition to HTML5 drag & drop (only working in Firefox/Chrome).
***//* Essential FileDrop zone element configuration: */
.fd-zone {
position: relative;
overflow: hidden;
/* The following are not required but create a pretty box: */
width: 15em;
margin: 0 auto;
text-align: center;
}/* Hides <input type="file"> while simulating "Browse" button: */
.fd-file {
opacity: 0;
font-size: 118px;
position: absolute;
right: 0;
top: 0;
z-index: 1;
padding: 0;
margin: 0;
cursor: pointer;
filter: alpha(opacity=0);
font-family: sans-serif;
}/* Provides visible feedback when use drags a file over the drop zone: */
.fd-zone.over { border-color: maroon; background: #eee; }
JavaScript is disabled in your browser. How do you expect FileDrop to work?
FileDrop basic sample
Drop a file inside…
Or click here to Browse..
Allow multiple selection
// Tell FileDrop we can deal with iframe uploads using this URL:
var options = {iframe: {url: 'upload.php'}};
// Attach FileDrop to an area ('zone' is an ID but you can also give a DOM node):
var zone = new FileDrop('zone', options);// Do something when a user chooses or drops a file:
zone.event('send', function (files) {
// Depending on browser support files (FileList) might contain multiple items.
files.each(function (file) {
// React on successful AJAX upload:
file.event('done', function (xhr) {
// 'this' here points to fd.File instance that has triggered the event.
alert('Done uploading ' + this.name + ', response:\n\n' + xhr.responseText);
});// Send the file:
file.sendTo('upload.php');
});
});// React on successful iframe fallback upload (this is separate mechanism
// from proper AJAX upload hence another handler):
zone.event('iframeDone', function (xhr) {
alert('Done uploading via <iframe>, response:\n\n' + xhr.responseText);
});// A bit of sugar - toggling multiple selection:
fd.addEvent(fd.byID('multiple'), 'change', function (e) {
zone.multiple(e.currentTarget || e.srcElement.checked);
});
```
## jQuery integration
FileDrop can be integrated with jQuery by simply calling the following method (once, after loading both FileDrop and jQuery): `fd.jQuery()`.
Drop zone events are prefixed with **fd** while individual file events start with **file**. DOM node events are triggered before those assigned to `obj.on.XXX` arrays and if a node handler returns non-null value on’s events are skipped.
Note that jQuery will prepend its own event object in front of FileDrop’s normal event arguments since they’re triggered as regular events of a DOM node. See extensive comments in the sources for more details and examples.
More information in the [documentation](http://filedropjs.org/#jquery) →
```JS
fd.jQuery(); // you can also pass an object like 'jQuery'.// Henceforth it's possible to access FileDrop as $().filedrop().
$('')Drop something here...
.appendTo(document.body)
.filedrop()
// jQuery always passes event object as the first argument.
.on('fdsend', function (e, files) {
$.each(files, function (i, file) {
file.SendTo('upload.php');
});
})
.on('filedone', function (e, file) {
alert('Done uploading ' + file.name + ' on ' + this.tagName);
});
```