-
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.
- Loading branch information
Danial Farid
authored and
Danial Farid
committed
Sep 25, 2015
1 parent
3ef6f80
commit 5b027c3
Showing
17 changed files
with
221 additions
and
116 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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 7.3.8 | ||
* @version 7.3.9 | ||
*/ | ||
|
||
(function () { | ||
|
@@ -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 <[email protected]> | ||
* @version 7.3.8 | ||
* @version 7.3.9 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -445,7 +445,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | |
|
||
var ngFileUpload = angular.module('ngFileUpload', []); | ||
|
||
ngFileUpload.version = '7.3.8'; | ||
ngFileUpload.version = '7.3.9'; | ||
|
||
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
var upload = this; | ||
|
@@ -1315,25 +1315,36 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
var upload = UploadDataUrl; | ||
|
||
function globStringToRegex(str) { | ||
var regexp = '', excludes = []; | ||
if (str.length > 2 && str[0] === '/' && str[str.length - 1] === '/') { | ||
return str.substring(1, str.length - 1); | ||
} | ||
var split = str.split(','), result = ''; | ||
if (split.length > 1) { | ||
for (var i = 0; i < split.length; i++) { | ||
result += '(' + globStringToRegex(split[i]) + ')'; | ||
if (i < split.length - 1) { | ||
result += '|'; | ||
} | ||
} | ||
regexp = str.substring(1, str.length - 1); | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
var split = str.split(','); | ||
if (split.length > 1) { | ||
for (var i = 0; i < split.length; i++) { | ||
var r = globStringToRegex(split[i]); | ||
if (r.regexp) { | ||
regexp += '(' + r.regexp + ')'; | ||
if (i < split.length - 1) { | ||
regexp += '|'; | ||
} | ||
} else { | ||
excludes = excludes.concat(r.excludes); | ||
} | ||
} | ||
} else { | ||
if (str.indexOf('!') === 0) { | ||
excludes.push('^((?!' + globStringToRegex(str.substring(1)).regexp + ').)*$'); | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
} | ||
regexp = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&') + '$'; | ||
regexp = regexp.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
return {regexp: regexp, excludes: excludes}; | ||
} | ||
|
||
upload.registerValidators = function (ngModel, elem, attr, scope) { | ||
|
@@ -1372,9 +1383,19 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
if (!val) { | ||
return true; | ||
} | ||
var regexp = new RegExp(globStringToRegex(val), 'gi'); | ||
return (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
var pattern = globStringToRegex(val), valid = true; | ||
if (pattern.regexp && pattern.regexp.length) { | ||
var regexp = new RegExp(pattern.regexp, 'i'); | ||
valid = (file.type != null && regexp.test(file.type)) || | ||
(file.name != null && regexp.test(file.name)); | ||
} | ||
var len = pattern.excludes.length; | ||
while (len--) { | ||
var exclude = new RegExp(pattern.excludes[len], 'i'); | ||
valid = valid && (file.type == null || exclude.test(file.type)) && | ||
(file.name == null || exclude.test(file.name)); | ||
} | ||
return valid; | ||
}; | ||
|
||
upload.validate = function (files, ngModel, attr, scope, later, callback) { | ||
|
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 7.3.8 | ||
* @version 7.3.9 | ||
*/ | ||
|
||
(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 7.3.8 | ||
* @version 7.3.9 | ||
*/ | ||
|
||
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 = '7.3.8'; | ||
ngFileUpload.version = '7.3.9'; | ||
|
||
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
var upload = this; | ||
|
@@ -893,25 +893,36 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
var upload = UploadDataUrl; | ||
|
||
function globStringToRegex(str) { | ||
var regexp = '', excludes = []; | ||
if (str.length > 2 && str[0] === '/' && str[str.length - 1] === '/') { | ||
return str.substring(1, str.length - 1); | ||
} | ||
var split = str.split(','), result = ''; | ||
if (split.length > 1) { | ||
for (var i = 0; i < split.length; i++) { | ||
result += '(' + globStringToRegex(split[i]) + ')'; | ||
if (i < split.length - 1) { | ||
result += '|'; | ||
} | ||
} | ||
regexp = str.substring(1, str.length - 1); | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
var split = str.split(','); | ||
if (split.length > 1) { | ||
for (var i = 0; i < split.length; i++) { | ||
var r = globStringToRegex(split[i]); | ||
if (r.regexp) { | ||
regexp += '(' + r.regexp + ')'; | ||
if (i < split.length - 1) { | ||
regexp += '|'; | ||
} | ||
} else { | ||
excludes = excludes.concat(r.excludes); | ||
} | ||
} | ||
} else { | ||
if (str.indexOf('!') === 0) { | ||
excludes.push('^((?!' + globStringToRegex(str.substring(1)).regexp + ').)*$'); | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
} | ||
regexp = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&') + '$'; | ||
regexp = regexp.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
return {regexp: regexp, excludes: excludes}; | ||
} | ||
|
||
upload.registerValidators = function (ngModel, elem, attr, scope) { | ||
|
@@ -950,9 +961,19 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
if (!val) { | ||
return true; | ||
} | ||
var regexp = new RegExp(globStringToRegex(val), 'gi'); | ||
return (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
var pattern = globStringToRegex(val), valid = true; | ||
if (pattern.regexp && pattern.regexp.length) { | ||
var regexp = new RegExp(pattern.regexp, 'i'); | ||
valid = (file.type != null && regexp.test(file.type)) || | ||
(file.name != null && regexp.test(file.name)); | ||
} | ||
var len = pattern.excludes.length; | ||
while (len--) { | ||
var exclude = new RegExp(pattern.excludes[len], 'i'); | ||
valid = valid && (file.type == null || exclude.test(file.type)) && | ||
(file.name == null || exclude.test(file.name)); | ||
} | ||
return valid; | ||
}; | ||
|
||
upload.validate = function (files, ngModel, attr, scope, later, callback) { | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -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 7.3.8 | ||
* @version 7.3.9 | ||
*/ | ||
|
||
(function () { | ||
|
@@ -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 <[email protected]> | ||
* @version 7.3.8 | ||
* @version 7.3.9 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -445,7 +445,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | |
|
||
var ngFileUpload = angular.module('ngFileUpload', []); | ||
|
||
ngFileUpload.version = '7.3.8'; | ||
ngFileUpload.version = '7.3.9'; | ||
|
||
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
var upload = this; | ||
|
@@ -1315,25 +1315,36 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
var upload = UploadDataUrl; | ||
|
||
function globStringToRegex(str) { | ||
var regexp = '', excludes = []; | ||
if (str.length > 2 && str[0] === '/' && str[str.length - 1] === '/') { | ||
return str.substring(1, str.length - 1); | ||
} | ||
var split = str.split(','), result = ''; | ||
if (split.length > 1) { | ||
for (var i = 0; i < split.length; i++) { | ||
result += '(' + globStringToRegex(split[i]) + ')'; | ||
if (i < split.length - 1) { | ||
result += '|'; | ||
} | ||
} | ||
regexp = str.substring(1, str.length - 1); | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
var split = str.split(','); | ||
if (split.length > 1) { | ||
for (var i = 0; i < split.length; i++) { | ||
var r = globStringToRegex(split[i]); | ||
if (r.regexp) { | ||
regexp += '(' + r.regexp + ')'; | ||
if (i < split.length - 1) { | ||
regexp += '|'; | ||
} | ||
} else { | ||
excludes = excludes.concat(r.excludes); | ||
} | ||
} | ||
} else { | ||
if (str.indexOf('!') === 0) { | ||
excludes.push('^((?!' + globStringToRegex(str.substring(1)).regexp + ').)*$'); | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
} | ||
regexp = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&') + '$'; | ||
regexp = regexp.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
return {regexp: regexp, excludes: excludes}; | ||
} | ||
|
||
upload.registerValidators = function (ngModel, elem, attr, scope) { | ||
|
@@ -1372,9 +1383,19 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct | |
if (!val) { | ||
return true; | ||
} | ||
var regexp = new RegExp(globStringToRegex(val), 'gi'); | ||
return (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
var pattern = globStringToRegex(val), valid = true; | ||
if (pattern.regexp && pattern.regexp.length) { | ||
var regexp = new RegExp(pattern.regexp, 'i'); | ||
valid = (file.type != null && regexp.test(file.type)) || | ||
(file.name != null && regexp.test(file.name)); | ||
} | ||
var len = pattern.excludes.length; | ||
while (len--) { | ||
var exclude = new RegExp(pattern.excludes[len], 'i'); | ||
valid = valid && (file.type == null || exclude.test(file.type)) && | ||
(file.name == null || exclude.test(file.name)); | ||
} | ||
return valid; | ||
}; | ||
|
||
upload.validate = function (files, ngModel, attr, scope, later, callback) { | ||
|
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 7.3.8 | ||
* @version 7.3.9 | ||
*/ | ||
|
||
(function () { | ||
|
Oops, something went wrong.