cosmetic changes

This commit is contained in:
rolux 2013-03-24 15:10:29 +05:30
parent 0bc7cfdd30
commit 8e40262ab1

View file

@ -26,8 +26,8 @@
}); });
*/ */
pandora.chunkupload = function(options) { pandora.chunkupload = function(options) {
var chunkSize = options.size || 1024*1024, var chunkSize = options.size || 1024 * 1024,
chunkUrl, chunkURL,
file = options.file, file = options.file,
maxRetry = -1, maxRetry = -1,
retries = 0, retries = 0,
@ -45,7 +45,7 @@ pandora.chunkupload = function(options) {
} }
function initUpload() { function initUpload() {
//request upload slot from server // request upload slot from server
that.status = 'requesting chunk upload'; that.status = 'requesting chunk upload';
that.progress = 0; that.progress = 0;
request = new XMLHttpRequest(); request = new XMLHttpRequest();
@ -63,14 +63,14 @@ pandora.chunkupload = function(options) {
if (response.maxRetry) { if (response.maxRetry) {
maxRetry = response.maxRetry; maxRetry = response.maxRetry;
} }
chunkUrl = response.uploadUrl; chunkURL = response.uploadUrl;
if (document.location.protocol == 'https:') { if (document.location.protocol == 'https:') {
chunkUrl = chunkUrl.replace(/http:\/\//, 'https://'); chunkURL = chunkURL.replace(/http:\/\//, 'https://');
} }
if (chunkUrl) { if (chunkURL) {
that.status = 'uploading'; that.status = 'uploading';
that.progress = 0.0; that.progress = 0.0;
//start upload // start upload
uploadChunk(0); uploadChunk(0);
} else { } else {
that.status = 'upload failed, no upload url provided'; that.status = 'upload failed, no upload url provided';
@ -111,7 +111,7 @@ pandora.chunkupload = function(options) {
chunk, chunk,
chunkOffset = chunkId * chunkSize; chunkOffset = chunkId * chunkSize;
if(file.mozSlice) { if (file.mozSlice) {
chunk = file.mozSlice(chunkOffset, chunkOffset+chunkSize, file.type); chunk = file.mozSlice(chunkOffset, chunkOffset+chunkSize, file.type);
} else if(file.webkitSlice) { } else if(file.webkitSlice) {
chunk = file.webkitSlice(chunkOffset, chunkOffset+chunkSize, file.type); chunk = file.webkitSlice(chunkOffset, chunkOffset+chunkSize, file.type);
@ -119,7 +119,7 @@ pandora.chunkupload = function(options) {
chunk = file.slice(chunkOffset, chunkOffset+chunkSize, file.type); chunk = file.slice(chunkOffset, chunkOffset+chunkSize, file.type);
} else { } else {
that.status = 'Sorry, your browser is currently not supported.'; that.status = 'Sorry, your browser is currently not supported.';
done() done();
} }
progress(parseFloat(chunkOffset)/bytesAvailable); progress(parseFloat(chunkOffset)/bytesAvailable);
@ -140,12 +140,12 @@ pandora.chunkupload = function(options) {
that.status = 'done'; that.status = 'done';
done(); done();
} else if (response.result == 1) { } else if (response.result == 1) {
//reset retry counter // reset retry counter
retries = 0; retries = 0;
//start uploading next chunk // start uploading next chunk
uploadChunk(chunkId + 1); uploadChunk(chunkId + 1);
} else { } else {
//failed to upload, try again in 5 second // failed to upload, try again in 5 second
retries++; retries++;
if (maxRetry > 0 && retries > maxRetry) { if (maxRetry > 0 && retries > maxRetry) {
that.status = 'uplaod failed'; that.status = 'uplaod failed';
@ -159,7 +159,7 @@ pandora.chunkupload = function(options) {
} }
}, false); }, false);
request.addEventListener('error', function (evt) { request.addEventListener('error', function (evt) {
//failed to upload, try again in 3 second // failed to upload, try again in 3 second
retries++; retries++;
if (maxRetry > 0 && retries > maxRetry) { if (maxRetry > 0 && retries > maxRetry) {
that.status = 'uplaod failed'; that.status = 'uplaod failed';
@ -191,7 +191,7 @@ pandora.chunkupload = function(options) {
formData.append('done', 1); formData.append('done', 1);
} }
formData.append('chunk', chunk); formData.append('chunk', chunk);
request.open('POST', chunkUrl, true); request.open('POST', chunkURL, true);
request.send(formData); request.send(formData);
} }
@ -201,5 +201,7 @@ pandora.chunkupload = function(options) {
request = null; request = null;
} }
}; };
return that; return that;
}; };