Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
feat($addCanvas): start of ability to accept <canvas> in addFiles m…
Browse files Browse the repository at this point in the history
…ethod

- Deprecated addBlobs.
- Removed addBlobs from documentation.
- Redirected unit tests that called addBlobs to use addFiles instead
- addFiles now handles the work of addBlobs and, of course, addFiles
- re-organized addFiles
TODO: accept `<canvas>`

#1198
  • Loading branch information
Ray Nicholus committed Jun 4, 2014
1 parent 5cde7eb commit eb5b396
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Fine Uploader](http://fineuploader.com/img/FineUploader_logo.png)](http://fineuploader.com/)

Version: 5.0.0 (IN PROGRESS)
Version: 5.1.0-1 (IN PROGRESS)

[![Build Status](https://travis-ci.org/Widen/fine-uploader.png?branch=master)](https://travis-ci.org/Widen/fine-uploader) | [![Semver badge](http://calm-shore-6115.herokuapp.com/?label=SemVer&value=2.0.0&color=green)](http://semver.org/spec/v2.0.0.html)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fine-uploader",
"version": "5.0.0",
"version": "5.1.0-1",
"devDependencies": {
"jquery": "1.10.0",
"purl": "https://github.com/allmarkedup/purl.git#~2.3.1",
Expand Down
77 changes: 52 additions & 25 deletions client/js/uploader.basic.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,65 @@
}
},

addFiles: function(filesOrInputs, params, endpoint) {
var verifiedFilesOrInputs = [],
batchId = this._storedIds.length === 0 ? qq.getUniqueId() : this._currentBatchId,
fileOrInputIndex, fileOrInput, fileIndex;
addFiles: function(data, params, endpoint) {
var batchId = this._storedIds.length === 0 ? qq.getUniqueId() : this._currentBatchId,

processBlob = qq.bind(function(blob) {
this._handleNewFile({
blob: blob,
name: this._options.blobs.defaultName
}, batchId, verifiedFiles);
}, this),

processBlobData = qq.bind(function(blobData) {
this._handleNewFile(blobData, batchId, verifiedFiles);
}, this),

processFileOrInput = qq.bind(function(fileOrInput) {
if (qq.isInput(fileOrInput) && qq.supportedFeatures.ajaxUploading) {
var files = Array.prototype.slice.call(fileOrInput.files);

qq.each(files, function(idx, file) {
this._handleNewFile(file, batchId, verifiedFiles);
});
}
else {
this._handleNewFile(fileOrInput, batchId, verifiedFiles);
}
}, this),

this._currentBatchId = batchId;
normalizeData = function() {
if (qq.isFileList(data)) {
data = Array.prototype.slice.call(data);
}
data = [].concat(data);
},

if (filesOrInputs) {
if (!qq.isFileList(filesOrInputs)) {
filesOrInputs = [].concat(filesOrInputs);
}
self = this,
verifiedFiles = [];

this._currentBatchId = batchId;

for (fileOrInputIndex = 0; fileOrInputIndex < filesOrInputs.length; fileOrInputIndex+=1) {
fileOrInput = filesOrInputs[fileOrInputIndex];
if (data) {
normalizeData();

if (qq.isFileOrInput(fileOrInput)) {
if (qq.isInput(fileOrInput) && qq.supportedFeatures.ajaxUploading) {
for (fileIndex = 0; fileIndex < fileOrInput.files.length; fileIndex++) {
this._handleNewFile(fileOrInput.files[fileIndex], batchId, verifiedFilesOrInputs);
}
}
else {
this._handleNewFile(fileOrInput, batchId, verifiedFilesOrInputs);
}
qq.each(data, function(idx, fileContainer) {
if (qq.isFileOrInput(fileContainer)) {
processFileOrInput(fileContainer);
}
else if (qq.isBlob(fileContainer)) {
processBlob(fileContainer);
}
else if (qq.isObject(fileContainer) && fileContainer.blob && fileContainer.name) {
processBlobData(fileContainer);
}
else {
this.log(fileOrInput + " is not a File or INPUT element! Ignoring!", "warn");
self.log(fileContainer + " is not a valid file container! Ignoring!", "warn");
}
}
});

this.log("Received " + verifiedFilesOrInputs.length + " files or inputs.");
this._prepareItemsForUpload(verifiedFilesOrInputs, params, endpoint);
this.log("Received " + verifiedFiles.length + " files.");
this._prepareItemsForUpload(verifiedFiles, params, endpoint);
}
},

Expand Down Expand Up @@ -994,7 +1021,7 @@

name += "." + extension;

this.addBlobs({
this.addFiles({
name: name,
blob: blob
});
Expand Down
2 changes: 1 addition & 1 deletion client/js/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*global qq */
qq.version="5.0.0";
qq.version="5.1.0-1";
3 changes: 1 addition & 2 deletions docs/api/events.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ See the [`uploadChunk` event](#uploadChunk) for more information on the `chunkDa
}}

{{ api_event("validate", "validate",
""" Called once for each selected, dropped, or `addFiles` submitted file and for
each `addBlobs` submitted `Blob`.
""" Called once for each selected, dropped, or `addFiles` submitted file.

This callback is always invoked before the default Fine Uploader validators
execute.
Expand Down
31 changes: 6 additions & 25 deletions docs/api/methods.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,7 @@ $(document).ready(function() {
{% markdown %}
## Core
{% endmarkdown %}
{{ api_method("addFiles", "addFiles (files[, params[, endpoint]])", "Submit one or more File objects to the uploader",
[
{
"name": "files",
"type": "Array",
"description": "An array of `File`s or `<input>` `HTMLElements`"
},
{
"name": "params",
"type": "Object",
"description": "A set of parameters to send with the file to be added"
},
{
"name": "endpoint",
"type": "String",
"description": "The endpoint to send this file to"
}
]) }}

{{ api_method("addBlobs", "addBlobs (blobs[, params[, endpoint]])", "Submit one or more Blob objects to the uploader.
{{ api_method("addFiles", "addFiles (files[, params[, endpoint]])", "Submit one or more files to the uploader.

A `BlobData` object:

Expand All @@ -60,11 +41,11 @@ A `BlobData` object:

",
[
{
"name": "blobs",
"type": "Array",
"description": "An array of `Blob` or `BlobData` objects."
},
{
"name": "files",
"type": "Array",
"description": "An array of `File`s, `<input>`s, `FileList`s, `Blob`s, or `BlobData` objects"
},
{
"name": "params",
"type": "Object",
Expand Down
2 changes: 1 addition & 1 deletion docs/features/upload-files.jmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "_templates/base.html" %}
{% set page_title = "Upload Files" %}
{% block sidebar %}
{{ api_links(options=['request', 'request-s3', 'credentials-s3'], methods=['addFiles', 'addBlobs', 'uploadStoredFiles'], events=['submit', 'submitted', 'complete', 'upload']) }}
{{ api_links(options=['request', 'request-s3', 'credentials-s3'], methods=['addFiles', 'uploadStoredFiles'], events=['submit', 'submitted', 'complete', 'upload']) }}
{% endblock %}
{% block content %}
{% markdown %}
Expand Down
2 changes: 1 addition & 1 deletion fineuploader.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"azure",
"microsoft"
],
"version": "5.0.0",
"version": "5.1.0-1",
"author": {
"name": "Widen Enterprises",
"url": "http://widen.com"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fineuploader",
"title": "Fine Uploader",
"version": "5.0.0",
"version": "5.1.0-1",
"description": "Multiple file upload component with progress-bar, drag-and-drop, support for all modern browsers.",
"main": "./fine-uploader/js/fineuploader.js",
"maintainers": [
Expand Down
2 changes: 1 addition & 1 deletion test/unit/azure/chunked-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("azure chunked upload tests", function() {
var signatureRequest, signatureRequestPurl;

fileTestHelper.mockXhr();
uploader.addBlobs({name: "test.jpg", blob: blob});
uploader.addFiles({name: "test.jpg", blob: blob});

assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");

Expand Down
2 changes: 1 addition & 1 deletion test/unit/azure/delete-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (qqtest.canDownloadFileAsBlob) {
var signatureRequest;

fileTestHelper.mockXhr();
uploader.addBlobs({name: "test.jpg", blob: blob});
uploader.addFiles({name: "test.jpg", blob: blob});

assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");

Expand Down
2 changes: 1 addition & 1 deletion test/unit/azure/simple-file-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (qqtest.canDownloadFileAsBlob) {
var signatureRequest;

fileTestHelper.mockXhr();
uploader.addBlobs({name: "test.jpg", blob: blob});
uploader.addFiles({name: "test.jpg", blob: blob});

setTimeout(function() {
assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");
Expand Down
4 changes: 2 additions & 2 deletions test/unit/chunked-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});
});
}

Expand Down Expand Up @@ -183,7 +183,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});
});
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit/concurrent-chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});
});
});

Expand Down Expand Up @@ -116,7 +116,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});
});
});

Expand Down Expand Up @@ -176,7 +176,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});

});
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/delete-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ if (qqtest.canDownloadFileAsBlob) {

var request;

uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});

assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");
request = fileTestHelper.getRequests()[0];
Expand Down
4 changes: 2 additions & 2 deletions test/unit/file-upload-params-and-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if (qqtest.canDownloadFileAsBlob) {
purlUrl,
theparams = overrideParams || params;

uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});
uploader.uploadStoredFiles();

assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");
Expand All @@ -81,7 +81,7 @@ if (qqtest.canDownloadFileAsBlob) {

var request;

uploader.addBlobs({name: "test", blob: blob});
uploader.addFiles({name: "test", blob: blob});
uploader.uploadStoredFiles();

assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");
Expand Down
2 changes: 1 addition & 1 deletion test/unit/form-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe("test form support", function() {

var request, requestParams;

uploader.addBlobs(blob);
uploader.addFiles(blob);

assert.equal(fileTestHelper.getRequests().length, 0, "Wrong # of requests");
uploader.uploadStoredFiles();
Expand Down
14 changes: 7 additions & 7 deletions test/unit/on-all-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs(blob);
uploader.addFiles(blob);
!autoUpload && uploader.uploadStoredFiles();

if (success) {
Expand Down Expand Up @@ -97,7 +97,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs([blob, blob]);
uploader.addFiles([blob, blob]);
});
};

Expand Down Expand Up @@ -139,7 +139,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs(blob);
uploader.addFiles(blob);
uploader.cancel(0);

setTimeout(function() {
Expand Down Expand Up @@ -196,7 +196,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs([blob, blob]);
uploader.addFiles([blob, blob]);
});
});

