-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjquery-dragout.js
32 lines (31 loc) · 1020 Bytes
/
jquery-dragout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Download a file by dragging it out of the browser.
* Currently only supported by google chrome browser
* @example
* <a class="dragout"
* data-downloadurl="application/pdf:saleking-invoice.pdf:http://salesking.eu"
* href="http://some-url.de"
* salesking-invoice.pdf</a>
*
* $('.downdrag').dragout();
*
* The important part:
* data-downloadurl="application/pdf:saleking-invoice.pdf:http://salesking.eu"
* data-downloadurl="mime-type:filename:file-url"
*/
(function($) {
$.fn.extend({
dragout : function () {
var files = this;
if(files.length > 0) {
var use_data = (typeof files[0].dataset === "undefined") ? false : true;
$(files).each(function() {
var url = use_data ? this.dataset.downloadurl : this.getAttribute("data-downloadurl");
this.addEventListener("dragstart",function(e){
e.dataTransfer.setData("DownloadURL",url);
},false);
});
}
}
});
})(jQuery);