Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial Farid authored and Danial Farid committed Nov 27, 2015
1 parent 628b227 commit f132a67
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 105 deletions.
2 changes: 0 additions & 2 deletions demo/src/main/webapp/js/FileAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@
return attr in input;
},

_support

/**
* FileAPI (core object)
*/
Expand Down
7 changes: 3 additions & 4 deletions demo/src/main/webapp/js/FileAPI.min.js

Large diffs are not rendered by default.

46 changes: 30 additions & 16 deletions demo/src/main/webapp/js/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 10.0.2
* @version 10.0.3
*/

(function () {
Expand Down Expand Up @@ -421,7 +421,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 10.0.2
* @version 10.0.3
*/

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

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

ngFileUpload.version = '10.0.2';
ngFileUpload.version = '10.0.3';

ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
Expand Down Expand Up @@ -838,6 +838,7 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
var promises = [upload.emptyPromise()];
angular.forEach(files, function (f, i) {
if (f.type.indexOf('image') === 0) {
if (param.pattern && !upload.validatePattern(f, param.pattern)) return;
var promise = upload.resize(f, param.width, param.height, param.quality, param.type);
promises.push(promise);
promise.then(function (resizedFile) {
Expand Down Expand Up @@ -914,7 +915,9 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
}

var newFiles = files;
var prevFiles = ((ngModel && ngModel.$modelValue) || attr.$$ngfPrevFiles || []).slice(0);
var prevFiles = ngModel && ngModel.$modelValue && (angular.isArray(ngModel.$modelValue) ?
ngModel.$modelValue : [ngModel.$modelValue]);
prevFiles = (prevFiles || attr.$$ngfPrevFiles || []).slice(0);
var keepResult = handleKeep(files, prevFiles, attr, scope);
files = keepResult.files;
var dupFiles = keepResult.dupFiles;
Expand Down Expand Up @@ -1036,13 +1039,12 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
if (elem !== fileElem) {
for (var i = 0; i < elem[0].attributes.length; i++) {
var attribute = elem[0].attributes[i];
if (attribute.name !== 'type' && attribute.name !== 'class' &&
attribute.name !== 'id' && attribute.name !== 'style') {
if (attribute.name !== 'type' && attribute.name !== 'class' && attribute.name !== 'style') {
if (attribute.value == null || attribute.value === '') {
if (attribute.name === 'required') attribute.value = 'required';
if (attribute.name === 'multiple') attribute.value = 'multiple';
}
fileElem.attr(attribute.name, attribute.value);
fileElem.attr(attribute.name, attribute.name === 'id' ? 'ngf-' + attribute.value : attribute.value);
}
}
}
Expand Down Expand Up @@ -1663,24 +1665,36 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct
}, /image/, this.imageDimensions, function (d, val) {
return d.width >= val;
})));
function ratioToFloat(val) {
var r = val, xIndex = r.search(/x/i);
if (xIndex > -1) {
r = parseFloat(r.substring(0, xIndex)) / parseFloat(r.substring(xIndex + 1));
} else {
r = parseFloat(r);
}
return r;
}
promises.push(upload.happyPromise(validateAsync('ratio', function (cons) {
return cons.ratio;
}, /image/, this.imageDimensions, function (d, val) {
var split = val.toString().split(','), valid = false;

for (var i = 0; i < split.length; i++) {
var r = split[i], xIndex = r.search(/x/i);
if (xIndex > -1) {
r = parseFloat(r.substring(0, xIndex)) / parseFloat(r.substring(xIndex + 1));
} else {
r = parseFloat(r);
}
if (Math.abs((d.width / d.height) - r) < 0.0001) {
if (Math.abs((d.width / d.height) - ratioToFloat(split[i])) < 0.0001) {
valid = true;
}
}
return valid;
})));
promises.push(upload.happyPromise(validateAsync('maxRatio', function (cons) {
return cons.ratio;
}, /image/, this.imageDimensions, function (d, val) {
return Math.abs((d.width / d.height) - ratioToFloat(val)) < 0.0001;
})));
promises.push(upload.happyPromise(validateAsync('minRatio', function (cons) {
return cons.ratio;
}, /image/, this.imageDimensions, function (d, val) {
return Math.abs((d.width / d.height) - ratioToFloat(val)) > -0.0001;
})));
promises.push(upload.happyPromise(validateAsync('maxDuration', function (cons) {
return cons.duration && cons.duration.max;
}, /audio|video/, this.mediaDuration, function (d, val) {
Expand Down Expand Up @@ -2335,7 +2349,7 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
return;
}
if (angular.isString(orientation)) {
defer.reject(orientation);
defer.resolve(1);
} else {
file.$ngfOrientation = orientation;
defer.resolve(orientation);
Expand Down
7 changes: 4 additions & 3 deletions demo/src/main/webapp/js/ng-file-upload-all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/src/main/webapp/js/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 10.0.2
* @version 10.0.3
*/

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

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

44 changes: 29 additions & 15 deletions demo/src/main/webapp/js/ng-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 10.0.2
* @version 10.0.3
*/

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

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

ngFileUpload.version = '10.0.2';
ngFileUpload.version = '10.0.3';

ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
Expand Down Expand Up @@ -419,6 +419,7 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
var promises = [upload.emptyPromise()];
angular.forEach(files, function (f, i) {
if (f.type.indexOf('image') === 0) {
if (param.pattern && !upload.validatePattern(f, param.pattern)) return;
var promise = upload.resize(f, param.width, param.height, param.quality, param.type);
promises.push(promise);
promise.then(function (resizedFile) {
Expand Down Expand Up @@ -495,7 +496,9 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
}

var newFiles = files;
var prevFiles = ((ngModel && ngModel.$modelValue) || attr.$$ngfPrevFiles || []).slice(0);
var prevFiles = ngModel && ngModel.$modelValue && (angular.isArray(ngModel.$modelValue) ?
ngModel.$modelValue : [ngModel.$modelValue]);
prevFiles = (prevFiles || attr.$$ngfPrevFiles || []).slice(0);
var keepResult = handleKeep(files, prevFiles, attr, scope);
files = keepResult.files;
var dupFiles = keepResult.dupFiles;
Expand Down Expand Up @@ -617,13 +620,12 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
if (elem !== fileElem) {
for (var i = 0; i < elem[0].attributes.length; i++) {
var attribute = elem[0].attributes[i];
if (attribute.name !== 'type' && attribute.name !== 'class' &&
attribute.name !== 'id' && attribute.name !== 'style') {
if (attribute.name !== 'type' && attribute.name !== 'class' && attribute.name !== 'style') {
if (attribute.value == null || attribute.value === '') {
if (attribute.name === 'required') attribute.value = 'required';
if (attribute.name === 'multiple') attribute.value = 'multiple';
}
fileElem.attr(attribute.name, attribute.value);
fileElem.attr(attribute.name, attribute.name === 'id' ? 'ngf-' + attribute.value : attribute.value);
}
}
}
Expand Down Expand Up @@ -1244,24 +1246,36 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct
}, /image/, this.imageDimensions, function (d, val) {
return d.width >= val;
})));
function ratioToFloat(val) {
var r = val, xIndex = r.search(/x/i);
if (xIndex > -1) {
r = parseFloat(r.substring(0, xIndex)) / parseFloat(r.substring(xIndex + 1));
} else {
r = parseFloat(r);
}
return r;
}
promises.push(upload.happyPromise(validateAsync('ratio', function (cons) {
return cons.ratio;
}, /image/, this.imageDimensions, function (d, val) {
var split = val.toString().split(','), valid = false;

for (var i = 0; i < split.length; i++) {
var r = split[i], xIndex = r.search(/x/i);
if (xIndex > -1) {
r = parseFloat(r.substring(0, xIndex)) / parseFloat(r.substring(xIndex + 1));
} else {
r = parseFloat(r);
}
if (Math.abs((d.width / d.height) - r) < 0.0001) {
if (Math.abs((d.width / d.height) - ratioToFloat(split[i])) < 0.0001) {
valid = true;
}
}
return valid;
})));
promises.push(upload.happyPromise(validateAsync('maxRatio', function (cons) {
return cons.ratio;
}, /image/, this.imageDimensions, function (d, val) {
return Math.abs((d.width / d.height) - ratioToFloat(val)) < 0.0001;
})));
promises.push(upload.happyPromise(validateAsync('minRatio', function (cons) {
return cons.ratio;
}, /image/, this.imageDimensions, function (d, val) {
return Math.abs((d.width / d.height) - ratioToFloat(val)) > -0.0001;
})));
promises.push(upload.happyPromise(validateAsync('maxDuration', function (cons) {
return cons.duration && cons.duration.max;
}, /audio|video/, this.mediaDuration, function (d, val) {
Expand Down Expand Up @@ -1916,7 +1930,7 @@ ngFileUpload.service('UploadExif', ['UploadResize', '$q', function (UploadResize
return;
}
if (angular.isString(orientation)) {
defer.reject(orientation);
defer.resolve(1);
} else {
file.$ngfOrientation = orientation;
defer.resolve(orientation);
Expand Down
4 changes: 2 additions & 2 deletions demo/src/main/webapp/js/ng-file-upload.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/FileAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@
return attr in input;
},

_support

/**
* FileAPI (core object)
*/
Expand Down
7 changes: 3 additions & 4 deletions dist/FileAPI.min.js

Large diffs are not rendered by default.

Loading

2 comments on commit f132a67

@piotrd
Copy link

@piotrd piotrd commented on f132a67 Nov 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed #1139, #1113, #1163, #1164, #1167

@danialfarid If I may have a request: would it be too much of a hassle if you made separate commits per each issue? I am trying to debug an issue after upgrading ng-file-upload to version with this commit (something related to #1139) and it's really hard to make out which change(s) is related to that :(

@danialfarid
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will try to do smaller commits.

Please sign in to comment.