Expand Down Expand Up @@ -235,7 +235,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs([blob, blob]);
uploader.addFiles([blob, blob]);
});
});

Expand All @@ -260,7 +260,7 @@ if (qqtest.canDownloadFileAsBlob) {

qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) {
fileTestHelper.mockXhr();
uploader.addBlobs([blob, blob]);
uploader.addFiles([blob, blob]);

setTimeout(function() {
assert.deepEqual(callbackOrder, ["submit", "submit"]);
Expand Down Expand Up @@ -305,7 +305,7 @@ if (qqtest.canDownloadFileAsBlob) {
}),
uploadFiles = function() {
callbackOrder = [];
uploader.addBlobs([blobToUpload, blobToUpload]);
uploader.addFiles([blobToUpload, blobToUpload]);
},
blobToUpload;

Expand Down
4 changes: 2 additions & 2 deletions test/unit/s3/chunked-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (qqtest.canDownloadFileAsBlob) {
var initiateSignatureRequest, uploadRequest, initiateToSign;

fileTestHelper.mockXhr();
uploader.addBlobs({name: "test.jpg", blob: blob});
uploader.addFiles({name: "test.jpg", blob: blob});

assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");

Expand Down Expand Up @@ -544,7 +544,7 @@ if (qqtest.canDownloadFileAsBlob) {
var uploadRequest;

fileTestHelper.mockXhr();
uploader.addBlobs({name: "test.jpg", blob: blob});
uploader.addFiles({name: "test.jpg", blob: blob});

assert.equal(fileTestHelper.getRequests().length, 1, "Wrong # of requests");

Expand Down
Loading

0 comments on commit eb5b396

Please sign in to comment.