Skip to content

Commit

Permalink
12.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial Farid authored and Danial Farid committed Mar 11, 2016
1 parent 4c246dc commit ad064ea
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular:angular@1.2.24
danialf:ng-file-upload@12.0.0
danialf:ng-file-upload@12.0.1
meteor@1.1.10
underscore@1.0.4
2 changes: 1 addition & 1 deletion FileAPI.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 45 additions & 21 deletions ng-file-upload-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <danial.farid@gmail.com>
* @version 12.0.1
* @version 12.0.2
*/

(function () {
Expand Down Expand Up @@ -424,7 +424,7 @@ if (!window.FileReader) {
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort,
* progress, resize, thumbnail, preview, validation and CORS
* @author Danial <danial.farid@gmail.com>
* @version 12.0.1
* @version 12.0.2
*/

if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
Expand All @@ -445,14 +445,14 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {

var ngFileUpload = angular.module('ngFileUpload', []);

ngFileUpload.version = '12.0.1';
ngFileUpload.version = '12.0.2';

ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
upload.promisesCount = 0;

this.isResumeSupported = function () {
return window.Blob && (window.Blob instanceof Function) && window.Blob.prototype.slice;
return window.Blob && window.Blob.prototype.slice;
};

var resumeSupported = this.isResumeSupported();
Expand Down Expand Up @@ -894,8 +894,25 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
}

function resize(files, attr, scope) {
var param = upload.attrGetter('ngfResize', attr, scope);
if (!param || !angular.isObject(param) || !upload.isResizeSupported() || !files.length) return upload.emptyPromise();
var resizeVal = upload.attrGetter('ngfResize', attr, scope);
if (!resizeVal || !upload.isResizeSupported() || !files.length) return upload.emptyPromise();
if (resizeVal instanceof Function) {
var defer = $q.defer();
resizeVal(files).then(function (p) {
resizeWithParams(p, files, attr, scope).then(function (r) {
defer.resolve(r);
}, function (e) {
defer.reject(e);
});
}, function (e) {
defer.reject(e);
});
} else {
return resizeWithParams(resizeVal, files, attr, scope);
}
}

function resizeWithParams(param, files, attr, scope) {
var promises = [upload.emptyPromise()];

function handleFile(f, i) {
Expand Down Expand Up @@ -1021,7 +1038,7 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE

resize(validateAfterResize ? allNewFiles : valids, attr, scope).then(function () {
if (validateAfterResize) {
upload.validate(allNewFiles, allLength, ngModel, attr, scope).then(function () {
upload.validate(allNewFiles, prevValidFiles.length, ngModel, attr, scope).then(function () {
separateInvalids();
updateModel();
});
Expand Down Expand Up @@ -1059,9 +1076,8 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE

var validateAfterResize = upload.attrGetter('ngfValidateAfterResize', attr, scope);

var allLength = allNewFiles.length + prevValidFiles.length + prevInvalidFiles.length;
var options = upload.attrGetter('ngModelOptions', attr, scope);
upload.validate(allNewFiles, allLength, ngModel, attr, scope).then(function () {
upload.validate(allNewFiles, prevValidFiles.length, ngModel, attr, scope).then(function () {
if (noDelay) {
update(allNewFiles, [], files, dupFiles, isSingleModel);
} else {
Expand Down Expand Up @@ -1638,7 +1654,7 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct
if (files && !angular.isArray(files)) {
files = [files];
}
upload.validate(files, files ? files.length : 0, ngModel, attr, scope).then(function () {
upload.validate(files, 0, ngModel, attr, scope).then(function () {
upload.applyModelValidation(ngModel, files);
});
}
Expand Down Expand Up @@ -1679,7 +1695,7 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct
return val;
};

upload.validate = function (files, allLength, ngModel, attr, scope) {
upload.validate = function (files, prevLength, ngModel, attr, scope) {
ngModel = ngModel || {};
ngModel.$ngfValidations = ngModel.$ngfValidations || [];

Expand All @@ -1705,7 +1721,7 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct
if (file) {
var val = upload.getValidationAttr(attr, scope, name, validationName, file);
if (val != null) {
if (!fn(file, val)) {
if (!fn(file, val, i)) {
file.$error = name;
(file.$errorMessages = (file.$errorMessages || {})).name = true;
file.$errorParam = val;
Expand All @@ -1721,8 +1737,8 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct
}
}

validateSync('maxFiles', null, function (file, val) {
return allLength <= val;
validateSync('maxFiles', null, function (file, val, i) {
return prevLength + i < val;
});
validateSync('pattern', null, upload.validatePattern);
validateSync('minSize', 'size.min', function (file, val) {
Expand Down Expand Up @@ -1900,7 +1916,9 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct
return;
}
upload.dataUrl(file).then(function (dataUrl) {
var img = angular.element('<img>').attr('src', dataUrl).css('visibility', 'hidden').css('position', 'fixed');
var img = angular.element('<img>').attr('src', dataUrl)
.css('visibility', 'hidden').css('position', 'fixed')
.css('max-width', 'none !important').css('max-height', 'none !important');

function success() {
var width = img[0].clientWidth;
Expand Down Expand Up @@ -2132,15 +2150,20 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
setTimeout(function () {throw e;}, 1);
}
}
deferred.resolve(upload.dataUrltoBlob(dataUrl, file.name, file.size));
try {
var blob = upload.dataUrltoBlob(dataUrl, file.name, file.size);
deferred.resolve(blob);
} catch (e) {
deferred.reject(e);
}
}, function (r) {
if (r === 'resizeIf') {
deferred.resolve(file);
}
deferred.reject();
deferred.reject(r);
});
}, function () {
deferred.reject();
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
};
Expand Down Expand Up @@ -2333,6 +2356,7 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
});
return defer.promise;
}
return upload.emptyPromise();
}

function calculateDragOverClass(scope, attr, evt, callback) {
Expand Down Expand Up @@ -2465,7 +2489,7 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa

var defer = $q.defer();
$q.all(promises).then(function () {
if (!multiple && !includeDir) {
if (!multiple && !includeDir && files.length) {
var i = 0;
while (files[i] && files[i].type === 'directory') i++;
defer.resolve([files[i]]);
Expand Down Expand Up @@ -2517,7 +2541,7 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
upload.readOrientation = function (file) {
var defer = $q.defer();
var reader = new FileReader();
var slicedFile = file.slice(0, 64 * 1024);
var slicedFile = file.slice ? file.slice(0, 64 * 1024) : file;
reader.readAsArrayBuffer(slicedFile);
reader.onerror = function (e) {
return defer.reject(e);
Expand Down
7 changes: 3 additions & 4 deletions ng-file-upload-all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ng-file-upload-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <danial.farid@gmail.com>
* @version 12.0.1
* @version 12.0.2
*/

(function () {
Expand Down
2 changes: 1 addition & 1 deletion ng-file-upload-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ad064ea

Please sign in to comment.