Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
84
gaia/dev_apps/uitest/js/API/downloads.js
Executable file
84
gaia/dev_apps/uitest/js/API/downloads.js
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
'use strict';
|
||||
|
||||
var Downloads = function Downloads() {
|
||||
|
||||
var deleteButton, statusButton;
|
||||
|
||||
var download = null;
|
||||
|
||||
var init = function init() {
|
||||
deleteButton = document.getElementById('downloadDelete');
|
||||
deleteButton.addEventListener('click', onDelete);
|
||||
statusButton = document.getElementById('downloadStatus');
|
||||
statusButton.addEventListener('click', onStatus);
|
||||
|
||||
listen();
|
||||
};
|
||||
|
||||
var onDelete = function onDelete(evt) {
|
||||
LazyLoader.load(['/shared/js/download/download_helper.js'],
|
||||
function helperLoaded() {
|
||||
var request = DownloadHelper.remove(download);
|
||||
request.onsuccess = function() {
|
||||
alert('Download removed succesfully');
|
||||
download = null;
|
||||
deleteButton.disabled = true;
|
||||
statusButton.disabled = true;
|
||||
};
|
||||
|
||||
request.onerror = function(msg) {
|
||||
alert('Error : ' + msg.message);
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var onStatus = function onStatus(evt) {
|
||||
if (download === null) {
|
||||
alert('No download initiated');
|
||||
} else {
|
||||
var msg = 'Current download:\n';
|
||||
msg += 'Total bytes: ' + download.totalBytes + '\n';
|
||||
msg += 'Current bytes: ' + download.currentBytes + '\n';
|
||||
msg += 'Url: ' + download.url + '\n';
|
||||
msg += 'Path: ' + download.path + '\n';
|
||||
try {
|
||||
msg += 'Start time: ' + download.startTime + '\n';
|
||||
} catch (e) {
|
||||
msg += 'Start: unknown\n';
|
||||
}
|
||||
msg += 'Id: ' + download.id + '\n';
|
||||
alert('Current download: ' + JSON.stringify(msg));
|
||||
console.log(msg);
|
||||
}
|
||||
};
|
||||
|
||||
var listen = function listen() {
|
||||
navigator.mozDownloadManager.ondownloadstart = downloadStartedListener;
|
||||
};
|
||||
|
||||
var downloadStartedListener = function downloadStartedListener(evt) {
|
||||
download = evt.download;
|
||||
download.onstatechange = downloadChangeListener;
|
||||
|
||||
statusButton.disabled = false;
|
||||
statusButton.textContent = 'Status: ' + download.state;
|
||||
//console.log('State new download: ' + download.state);
|
||||
};
|
||||
|
||||
var downloadChangeListener = function downloadChangeListener(evt) {
|
||||
statusButton.textContent = 'Status: ' + download.state;
|
||||
console.log('State change: ' + download.state);
|
||||
|
||||
if (download.state === 'succeeded') {
|
||||
console.log('Download finished');
|
||||
deleteButton.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'init': init
|
||||
};
|
||||
}();
|
||||
|
||||
window.addEventListener('load', Downloads.init.bind(Downloads));
|
||||
Loading…
Reference in a new issue