-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
23 changed files
with
169 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,8 +275,6 @@ | |
return attr in input; | ||
}, | ||
|
||
_support | ||
|
||
/** | ||
* FileAPI (core object) | ||
*/ | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 10.0.2 | ||
* @version 10.0.3 | ||
*/ | ||
|
||
(function () { | ||
|
@@ -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 <[email protected]> | ||
* @version 10.0.2 | ||
* @version 10.0.3 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -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; | ||
|
@@ -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) { | ||
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
} | ||
} | ||
|
@@ -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) { | ||
|
@@ -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); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 10.0.2 | ||
* @version 10.0.3 | ||
*/ | ||
|
||
(function () { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
* @version 10.0.2 | ||
* @version 10.0.3 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -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; | ||
|
@@ -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) { | ||
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
} | ||
} | ||
|
@@ -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) { | ||
|
@@ -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); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,8 +275,6 @@ | |
return attr in input; | ||
}, | ||
|
||
_support | ||
|
||
/** | ||
* FileAPI (core object) | ||
*/ | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
f132a67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 :(
f132a67
There was a problem hiding this comment.
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.