forked from revolunet/cordova-download-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcordova-download.js
27 lines (27 loc) · 1.09 KB
/
cordova-download.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
// revolunet 2012
// Cordova Javascript plugin implementation
var FileDownload = function() {};
FileDownload.prototype.start = function(url, success, fail, progress, outPath) {
var key = 'f' + this.callbackIdx++;
window.plugins.Download.callbackMap[key] = {
success: function(result) {
success(result);
delete window.plugins.Download.callbackMap[key];
},
fail: function(result) {
fail(result);
delete window.plugins.Download.callbackMap[key];
},
progress: progress
};
var callback = 'window.plugins.Download.callbackMap.' + key;
return Cordova.exec("FileDownloadPlugin.start", callback + '.success', callback + '.fail', callback + '.progress', url, outPath );
};
FileDownload.prototype.callbackMap = {};
FileDownload.prototype.callbackIdx = 0;
FileDownload.prototype.status = ['idle', 'download', 'unzip', 'finished', 'canceled', 'error'];
cordova.addConstructor(function() {
if(!window.plugins) window.plugins = {};
window.plugins.Download = new FileDownload();
});
// end plugin implementation