ng-file-upload
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -1,2 +0,2 @@ | ||
/*! 5.0.0 */ | ||
/*! 5.0.1 */ | ||
/*! FileAPI 2.0.7 - BSD | git://github.com/mailru/FileAPI.git | ||
@@ -3,0 +3,0 @@ * FileAPI — a set of javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF. |
/**! | ||
* AngularJS file upload/drop directive and service with progress and abort | ||
* @author Danial <danial.farid@gmail.com> | ||
* @version 5.0.0 | ||
* @version 5.0.1 | ||
*/ | ||
var ngFileUpload = angular.module('ngFileUpload', []); | ||
ngFileUpload.version = '5.0.0'; | ||
ngFileUpload.version = '5.0.1'; | ||
ngFileUpload.service('Upload', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
@@ -34,3 +34,4 @@ function patchXHR(fnName, newFn) { | ||
var deferred = $q.defer(); | ||
var deferred = | ||
$q.defer(); | ||
var promise = deferred.promise; | ||
@@ -208,262 +209,262 @@ | ||
(function () { | ||
ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', | ||
function ($parse, $timeout, $compile) { | ||
return { | ||
restrict: 'AEC', | ||
require: '?ngModel', | ||
link: function (scope, elem, attr, ngModel) { | ||
linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile); | ||
} | ||
}; | ||
}]); | ||
ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', | ||
function ($parse, $timeout, $compile) { | ||
return { | ||
restrict: 'AEC', | ||
require: '?ngModel', | ||
link: function (scope, elem, attr, ngModel) { | ||
linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile); | ||
} | ||
}; | ||
}]); | ||
function linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) { | ||
/** @namespace attr.ngfSelect */ | ||
/** @namespace attr.ngfChange */ | ||
/** @namespace attr.ngModel */ | ||
/** @namespace attr.ngModelRejected */ | ||
/** @namespace attr.ngfMultiple */ | ||
/** @namespace attr.ngfCapture */ | ||
/** @namespace attr.ngfAccept */ | ||
/** @namespace attr.ngfMaxSize */ | ||
/** @namespace attr.ngfMinSize */ | ||
/** @namespace attr.ngfResetOnClick */ | ||
/** @namespace attr.ngfResetModelOnClick */ | ||
/** @namespace attr.ngfKeep */ | ||
/** @namespace attr.ngfKeepDistinct */ | ||
function linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) { | ||
/** @namespace attr.ngfSelect */ | ||
/** @namespace attr.ngfChange */ | ||
/** @namespace attr.ngModel */ | ||
/** @namespace attr.ngModelRejected */ | ||
/** @namespace attr.ngfMultiple */ | ||
/** @namespace attr.ngfCapture */ | ||
/** @namespace attr.ngfAccept */ | ||
/** @namespace attr.ngfMaxSize */ | ||
/** @namespace attr.ngfMinSize */ | ||
/** @namespace attr.ngfResetOnClick */ | ||
/** @namespace attr.ngfResetModelOnClick */ | ||
/** @namespace attr.ngfKeep */ | ||
/** @namespace attr.ngfKeepDistinct */ | ||
if (elem.attr('__ngf_gen__')) { | ||
return; | ||
} | ||
if (elem.attr('__ngf_gen__')) { | ||
return; | ||
} | ||
scope.$on('$destroy', function () { | ||
if (elem.$$ngfRefElem) elem.$$ngfRefElem.remove(); | ||
}); | ||
scope.$on('$destroy', function () { | ||
if (elem.$$ngfRefElem) elem.$$ngfRefElem.remove(); | ||
}); | ||
var disabled = false; | ||
if (attr.ngfSelect.search(/\W+$files\W+/) === -1) { | ||
scope.$watch(attr.ngfSelect, function (val) { | ||
disabled = val === false; | ||
}); | ||
} | ||
function isInputTypeFile() { | ||
return elem[0].tagName.toLowerCase() === 'input' && attr.type && attr.type.toLowerCase() === 'file'; | ||
} | ||
var disabled = false; | ||
if (attr.ngfSelect.search(/\W+$files\W+/) === -1) { | ||
scope.$watch(attr.ngfSelect, function (val) { | ||
disabled = val === false; | ||
}); | ||
} | ||
function isInputTypeFile() { | ||
return elem[0].tagName.toLowerCase() === 'input' && attr.type && attr.type.toLowerCase() === 'file'; | ||
} | ||
var isUpdating = false; | ||
var isUpdating = false; | ||
function changeFn(evt) { | ||
if (!isUpdating) { | ||
isUpdating = true; | ||
try { | ||
var fileList = evt.__files_ || (evt.target && evt.target.files); | ||
var files = [], rejFiles = []; | ||
function changeFn(evt) { | ||
if (!isUpdating) { | ||
isUpdating = true; | ||
try { | ||
var fileList = evt.__files_ || (evt.target && evt.target.files); | ||
var files = [], rejFiles = []; | ||
for (var i = 0; i < fileList.length; i++) { | ||
var file = fileList.item(i); | ||
if (validate(scope, $parse, attr, file, evt)) { | ||
files.push(file); | ||
} else { | ||
rejFiles.push(file); | ||
} | ||
} | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, files, rejFiles, evt); | ||
if (files.length === 0) evt.target.value = files; | ||
for (var i = 0; i < fileList.length; i++) { | ||
var file = fileList.item(i); | ||
if (validate(scope, $parse, attr, file, evt)) { | ||
files.push(file); | ||
} else { | ||
rejFiles.push(file); | ||
} | ||
} | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, files, rejFiles, evt); | ||
if (files.length === 0) evt.target.value = files; | ||
// if (evt.target && evt.target.getAttribute('__ngf_gen__')) { | ||
// angular.element(evt.target).remove(); | ||
// } | ||
} finally { | ||
isUpdating = false; | ||
} finally { | ||
isUpdating = false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function bindAttrToFileInput(fileElem) { | ||
if (attr.ngfMultiple) fileElem.attr('multiple', $parse(attr.ngfMultiple)(scope)); | ||
if (attr.ngfCapture) fileElem.attr('capture', $parse(attr.ngfCapture)(scope)); | ||
if (attr.accept) fileElem.attr('accept', attr.accept); | ||
for (var i = 0; i < elem[0].attributes.length; i++) { | ||
var attribute = elem[0].attributes[i]; | ||
if ((isInputTypeFile() && attribute.name !== 'type') || | ||
(attribute.name !== 'type' && attribute.name !== 'class' && | ||
attribute.name !== 'id' && attribute.name !== 'style')) { | ||
fileElem.attr(attribute.name, attribute.value); | ||
function bindAttrToFileInput(fileElem) { | ||
if (attr.ngfMultiple) fileElem.attr('multiple', $parse(attr.ngfMultiple)(scope)); | ||
if (attr.ngfCapture) fileElem.attr('capture', $parse(attr.ngfCapture)(scope)); | ||
if (attr.accept) fileElem.attr('accept', attr.accept); | ||
for (var i = 0; i < elem[0].attributes.length; i++) { | ||
var attribute = elem[0].attributes[i]; | ||
if ((isInputTypeFile() && attribute.name !== 'type') || | ||
(attribute.name !== 'type' && attribute.name !== 'class' && | ||
attribute.name !== 'id' && attribute.name !== 'style')) { | ||
fileElem.attr(attribute.name, attribute.value); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function createFileInput(evt, resetOnClick) { | ||
if (elem.attr('disabled') || disabled) return; | ||
function createFileInput(evt, resetOnClick) { | ||
if (elem.attr('disabled') || disabled) return; | ||
if (!resetOnClick && (evt || isInputTypeFile())) return elem.$$ngfRefElem || elem; | ||
if (!resetOnClick && (evt || isInputTypeFile())) return elem.$$ngfRefElem || elem; | ||
var fileElem = angular.element('<input type="file">'); | ||
bindAttrToFileInput(fileElem); | ||
var fileElem = angular.element('<input type="file">'); | ||
bindAttrToFileInput(fileElem); | ||
if (isInputTypeFile()) { | ||
elem.replaceWith(fileElem); | ||
elem = fileElem; | ||
fileElem.attr('__ngf_gen__', true); | ||
$compile(elem)(scope); | ||
} else { | ||
fileElem.css('visibility', 'hidden').css('position', 'absolute') | ||
.css('width', '9').css('height', '1').css('z-index', '-100000') | ||
.attr('tabindex', '-1'); | ||
if (elem.$$ngfRefElem) { | ||
elem.$$ngfRefElem.remove(); | ||
if (isInputTypeFile()) { | ||
elem.replaceWith(fileElem); | ||
elem = fileElem; | ||
fileElem.attr('__ngf_gen__', true); | ||
$compile(elem)(scope); | ||
} else { | ||
fileElem.css('visibility', 'hidden').css('position', 'absolute') | ||
.css('width', '9').css('height', '1').css('z-index', '-100000') | ||
.attr('tabindex', '-1'); | ||
if (elem.$$ngfRefElem) { | ||
elem.$$ngfRefElem.remove(); | ||
} | ||
elem.$$ngfRefElem = fileElem; | ||
document.body.appendChild(fileElem[0]); | ||
} | ||
return fileElem; | ||
} | ||
elem.$$ngfRefElem = fileElem; | ||
document.body.appendChild(fileElem[0]); | ||
} | ||
return fileElem; | ||
} | ||
function resetModel(evt) { | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, [], [], evt, true); | ||
} | ||
function resetModel(evt) { | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, [], [], evt, true); | ||
} | ||
function clickHandler(evt) { | ||
if (evt != null) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var resetOnClick = $parse(attr.ngfResetOnClick)(scope) !== false; | ||
var fileElem = createFileInput(evt, resetOnClick); | ||
function clickHandler(evt) { | ||
if (evt != null) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var resetOnClick = $parse(attr.ngfResetOnClick)(scope) !== false; | ||
var fileElem = createFileInput(evt, resetOnClick); | ||
function clickAndAssign(evt) { | ||
if (evt) { | ||
fileElem[0].click(); | ||
} | ||
if (isInputTypeFile() || !evt) { | ||
elem.bind('click touchend', clickHandler); | ||
} | ||
} | ||
function clickAndAssign(evt) { | ||
if (evt) { | ||
fileElem[0].click(); | ||
if (fileElem) { | ||
if (!evt || resetOnClick) fileElem.bind('change', changeFn); | ||
if (evt && resetOnClick && $parse(attr.ngfResetModelOnClick)(scope) !== false) resetModel(evt); | ||
// fix for android native browser < 4.4 | ||
if (isAndroidBelow44(navigator.userAgent)) { | ||
setTimeout(function () { | ||
clickAndAssign(evt); | ||
}, 0); | ||
} else { | ||
clickAndAssign(evt); | ||
} | ||
} | ||
return false; | ||
} | ||
if (isInputTypeFile() || !evt) { | ||
elem.bind('click touchend', clickHandler); | ||
} | ||
} | ||
if (fileElem) { | ||
if (!evt || resetOnClick) fileElem.bind('change', changeFn); | ||
if (evt && resetOnClick && $parse(attr.ngfResetModelOnClick)(scope) !== false) resetModel(evt); | ||
// fix for android native browser < 4.4 | ||
if (isAndroidBelow44()) { | ||
setTimeout(function () { | ||
clickAndAssign(evt); | ||
}, 0); | ||
if (window.FileAPI && window.FileAPI.ngfFixIE) { | ||
window.FileAPI.ngfFixIE(elem, createFileInput, bindAttrToFileInput, changeFn); | ||
} else { | ||
clickAndAssign(evt); | ||
clickHandler(); | ||
//if (!isInputTypeFile()) { | ||
// elem.bind('click touchend', clickHandler); | ||
//} | ||
} | ||
} | ||
return false; | ||
} | ||
if (window.FileAPI && window.FileAPI.ngfFixIE) { | ||
window.FileAPI.ngfFixIE(elem, createFileInput, bindAttrToFileInput, changeFn); | ||
} else { | ||
clickHandler(); | ||
//if (!isInputTypeFile()) { | ||
// elem.bind('click touchend', clickHandler); | ||
//} | ||
} | ||
} | ||
function isAndroidBelow44(ua) { | ||
var m = ua.match(/Android[^\d]*(\d+)\.(\d+)/); | ||
if (m && m.length > 2) { | ||
return parseInt(m[1]) < 4 || (parseInt(m[1]) === 4 && parseInt(m[2]) < 4); | ||
} | ||
function isAndroidBelow44() { | ||
var match = navigator.userAgent.toLowerCase().match(/android[^\d]*(\d|.)/); | ||
if (match) { | ||
var version = match[0].split('.'); | ||
return version[0] < '4' || (version[0] === '4' && version[1] < '4'); | ||
return false; | ||
} | ||
return false; | ||
} | ||
ngFileUpload.validate = function (scope, $parse, attr, file, evt) { | ||
function globStringToRegex(str) { | ||
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 += '|'; | ||
} | ||
ngFileUpload.validate = function (scope, $parse, attr, file, evt) { | ||
function globStringToRegex(str) { | ||
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 += '|'; | ||
} | ||
} | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
} | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
var accept = $parse(attr.ngfAccept)(scope, {$file: file, $event: evt}); | ||
var fileSizeMax = $parse(attr.ngfMaxSize)(scope, {$file: file, $event: evt}) || 9007199254740991; | ||
var fileSizeMin = $parse(attr.ngfMinSize)(scope, {$file: file, $event: evt}) || -1; | ||
if (accept != null && angular.isString(accept)) { | ||
var regexp = new RegExp(globStringToRegex(accept), 'gi'); | ||
accept = (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
} | ||
return (accept == null || accept) && (file.size == null || (file.size < fileSizeMax && file.size > fileSizeMin)); | ||
}; | ||
var accept = $parse(attr.ngfAccept)(scope, {$file: file, $event: evt}); | ||
var fileSizeMax = $parse(attr.ngfMaxSize)(scope, {$file: file, $event: evt}) || 9007199254740991; | ||
var fileSizeMin = $parse(attr.ngfMinSize)(scope, {$file: file, $event: evt}) || -1; | ||
if (accept != null && angular.isString(accept)) { | ||
var regexp = new RegExp(globStringToRegex(accept), 'gi'); | ||
accept = (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
} | ||
return (accept == null || accept) && (file.size == null || (file.size < fileSizeMax && file.size > fileSizeMin)); | ||
}; | ||
ngFileUpload.updateModel = function ($parse, $timeout, scope, ngModel, attr, fileChange, | ||
files, rejFiles, evt, noDelay) { | ||
function update() { | ||
if ($parse(attr.ngfKeep)(scope) === true) { | ||
if (!files || !files.length) { | ||
return; | ||
} | ||
if ($parse(attr.ngfKeepDistinct)(scope) === true) { | ||
var prevFiles = (ngModel.$modelValue || []).slice(0), len = prevFiles.length; | ||
for (var i = 0; i < files.length; i++) { | ||
for (var j = 0; j < len; j++) { | ||
if (files[i].name === prevFiles[j].name) break; | ||
ngFileUpload.updateModel = function ($parse, $timeout, scope, ngModel, attr, fileChange, | ||
files, rejFiles, evt, noDelay) { | ||
function update() { | ||
if ($parse(attr.ngfKeep)(scope) === true) { | ||
if (!files || !files.length) { | ||
return; | ||
} | ||
if ($parse(attr.ngfKeepDistinct)(scope) === true) { | ||
var prevFiles = (ngModel.$modelValue || []).slice(0), len = prevFiles.length; | ||
for (var i = 0; i < files.length; i++) { | ||
for (var j = 0; j < len; j++) { | ||
if (files[i].name === prevFiles[j].name) break; | ||
} | ||
if (j === len) { | ||
prevFiles.push(files[i]); | ||
} | ||
} | ||
if (len === prevFiles.length) { | ||
return; | ||
} | ||
files = [].concat(prevFiles); | ||
} else { | ||
files = (ngModel.$modelValue || []).concat(files); | ||
} | ||
} | ||
if (j === len) { | ||
prevFiles.push(files[i]); | ||
if (ngModel) { | ||
$parse(attr.ngModel).assign(scope, files); | ||
$timeout(function () { | ||
if (ngModel) { | ||
ngModel.$setViewValue(files != null && files.length === 0 ? null : files); | ||
} | ||
}); | ||
} | ||
} | ||
if (len === prevFiles.length) { | ||
return; | ||
} | ||
files = [].concat(prevFiles); | ||
if (attr.ngModelRejected) { | ||
$parse(attr.ngModelRejected).assign(scope, rejFiles); | ||
} | ||
if (fileChange) { | ||
$parse(fileChange)(scope, { | ||
$files: files, | ||
$rejectedFiles: rejFiles, | ||
$event: evt | ||
}); | ||
} | ||
} | ||
if (noDelay) { | ||
update(); | ||
} else { | ||
files = (ngModel.$modelValue || []).concat(files); | ||
$timeout(function () { | ||
update(); | ||
}); | ||
} | ||
} | ||
if (ngModel) { | ||
$parse(attr.ngModel).assign(scope, files); | ||
$timeout(function () { | ||
if (ngModel) { | ||
ngModel.$setViewValue(files != null && files.length === 0 ? null : files); | ||
} | ||
}); | ||
} | ||
if (attr.ngModelRejected) { | ||
$parse(attr.ngModelRejected).assign(scope, rejFiles); | ||
} | ||
if (fileChange) { | ||
$parse(fileChange)(scope, { | ||
$files: files, | ||
$rejectedFiles: rejFiles, | ||
$event: evt | ||
}); | ||
} | ||
} | ||
}; | ||
if (noDelay) { | ||
update(); | ||
} else { | ||
$timeout(function () { | ||
update(); | ||
}); | ||
} | ||
}; | ||
var validate = ngFileUpload.validate; | ||
var updateModel = ngFileUpload.updateModel; | ||
var validate = ngFileUpload.validate; | ||
var updateModel = ngFileUpload.updateModel; | ||
})(); | ||
@@ -743,3 +744,3 @@ | ||
* @author Danial <danial.farid@gmail.com> | ||
* @version 5.0.0 | ||
* @version 5.0.1 | ||
*/ | ||
@@ -977,8 +978,12 @@ | ||
function getOffset(obj) { | ||
var left, top; | ||
left = top = 0; | ||
var left = 0, top = 0; | ||
if (window.jQuery) { | ||
return jQuery(obj).offset(); | ||
} | ||
if (obj.offsetParent) { | ||
do { | ||
left += obj.offsetLeft; | ||
top += obj.offsetTop; | ||
left += (obj.offsetLeft - obj.scrollLeft); | ||
top += (obj.offsetTop - obj.scrollTop); | ||
obj = obj.offsetParent; | ||
@@ -985,0 +990,0 @@ } while (obj); |
@@ -1,2 +0,2 @@ | ||
/*! 5.0.0 */ | ||
var ngFileUpload=angular.module("ngFileUpload",[]);ngFileUpload.version="5.0.0",ngFileUpload.service("Upload",["$http","$q","$timeout",function(a,b,c){function d(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function e(d){d.method=d.method||"POST",d.headers=d.headers||{};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progressFunc=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&d("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}}),this.upload=function(a){function b(c,d,e){if(void 0!==d)if(angular.isDate(d)&&(d=d.toISOString()),angular.isString(d))c.append(e,d);else if("form"===a.sendFieldsAs)if(angular.isObject(d))for(var f in d)d.hasOwnProperty(f)&&b(c,d[f],e+"["+f+"]");else c.append(e,d);else d=angular.isString(d)?d:JSON.stringify(d),"json-blob"===a.sendFieldsAs?c.append(e,new Blob([d],{type:"application/json"})):c.append(e,d)}return a.headers=a.headers||{},a.headers["Content-Type"]=void 0,a.transformRequest=a.transformRequest?angular.isArray(a.transformRequest)?a.transformRequest:[a.transformRequest]:[],a.transformRequest.push(function(c){var d,e=new FormData,f={};for(d in a.fields)a.fields.hasOwnProperty(d)&&(f[d]=a.fields[d]);c&&(f.data=c);for(d in f)if(f.hasOwnProperty(d)){var g=f[d];a.formDataAppender?a.formDataAppender(e,d,g):b(e,g,d)}if(null!=a.file){var h=a.fileFormDataName||"file";if(angular.isArray(a.file))for(var i=angular.isString(h),j=0;j<a.file.length;j++)e.append(i?h:h[j],a.file[j],a.fileName&&a.fileName[j]||a.file[j].name);else e.append(h,a.file,a.fileName||a.file.name)}return e}),e(a)},this.http=function(b){return b.transformRequest=b.transformRequest||function(b){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](arguments)},e(b)}}]),function(){function a(a,e,f,g,h,i,j){function k(){return"input"===e[0].tagName.toLowerCase()&&f.type&&"file"===f.type.toLowerCase()}function l(b){if(!r){r=!0;try{for(var e=b.__files_||b.target&&b.target.files,j=[],k=[],l=0;l<e.length;l++){var m=e.item(l);c(a,h,f,m,b)?j.push(m):k.push(m)}d(h,i,a,g,f,f.ngfChange||f.ngfSelect,j,k,b),0===j.length&&(b.target.value=j)}finally{r=!1}}}function m(b){f.ngfMultiple&&b.attr("multiple",h(f.ngfMultiple)(a)),f.ngfCapture&&b.attr("capture",h(f.ngfCapture)(a)),f.accept&&b.attr("accept",f.accept);for(var c=0;c<e[0].attributes.length;c++){var d=e[0].attributes[c];(k()&&"type"!==d.name||"type"!==d.name&&"class"!==d.name&&"id"!==d.name&&"style"!==d.name)&&b.attr(d.name,d.value)}}function n(b,c){if(!e.attr("disabled")&&!q){if(!c&&(b||k()))return e.$$ngfRefElem||e;var d=angular.element('<input type="file">');return m(d),k()?(e.replaceWith(d),e=d,d.attr("__ngf_gen__",!0),j(e)(a)):(d.css("visibility","hidden").css("position","absolute").css("width","9").css("height","1").css("z-index","-100000").attr("tabindex","-1"),e.$$ngfRefElem&&e.$$ngfRefElem.remove(),e.$$ngfRefElem=d,document.body.appendChild(d[0])),d}}function o(b){d(h,i,a,g,f,f.ngfChange||f.ngfSelect,[],[],b,!0)}function p(c){function d(a){a&&i[0].click(),(k()||!a)&&e.bind("click touchend",p)}null!=c&&(c.preventDefault(),c.stopPropagation());var g=h(f.ngfResetOnClick)(a)!==!1,i=n(c,g);return i&&((!c||g)&&i.bind("change",l),c&&g&&h(f.ngfResetModelOnClick)(a)!==!1&&o(c),b()?setTimeout(function(){d(c)},0):d(c)),!1}if(!e.attr("__ngf_gen__")){a.$on("$destroy",function(){e.$$ngfRefElem&&e.$$ngfRefElem.remove()});var q=!1;-1===f.ngfSelect.search(/\W+$files\W+/)&&a.$watch(f.ngfSelect,function(a){q=a===!1});var r=!1;window.FileAPI&&window.FileAPI.ngfFixIE?window.FileAPI.ngfFixIE(e,n,m,l):p()}}function b(){var a=navigator.userAgent.toLowerCase().match(/android[^\d]*(\d|.)/);if(a){var b=a[0].split(".");return b[0]<"4"||"4"===b[0]&&b[1]<"4"}return!1}ngFileUpload.directive("ngfSelect",["$parse","$timeout","$compile",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.validate=function(a,b,c,d,e){function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d<b.length;d++)c+="("+f(b[d])+")",d<b.length-1&&(c+="|");else 0===a.indexOf(".")&&(a="*"+a),c="^"+a.replace(new RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}var g=b(c.ngfAccept)(a,{$file:d,$event:e}),h=b(c.ngfMaxSize)(a,{$file:d,$event:e})||9007199254740991,i=b(c.ngfMinSize)(a,{$file:d,$event:e})||-1;if(null!=g&&angular.isString(g)){var j=new RegExp(f(g),"gi");g=null!=d.type&&j.test(d.type.toLowerCase())||null!=d.name&&j.test(d.name.toLowerCase())}return(null==g||g)&&(null==d.size||d.size<h&&d.size>i)},ngFileUpload.updateModel=function(a,b,c,d,e,f,g,h,i,j){function k(){if(a(e.ngfKeep)(c)===!0){if(!g||!g.length)return;if(a(e.ngfKeepDistinct)(c)===!0){for(var j=(d.$modelValue||[]).slice(0),k=j.length,l=0;l<g.length;l++){for(var m=0;k>m&&g[l].name!==j[m].name;m++);m===k&&j.push(g[l])}if(k===j.length)return;g=[].concat(j)}else g=(d.$modelValue||[]).concat(g)}d&&(a(e.ngModel).assign(c,g),b(function(){d&&d.$setViewValue(null!=g&&0===g.length?null:g)})),e.ngModelRejected&&a(e.ngModelRejected).assign(c,h),f&&a(f)(c,{$files:g,$rejectedFiles:h,$event:i})}j?k():b(function(){k()})};var c=ngFileUpload.validate,d=ngFileUpload.updateModel}(),function(){function a(a,e,f,g,h,i,j){function k(a,b,d){var e=!0,f=d.dataTransfer.items;if(null!=f)for(var g=0;g<f.length&&e;g++)e=e&&("file"===f[g].kind||""===f[g].kind)&&c(a,h,b,f[g],d);var i=h(b.ngfDragOverClass)(a,{$event:d});return i&&(i.delay&&(r=i.delay),i.accept&&(i=e?i.accept:i.reject)),i||b.ngfDragOverClass||"dragover"}function l(b,d,e,g){function k(d){c(a,h,f,d,b)?m.push(d):n.push(d)}function l(a,b,c){if(null!=b)if(b.isDirectory){var d=(c||"")+b.name;k({name:b.name,type:"directory",path:d});var e=b.createReader(),f=[];p++;var g=function(){e.readEntries(function(d){try{if(d.length)f=f.concat(Array.prototype.slice.call(d||[],0)),g();else{for(var e=0;e<f.length;e++)l(a,f[e],(c?c:"")+b.name+"/");p--}}catch(h){p--,console.error(h)}},function(){p--})};g()}else p++,b.file(function(a){try{p--,a.path=(c?c:"")+a.name,k(a)}catch(b){p--,console.error(b)}},function(){p--})}var m=[],n=[],o=b.dataTransfer.items,p=0;if(o&&o.length>0&&"file"!==j.protocol())for(var q=0;q<o.length;q++){if(o[q].webkitGetAsEntry&&o[q].webkitGetAsEntry()&&o[q].webkitGetAsEntry().isDirectory){var r=o[q].webkitGetAsEntry();if(r.isDirectory&&!e)continue;null!=r&&l(m,r)}else{var s=o[q].getAsFile();null!=s&&k(s)}if(!g&&m.length>0)break}else{var t=b.dataTransfer.files;if(null!=t)for(var u=0;u<t.length&&(k(t.item(u)),g||!(m.length>0));u++);}var v=0;!function w(a){i(function(){if(p)10*v++<2e4&&w(10);else{if(!g&&m.length>1){for(q=0;"directory"===m[q].type;)q++;m=[m[q]]}d(m,n)}},a||0)}()}var m=b();if(f.dropAvailable&&i(function(){a[f.dropAvailable]?a[f.dropAvailable].value=m:a[f.dropAvailable]=m}),!m)return void(h(f.ngfHideOnDropNotAvailable)(a)===!0&&e.css("display","none"));var n=!1;-1===f.ngfDrop.search(/\W+$files\W+/)&&a.$watch(f.ngfDrop,function(a){n=a===!1});var o,p=null,q=h(f.ngfStopPropagation),r=1;e[0].addEventListener("dragover",function(b){if(!e.attr("disabled")&&!n){if(b.preventDefault(),q(a)&&b.stopPropagation(),navigator.userAgent.indexOf("Chrome")>-1){var c=b.dataTransfer.effectAllowed;b.dataTransfer.dropEffect="move"===c||"linkMove"===c?"move":"copy"}i.cancel(p),a.actualDragOverClass||(o=k(a,f,b)),e.addClass(o)}},!1),e[0].addEventListener("dragenter",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation())},!1),e[0].addEventListener("dragleave",function(){e.attr("disabled")||n||(p=i(function(){e.removeClass(o),o=null},r||1))},!1),e[0].addEventListener("drop",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation(),e.removeClass(o),o=null,l(b,function(c,e){d(h,i,a,g,f,f.ngfChange||f.ngfDrop,c,e,b)},h(f.ngfAllowDir)(a)!==!1,f.multiple||h(f.ngfMultiple)(a)))},!1)}function b(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}var c=ngFileUpload.validate,d=ngFileUpload.updateModel;ngFileUpload.directive("ngfDrop",["$parse","$timeout","$location",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.directive("ngfNoFileDrop",function(){return function(a,c){b()&&c.css("display","none")}}),ngFileUpload.directive("ngfDropAvailable",["$parse","$timeout",function(a,c){return function(d,e,f){if(b()){var g=a(f.ngfDropAvailable);c(function(){g(d),g.assign&&g.assign(d,!0)})}}}]),ngFileUpload.directive("ngfSrc",["$parse","$timeout",function(a,b){return{restrict:"AE",link:function(d,e,f){window.FileReader&&d.$watch(f.ngfSrc,function(g){g&&c(d,a,f,g,null)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 8")||g.size<2e4)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 9")||g.size<4e6)?b(function(){var a=window.URL||window.webkitURL;if(a&&a.createObjectURL)e.attr("src",a.createObjectURL(g));else{var c=new FileReader;c.readAsDataURL(g),c.onload=function(a){b(function(){e.attr("src",a.target.result)})}}}):e.attr("src",f.ngfDefaultSrc||"")})}}}])}(),function(){function a(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function b(a,b,c){try{Object.defineProperty(a,b,{get:c})}catch(d){}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){var c=function(a){if(!a.__listeners){a.upload||(a.upload={}),a.__listeners=[];var b=a.upload.addEventListener;a.upload.addEventListener=function(c,d){a.__listeners[c]=d,b&&b.apply(this,arguments)}}};a("open",function(a){return function(b,d,e){c(this),this.__url=d;try{a.apply(this,[b,d,e])}catch(f){f.message.indexOf("Access is denied")>-1&&(this.__origError=f,a.apply(this,[b,"_fix_for_ie_crossdomain__",e]))}}}),a("getResponseHeader",function(a){return function(b){return this.__fileApiXHR&&this.__fileApiXHR.getResponseHeader?this.__fileApiXHR.getResponseHeader(b):null==a?null:a.apply(this,[b])}}),a("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.getAllResponseHeaders?this.__fileApiXHR.getAllResponseHeaders():null==a?null:a.apply(this)}}),a("abort",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.abort?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),a("setRequestHeader",function(a){return function(b,d){if("__setXHR_"===b){c(this);var e=d(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[b]=d,a.apply(this,arguments)}}),a("send",function(a){return function(){var c=this;if(arguments[0]&&arguments[0].__isFileAPIShim){var d=arguments[0],e={url:c.__url,jsonp:!1,cache:!0,complete:function(a,d){c.__completed=!0,!a&&c.__listeners.load&&c.__listeners.load({type:"load",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),!a&&c.__listeners.loadend&&c.__listeners.loadend({type:"loadend",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),"abort"===a&&c.__listeners.abort&&c.__listeners.abort({type:"abort",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),void 0!==d.status&&b(c,"status",function(){return 0===d.status&&a&&"abort"!==a?500:d.status}),void 0!==d.statusText&&b(c,"statusText",function(){return d.statusText}),b(c,"readyState",function(){return 4}),void 0!==d.response&&b(c,"response",function(){return d.response});var e=d.responseText||(a&&0===d.status&&"abort"!==a?a:void 0);b(c,"responseText",function(){return e}),b(c,"response",function(){return e}),a&&b(c,"err",function(){return a}),c.__fileApiXHR=d,c.onreadystatechange&&c.onreadystatechange(),c.onload&&c.onload()},progress:function(a){if(a.target=c,c.__listeners.progress&&c.__listeners.progress(a),c.__total=a.total,c.__loaded=a.loaded,a.total===a.loaded){var b=this;setTimeout(function(){c.__completed||(c.getAllResponseHeaders=function(){},b.complete(null,{status:204,statusText:"No Content"}))},FileAPI.noContentTimeout||1e4)}},headers:c.__requestHeaders};e.data={},e.files={};for(var f=0;f<d.data.length;f++){var g=d.data[f];null!=g.val&&null!=g.val.name&&null!=g.val.size&&null!=g.val.type?e.files[g.key]=g.val:e.data[g.key]=g.val}setTimeout(function(){if(!FileAPI.hasFlash)throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';c.__fileApiXHR=FileAPI.upload(e)},1)}else{if(this.__origError)throw this.__origError;a.apply(c,arguments)}}}),window.XMLHttpRequest.__isFileAPIShim=!0,window.FormData=FormData=function(){return{append:function(a,b,c){b.__isFileAPIBlobShim&&(b=b.data[0]),this.data.push({key:a,val:b,name:c})},data:[],__isFileAPIShim:!0}},window.Blob=Blob=function(a){return{data:a,__isFileAPIBlobShim:!0}}}}(),function(){function a(a){return"input"===a[0].tagName.toLowerCase()&&a.attr("type")&&"file"===a.attr("type").toLowerCase()}function b(){try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if(a)return!0}catch(b){if(void 0!==navigator.mimeTypes["application/x-shockwave-flash"])return!0}return!1}function c(a){var b,c;if(b=c=0,a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop,a=a.offsetParent;while(a);return{left:b,top:c}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){if(window.FileAPI||(window.FileAPI={}),FileAPI.forceLoad&&(FileAPI.html5=!1),!FileAPI.upload){var d,e,f,g,h,i=document.createElement("script"),j=document.getElementsByTagName("script");if(window.FileAPI.jsUrl)d=window.FileAPI.jsUrl;else if(window.FileAPI.jsPath)e=window.FileAPI.jsPath;else for(f=0;f<j.length;f++)if(h=j[f].src,g=h.search(/\/ng\-file\-upload[\-a-zA-z0-9\.]*\.js/),g>-1){e=h.substring(0,g+1);break}null==FileAPI.staticPath&&(FileAPI.staticPath=e),i.setAttribute("src",d||e+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(i),FileAPI.hasFlash=b()}FileAPI.ngfFixIE=function(d,e,f,g){if(!b())throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';var h=function(){if(d.attr("disabled"))d.$$ngfRefElem.removeClass("js-fileapi-wrapper");else{var b=d.$$ngfRefElem;b?f(d.$$ngfRefElem):(b=d.$$ngfRefElem=e(),b.addClass("js-fileapi-wrapper"),!a(d),setTimeout(function(){b.bind("mouseenter",h)},10),b.bind("change",function(a){i.apply(this,[a]),g.apply(this,[a])})),a(d)||b.css("position","absolute").css("top",c(d[0]).top+"px").css("left",c(d[0]).left+"px").css("width",d[0].offsetWidth+"px").css("height",d[0].offsetHeight+"px").css("filter","alpha(opacity=0)").css("display",d.css("display")).css("overflow","hidden").css("z-index","900000").css("visibility","visible")}};d.bind("mouseenter",h);var i=function(a){for(var b=FileAPI.getFiles(a),c=0;c<b.length;c++)void 0===b[c].size&&(b[c].size=0),void 0===b[c].name&&(b[c].name="file"),void 0===b[c].type&&(b[c].type="undefined");a.target||(a.target={}),a.target.files=b,a.target.files!==b&&(a.__files_=b),(a.__files_||a.target.files).item=function(b){return(a.__files_||a.target.files)[b]||null}}},FileAPI.disableFileInput=function(a,b){b?a.removeClass("js-fileapi-wrapper"):a.addClass("js-fileapi-wrapper")}}}(),window.FileReader||(window.FileReader=function(){var a=this,b=!1;this.listeners={},this.addEventListener=function(b,c){a.listeners[b]=a.listeners[b]||[],a.listeners[b].push(c)},this.removeEventListener=function(b,c){a.listeners[b]&&a.listeners[b].splice(a.listeners[b].indexOf(c),1)},this.dispatchEvent=function(b){var c=a.listeners[b.type];if(c)for(var d=0;d<c.length;d++)c[d].call(a,b)},this.onabort=this.onerror=this.onload=this.onloadstart=this.onloadend=this.onprogress=null;var c=function(b,c){var d={type:b,target:a,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d},d=function(d){b||(b=!0,a.onloadstart&&a.onloadstart(c("loadstart",d)));var e;"load"===d.type?(a.onloadend&&a.onloadend(c("loadend",d)),e=c("load",d),a.onload&&a.onload(e),a.dispatchEvent(e)):"progress"===d.type?(e=c("progress",d),a.onprogress&&a.onprogress(e),a.dispatchEvent(e)):(e=c("error",d),a.onerror&&a.onerror(e),a.dispatchEvent(e))};this.readAsArrayBuffer=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsBinaryString=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsDataURL=function(a){FileAPI.readAsDataURL(a,d)},this.readAsText=function(a){FileAPI.readAsText(a,d)}}); | ||
/*! 5.0.1 */ | ||
var ngFileUpload=angular.module("ngFileUpload",[]);ngFileUpload.version="5.0.1",ngFileUpload.service("Upload",["$http","$q","$timeout",function(a,b,c){function d(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function e(d){d.method=d.method||"POST",d.headers=d.headers||{};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progressFunc=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&d("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}}),this.upload=function(a){function b(c,d,e){if(void 0!==d)if(angular.isDate(d)&&(d=d.toISOString()),angular.isString(d))c.append(e,d);else if("form"===a.sendFieldsAs)if(angular.isObject(d))for(var f in d)d.hasOwnProperty(f)&&b(c,d[f],e+"["+f+"]");else c.append(e,d);else d=angular.isString(d)?d:JSON.stringify(d),"json-blob"===a.sendFieldsAs?c.append(e,new Blob([d],{type:"application/json"})):c.append(e,d)}return a.headers=a.headers||{},a.headers["Content-Type"]=void 0,a.transformRequest=a.transformRequest?angular.isArray(a.transformRequest)?a.transformRequest:[a.transformRequest]:[],a.transformRequest.push(function(c){var d,e=new FormData,f={};for(d in a.fields)a.fields.hasOwnProperty(d)&&(f[d]=a.fields[d]);c&&(f.data=c);for(d in f)if(f.hasOwnProperty(d)){var g=f[d];a.formDataAppender?a.formDataAppender(e,d,g):b(e,g,d)}if(null!=a.file){var h=a.fileFormDataName||"file";if(angular.isArray(a.file))for(var i=angular.isString(h),j=0;j<a.file.length;j++)e.append(i?h:h[j],a.file[j],a.fileName&&a.fileName[j]||a.file[j].name);else e.append(h,a.file,a.fileName||a.file.name)}return e}),e(a)},this.http=function(b){return b.transformRequest=b.transformRequest||function(b){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](arguments)},e(b)}}]),function(){function a(a,e,f,g,h,i,j){function k(){return"input"===e[0].tagName.toLowerCase()&&f.type&&"file"===f.type.toLowerCase()}function l(b){if(!r){r=!0;try{for(var e=b.__files_||b.target&&b.target.files,j=[],k=[],l=0;l<e.length;l++){var m=e.item(l);c(a,h,f,m,b)?j.push(m):k.push(m)}d(h,i,a,g,f,f.ngfChange||f.ngfSelect,j,k,b),0===j.length&&(b.target.value=j)}finally{r=!1}}}function m(b){f.ngfMultiple&&b.attr("multiple",h(f.ngfMultiple)(a)),f.ngfCapture&&b.attr("capture",h(f.ngfCapture)(a)),f.accept&&b.attr("accept",f.accept);for(var c=0;c<e[0].attributes.length;c++){var d=e[0].attributes[c];(k()&&"type"!==d.name||"type"!==d.name&&"class"!==d.name&&"id"!==d.name&&"style"!==d.name)&&b.attr(d.name,d.value)}}function n(b,c){if(!e.attr("disabled")&&!q){if(!c&&(b||k()))return e.$$ngfRefElem||e;var d=angular.element('<input type="file">');return m(d),k()?(e.replaceWith(d),e=d,d.attr("__ngf_gen__",!0),j(e)(a)):(d.css("visibility","hidden").css("position","absolute").css("width","9").css("height","1").css("z-index","-100000").attr("tabindex","-1"),e.$$ngfRefElem&&e.$$ngfRefElem.remove(),e.$$ngfRefElem=d,document.body.appendChild(d[0])),d}}function o(b){d(h,i,a,g,f,f.ngfChange||f.ngfSelect,[],[],b,!0)}function p(c){function d(a){a&&i[0].click(),(k()||!a)&&e.bind("click touchend",p)}null!=c&&(c.preventDefault(),c.stopPropagation());var g=h(f.ngfResetOnClick)(a)!==!1,i=n(c,g);return i&&((!c||g)&&i.bind("change",l),c&&g&&h(f.ngfResetModelOnClick)(a)!==!1&&o(c),b(navigator.userAgent)?setTimeout(function(){d(c)},0):d(c)),!1}if(!e.attr("__ngf_gen__")){a.$on("$destroy",function(){e.$$ngfRefElem&&e.$$ngfRefElem.remove()});var q=!1;-1===f.ngfSelect.search(/\W+$files\W+/)&&a.$watch(f.ngfSelect,function(a){q=a===!1});var r=!1;window.FileAPI&&window.FileAPI.ngfFixIE?window.FileAPI.ngfFixIE(e,n,m,l):p()}}function b(a){var b=a.match(/Android[^\d]*(\d+)\.(\d+)/);return b&&b.length>2?parseInt(b[1])<4||4===parseInt(b[1])&&parseInt(b[2])<4:!1}ngFileUpload.directive("ngfSelect",["$parse","$timeout","$compile",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.validate=function(a,b,c,d,e){function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d<b.length;d++)c+="("+f(b[d])+")",d<b.length-1&&(c+="|");else 0===a.indexOf(".")&&(a="*"+a),c="^"+a.replace(new RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}var g=b(c.ngfAccept)(a,{$file:d,$event:e}),h=b(c.ngfMaxSize)(a,{$file:d,$event:e})||9007199254740991,i=b(c.ngfMinSize)(a,{$file:d,$event:e})||-1;if(null!=g&&angular.isString(g)){var j=new RegExp(f(g),"gi");g=null!=d.type&&j.test(d.type.toLowerCase())||null!=d.name&&j.test(d.name.toLowerCase())}return(null==g||g)&&(null==d.size||d.size<h&&d.size>i)},ngFileUpload.updateModel=function(a,b,c,d,e,f,g,h,i,j){function k(){if(a(e.ngfKeep)(c)===!0){if(!g||!g.length)return;if(a(e.ngfKeepDistinct)(c)===!0){for(var j=(d.$modelValue||[]).slice(0),k=j.length,l=0;l<g.length;l++){for(var m=0;k>m&&g[l].name!==j[m].name;m++);m===k&&j.push(g[l])}if(k===j.length)return;g=[].concat(j)}else g=(d.$modelValue||[]).concat(g)}d&&(a(e.ngModel).assign(c,g),b(function(){d&&d.$setViewValue(null!=g&&0===g.length?null:g)})),e.ngModelRejected&&a(e.ngModelRejected).assign(c,h),f&&a(f)(c,{$files:g,$rejectedFiles:h,$event:i})}j?k():b(function(){k()})};var c=ngFileUpload.validate,d=ngFileUpload.updateModel}(),function(){function a(a,e,f,g,h,i,j){function k(a,b,d){var e=!0,f=d.dataTransfer.items;if(null!=f)for(var g=0;g<f.length&&e;g++)e=e&&("file"===f[g].kind||""===f[g].kind)&&c(a,h,b,f[g],d);var i=h(b.ngfDragOverClass)(a,{$event:d});return i&&(i.delay&&(r=i.delay),i.accept&&(i=e?i.accept:i.reject)),i||b.ngfDragOverClass||"dragover"}function l(b,d,e,g){function k(d){c(a,h,f,d,b)?m.push(d):n.push(d)}function l(a,b,c){if(null!=b)if(b.isDirectory){var d=(c||"")+b.name;k({name:b.name,type:"directory",path:d});var e=b.createReader(),f=[];p++;var g=function(){e.readEntries(function(d){try{if(d.length)f=f.concat(Array.prototype.slice.call(d||[],0)),g();else{for(var e=0;e<f.length;e++)l(a,f[e],(c?c:"")+b.name+"/");p--}}catch(h){p--,console.error(h)}},function(){p--})};g()}else p++,b.file(function(a){try{p--,a.path=(c?c:"")+a.name,k(a)}catch(b){p--,console.error(b)}},function(){p--})}var m=[],n=[],o=b.dataTransfer.items,p=0;if(o&&o.length>0&&"file"!==j.protocol())for(var q=0;q<o.length;q++){if(o[q].webkitGetAsEntry&&o[q].webkitGetAsEntry()&&o[q].webkitGetAsEntry().isDirectory){var r=o[q].webkitGetAsEntry();if(r.isDirectory&&!e)continue;null!=r&&l(m,r)}else{var s=o[q].getAsFile();null!=s&&k(s)}if(!g&&m.length>0)break}else{var t=b.dataTransfer.files;if(null!=t)for(var u=0;u<t.length&&(k(t.item(u)),g||!(m.length>0));u++);}var v=0;!function w(a){i(function(){if(p)10*v++<2e4&&w(10);else{if(!g&&m.length>1){for(q=0;"directory"===m[q].type;)q++;m=[m[q]]}d(m,n)}},a||0)}()}var m=b();if(f.dropAvailable&&i(function(){a[f.dropAvailable]?a[f.dropAvailable].value=m:a[f.dropAvailable]=m}),!m)return void(h(f.ngfHideOnDropNotAvailable)(a)===!0&&e.css("display","none"));var n=!1;-1===f.ngfDrop.search(/\W+$files\W+/)&&a.$watch(f.ngfDrop,function(a){n=a===!1});var o,p=null,q=h(f.ngfStopPropagation),r=1;e[0].addEventListener("dragover",function(b){if(!e.attr("disabled")&&!n){if(b.preventDefault(),q(a)&&b.stopPropagation(),navigator.userAgent.indexOf("Chrome")>-1){var c=b.dataTransfer.effectAllowed;b.dataTransfer.dropEffect="move"===c||"linkMove"===c?"move":"copy"}i.cancel(p),a.actualDragOverClass||(o=k(a,f,b)),e.addClass(o)}},!1),e[0].addEventListener("dragenter",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation())},!1),e[0].addEventListener("dragleave",function(){e.attr("disabled")||n||(p=i(function(){e.removeClass(o),o=null},r||1))},!1),e[0].addEventListener("drop",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation(),e.removeClass(o),o=null,l(b,function(c,e){d(h,i,a,g,f,f.ngfChange||f.ngfDrop,c,e,b)},h(f.ngfAllowDir)(a)!==!1,f.multiple||h(f.ngfMultiple)(a)))},!1)}function b(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}var c=ngFileUpload.validate,d=ngFileUpload.updateModel;ngFileUpload.directive("ngfDrop",["$parse","$timeout","$location",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.directive("ngfNoFileDrop",function(){return function(a,c){b()&&c.css("display","none")}}),ngFileUpload.directive("ngfDropAvailable",["$parse","$timeout",function(a,c){return function(d,e,f){if(b()){var g=a(f.ngfDropAvailable);c(function(){g(d),g.assign&&g.assign(d,!0)})}}}]),ngFileUpload.directive("ngfSrc",["$parse","$timeout",function(a,b){return{restrict:"AE",link:function(d,e,f){window.FileReader&&d.$watch(f.ngfSrc,function(g){g&&c(d,a,f,g,null)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 8")||g.size<2e4)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 9")||g.size<4e6)?b(function(){var a=window.URL||window.webkitURL;if(a&&a.createObjectURL)e.attr("src",a.createObjectURL(g));else{var c=new FileReader;c.readAsDataURL(g),c.onload=function(a){b(function(){e.attr("src",a.target.result)})}}}):e.attr("src",f.ngfDefaultSrc||"")})}}}])}(),function(){function a(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function b(a,b,c){try{Object.defineProperty(a,b,{get:c})}catch(d){}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){var c=function(a){if(!a.__listeners){a.upload||(a.upload={}),a.__listeners=[];var b=a.upload.addEventListener;a.upload.addEventListener=function(c,d){a.__listeners[c]=d,b&&b.apply(this,arguments)}}};a("open",function(a){return function(b,d,e){c(this),this.__url=d;try{a.apply(this,[b,d,e])}catch(f){f.message.indexOf("Access is denied")>-1&&(this.__origError=f,a.apply(this,[b,"_fix_for_ie_crossdomain__",e]))}}}),a("getResponseHeader",function(a){return function(b){return this.__fileApiXHR&&this.__fileApiXHR.getResponseHeader?this.__fileApiXHR.getResponseHeader(b):null==a?null:a.apply(this,[b])}}),a("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.getAllResponseHeaders?this.__fileApiXHR.getAllResponseHeaders():null==a?null:a.apply(this)}}),a("abort",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.abort?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),a("setRequestHeader",function(a){return function(b,d){if("__setXHR_"===b){c(this);var e=d(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[b]=d,a.apply(this,arguments)}}),a("send",function(a){return function(){var c=this;if(arguments[0]&&arguments[0].__isFileAPIShim){var d=arguments[0],e={url:c.__url,jsonp:!1,cache:!0,complete:function(a,d){c.__completed=!0,!a&&c.__listeners.load&&c.__listeners.load({type:"load",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),!a&&c.__listeners.loadend&&c.__listeners.loadend({type:"loadend",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),"abort"===a&&c.__listeners.abort&&c.__listeners.abort({type:"abort",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),void 0!==d.status&&b(c,"status",function(){return 0===d.status&&a&&"abort"!==a?500:d.status}),void 0!==d.statusText&&b(c,"statusText",function(){return d.statusText}),b(c,"readyState",function(){return 4}),void 0!==d.response&&b(c,"response",function(){return d.response});var e=d.responseText||(a&&0===d.status&&"abort"!==a?a:void 0);b(c,"responseText",function(){return e}),b(c,"response",function(){return e}),a&&b(c,"err",function(){return a}),c.__fileApiXHR=d,c.onreadystatechange&&c.onreadystatechange(),c.onload&&c.onload()},progress:function(a){if(a.target=c,c.__listeners.progress&&c.__listeners.progress(a),c.__total=a.total,c.__loaded=a.loaded,a.total===a.loaded){var b=this;setTimeout(function(){c.__completed||(c.getAllResponseHeaders=function(){},b.complete(null,{status:204,statusText:"No Content"}))},FileAPI.noContentTimeout||1e4)}},headers:c.__requestHeaders};e.data={},e.files={};for(var f=0;f<d.data.length;f++){var g=d.data[f];null!=g.val&&null!=g.val.name&&null!=g.val.size&&null!=g.val.type?e.files[g.key]=g.val:e.data[g.key]=g.val}setTimeout(function(){if(!FileAPI.hasFlash)throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';c.__fileApiXHR=FileAPI.upload(e)},1)}else{if(this.__origError)throw this.__origError;a.apply(c,arguments)}}}),window.XMLHttpRequest.__isFileAPIShim=!0,window.FormData=FormData=function(){return{append:function(a,b,c){b.__isFileAPIBlobShim&&(b=b.data[0]),this.data.push({key:a,val:b,name:c})},data:[],__isFileAPIShim:!0}},window.Blob=Blob=function(a){return{data:a,__isFileAPIBlobShim:!0}}}}(),function(){function a(a){return"input"===a[0].tagName.toLowerCase()&&a.attr("type")&&"file"===a.attr("type").toLowerCase()}function b(){try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if(a)return!0}catch(b){if(void 0!==navigator.mimeTypes["application/x-shockwave-flash"])return!0}return!1}function c(a){var b=0,c=0;if(window.jQuery)return jQuery(a).offset();if(a.offsetParent)do b+=a.offsetLeft-a.scrollLeft,c+=a.offsetTop-a.scrollTop,a=a.offsetParent;while(a);return{left:b,top:c}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){if(window.FileAPI||(window.FileAPI={}),FileAPI.forceLoad&&(FileAPI.html5=!1),!FileAPI.upload){var d,e,f,g,h,i=document.createElement("script"),j=document.getElementsByTagName("script");if(window.FileAPI.jsUrl)d=window.FileAPI.jsUrl;else if(window.FileAPI.jsPath)e=window.FileAPI.jsPath;else for(f=0;f<j.length;f++)if(h=j[f].src,g=h.search(/\/ng\-file\-upload[\-a-zA-z0-9\.]*\.js/),g>-1){e=h.substring(0,g+1);break}null==FileAPI.staticPath&&(FileAPI.staticPath=e),i.setAttribute("src",d||e+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(i),FileAPI.hasFlash=b()}FileAPI.ngfFixIE=function(d,e,f,g){if(!b())throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';var h=function(){if(d.attr("disabled"))d.$$ngfRefElem.removeClass("js-fileapi-wrapper");else{var b=d.$$ngfRefElem;b?f(d.$$ngfRefElem):(b=d.$$ngfRefElem=e(),b.addClass("js-fileapi-wrapper"),!a(d),setTimeout(function(){b.bind("mouseenter",h)},10),b.bind("change",function(a){i.apply(this,[a]),g.apply(this,[a])})),a(d)||b.css("position","absolute").css("top",c(d[0]).top+"px").css("left",c(d[0]).left+"px").css("width",d[0].offsetWidth+"px").css("height",d[0].offsetHeight+"px").css("filter","alpha(opacity=0)").css("display",d.css("display")).css("overflow","hidden").css("z-index","900000").css("visibility","visible")}};d.bind("mouseenter",h);var i=function(a){for(var b=FileAPI.getFiles(a),c=0;c<b.length;c++)void 0===b[c].size&&(b[c].size=0),void 0===b[c].name&&(b[c].name="file"),void 0===b[c].type&&(b[c].type="undefined");a.target||(a.target={}),a.target.files=b,a.target.files!==b&&(a.__files_=b),(a.__files_||a.target.files).item=function(b){return(a.__files_||a.target.files)[b]||null}}},FileAPI.disableFileInput=function(a,b){b?a.removeClass("js-fileapi-wrapper"):a.addClass("js-fileapi-wrapper")}}}(),window.FileReader||(window.FileReader=function(){var a=this,b=!1;this.listeners={},this.addEventListener=function(b,c){a.listeners[b]=a.listeners[b]||[],a.listeners[b].push(c)},this.removeEventListener=function(b,c){a.listeners[b]&&a.listeners[b].splice(a.listeners[b].indexOf(c),1)},this.dispatchEvent=function(b){var c=a.listeners[b.type];if(c)for(var d=0;d<c.length;d++)c[d].call(a,b)},this.onabort=this.onerror=this.onload=this.onloadstart=this.onloadend=this.onprogress=null;var c=function(b,c){var d={type:b,target:a,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d},d=function(d){b||(b=!0,a.onloadstart&&a.onloadstart(c("loadstart",d)));var e;"load"===d.type?(a.onloadend&&a.onloadend(c("loadend",d)),e=c("load",d),a.onload&&a.onload(e),a.dispatchEvent(e)):"progress"===d.type?(e=c("progress",d),a.onprogress&&a.onprogress(e),a.dispatchEvent(e)):(e=c("error",d),a.onerror&&a.onerror(e),a.dispatchEvent(e))};this.readAsArrayBuffer=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsBinaryString=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsDataURL=function(a){FileAPI.readAsDataURL(a,d)},this.readAsText=function(a){FileAPI.readAsText(a,d)}}); |
@@ -5,3 +5,3 @@ /**! | ||
* @author Danial <danial.farid@gmail.com> | ||
* @version 5.0.0 | ||
* @version 5.0.1 | ||
*/ | ||
@@ -239,8 +239,12 @@ | ||
function getOffset(obj) { | ||
var left, top; | ||
left = top = 0; | ||
var left = 0, top = 0; | ||
if (window.jQuery) { | ||
return jQuery(obj).offset(); | ||
} | ||
if (obj.offsetParent) { | ||
do { | ||
left += obj.offsetLeft; | ||
top += obj.offsetTop; | ||
left += (obj.offsetLeft - obj.scrollLeft); | ||
top += (obj.offsetTop - obj.scrollTop); | ||
obj = obj.offsetParent; | ||
@@ -247,0 +251,0 @@ } while (obj); |
@@ -1,2 +0,2 @@ | ||
/*! 5.0.0 */ | ||
!function(){function a(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function b(a,b,c){try{Object.defineProperty(a,b,{get:c})}catch(d){}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){var c=function(a){if(!a.__listeners){a.upload||(a.upload={}),a.__listeners=[];var b=a.upload.addEventListener;a.upload.addEventListener=function(c,d){a.__listeners[c]=d,b&&b.apply(this,arguments)}}};a("open",function(a){return function(b,d,e){c(this),this.__url=d;try{a.apply(this,[b,d,e])}catch(f){f.message.indexOf("Access is denied")>-1&&(this.__origError=f,a.apply(this,[b,"_fix_for_ie_crossdomain__",e]))}}}),a("getResponseHeader",function(a){return function(b){return this.__fileApiXHR&&this.__fileApiXHR.getResponseHeader?this.__fileApiXHR.getResponseHeader(b):null==a?null:a.apply(this,[b])}}),a("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.getAllResponseHeaders?this.__fileApiXHR.getAllResponseHeaders():null==a?null:a.apply(this)}}),a("abort",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.abort?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),a("setRequestHeader",function(a){return function(b,d){if("__setXHR_"===b){c(this);var e=d(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[b]=d,a.apply(this,arguments)}}),a("send",function(a){return function(){var c=this;if(arguments[0]&&arguments[0].__isFileAPIShim){var d=arguments[0],e={url:c.__url,jsonp:!1,cache:!0,complete:function(a,d){c.__completed=!0,!a&&c.__listeners.load&&c.__listeners.load({type:"load",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),!a&&c.__listeners.loadend&&c.__listeners.loadend({type:"loadend",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),"abort"===a&&c.__listeners.abort&&c.__listeners.abort({type:"abort",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),void 0!==d.status&&b(c,"status",function(){return 0===d.status&&a&&"abort"!==a?500:d.status}),void 0!==d.statusText&&b(c,"statusText",function(){return d.statusText}),b(c,"readyState",function(){return 4}),void 0!==d.response&&b(c,"response",function(){return d.response});var e=d.responseText||(a&&0===d.status&&"abort"!==a?a:void 0);b(c,"responseText",function(){return e}),b(c,"response",function(){return e}),a&&b(c,"err",function(){return a}),c.__fileApiXHR=d,c.onreadystatechange&&c.onreadystatechange(),c.onload&&c.onload()},progress:function(a){if(a.target=c,c.__listeners.progress&&c.__listeners.progress(a),c.__total=a.total,c.__loaded=a.loaded,a.total===a.loaded){var b=this;setTimeout(function(){c.__completed||(c.getAllResponseHeaders=function(){},b.complete(null,{status:204,statusText:"No Content"}))},FileAPI.noContentTimeout||1e4)}},headers:c.__requestHeaders};e.data={},e.files={};for(var f=0;f<d.data.length;f++){var g=d.data[f];null!=g.val&&null!=g.val.name&&null!=g.val.size&&null!=g.val.type?e.files[g.key]=g.val:e.data[g.key]=g.val}setTimeout(function(){if(!FileAPI.hasFlash)throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';c.__fileApiXHR=FileAPI.upload(e)},1)}else{if(this.__origError)throw this.__origError;a.apply(c,arguments)}}}),window.XMLHttpRequest.__isFileAPIShim=!0,window.FormData=FormData=function(){return{append:function(a,b,c){b.__isFileAPIBlobShim&&(b=b.data[0]),this.data.push({key:a,val:b,name:c})},data:[],__isFileAPIShim:!0}},window.Blob=Blob=function(a){return{data:a,__isFileAPIBlobShim:!0}}}}(),function(){function a(a){return"input"===a[0].tagName.toLowerCase()&&a.attr("type")&&"file"===a.attr("type").toLowerCase()}function b(){try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if(a)return!0}catch(b){if(void 0!==navigator.mimeTypes["application/x-shockwave-flash"])return!0}return!1}function c(a){var b,c;if(b=c=0,a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop,a=a.offsetParent;while(a);return{left:b,top:c}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){if(window.FileAPI||(window.FileAPI={}),FileAPI.forceLoad&&(FileAPI.html5=!1),!FileAPI.upload){var d,e,f,g,h,i=document.createElement("script"),j=document.getElementsByTagName("script");if(window.FileAPI.jsUrl)d=window.FileAPI.jsUrl;else if(window.FileAPI.jsPath)e=window.FileAPI.jsPath;else for(f=0;f<j.length;f++)if(h=j[f].src,g=h.search(/\/ng\-file\-upload[\-a-zA-z0-9\.]*\.js/),g>-1){e=h.substring(0,g+1);break}null==FileAPI.staticPath&&(FileAPI.staticPath=e),i.setAttribute("src",d||e+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(i),FileAPI.hasFlash=b()}FileAPI.ngfFixIE=function(d,e,f,g){if(!b())throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';var h=function(){if(d.attr("disabled"))d.$$ngfRefElem.removeClass("js-fileapi-wrapper");else{var b=d.$$ngfRefElem;b?f(d.$$ngfRefElem):(b=d.$$ngfRefElem=e(),b.addClass("js-fileapi-wrapper"),!a(d),setTimeout(function(){b.bind("mouseenter",h)},10),b.bind("change",function(a){i.apply(this,[a]),g.apply(this,[a])})),a(d)||b.css("position","absolute").css("top",c(d[0]).top+"px").css("left",c(d[0]).left+"px").css("width",d[0].offsetWidth+"px").css("height",d[0].offsetHeight+"px").css("filter","alpha(opacity=0)").css("display",d.css("display")).css("overflow","hidden").css("z-index","900000").css("visibility","visible")}};d.bind("mouseenter",h);var i=function(a){for(var b=FileAPI.getFiles(a),c=0;c<b.length;c++)void 0===b[c].size&&(b[c].size=0),void 0===b[c].name&&(b[c].name="file"),void 0===b[c].type&&(b[c].type="undefined");a.target||(a.target={}),a.target.files=b,a.target.files!==b&&(a.__files_=b),(a.__files_||a.target.files).item=function(b){return(a.__files_||a.target.files)[b]||null}}},FileAPI.disableFileInput=function(a,b){b?a.removeClass("js-fileapi-wrapper"):a.addClass("js-fileapi-wrapper")}}}(),window.FileReader||(window.FileReader=function(){var a=this,b=!1;this.listeners={},this.addEventListener=function(b,c){a.listeners[b]=a.listeners[b]||[],a.listeners[b].push(c)},this.removeEventListener=function(b,c){a.listeners[b]&&a.listeners[b].splice(a.listeners[b].indexOf(c),1)},this.dispatchEvent=function(b){var c=a.listeners[b.type];if(c)for(var d=0;d<c.length;d++)c[d].call(a,b)},this.onabort=this.onerror=this.onload=this.onloadstart=this.onloadend=this.onprogress=null;var c=function(b,c){var d={type:b,target:a,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d},d=function(d){b||(b=!0,a.onloadstart&&a.onloadstart(c("loadstart",d)));var e;"load"===d.type?(a.onloadend&&a.onloadend(c("loadend",d)),e=c("load",d),a.onload&&a.onload(e),a.dispatchEvent(e)):"progress"===d.type?(e=c("progress",d),a.onprogress&&a.onprogress(e),a.dispatchEvent(e)):(e=c("error",d),a.onerror&&a.onerror(e),a.dispatchEvent(e))};this.readAsArrayBuffer=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsBinaryString=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsDataURL=function(a){FileAPI.readAsDataURL(a,d)},this.readAsText=function(a){FileAPI.readAsText(a,d)}}); | ||
/*! 5.0.1 */ | ||
!function(){function a(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function b(a,b,c){try{Object.defineProperty(a,b,{get:c})}catch(d){}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){var c=function(a){if(!a.__listeners){a.upload||(a.upload={}),a.__listeners=[];var b=a.upload.addEventListener;a.upload.addEventListener=function(c,d){a.__listeners[c]=d,b&&b.apply(this,arguments)}}};a("open",function(a){return function(b,d,e){c(this),this.__url=d;try{a.apply(this,[b,d,e])}catch(f){f.message.indexOf("Access is denied")>-1&&(this.__origError=f,a.apply(this,[b,"_fix_for_ie_crossdomain__",e]))}}}),a("getResponseHeader",function(a){return function(b){return this.__fileApiXHR&&this.__fileApiXHR.getResponseHeader?this.__fileApiXHR.getResponseHeader(b):null==a?null:a.apply(this,[b])}}),a("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.getAllResponseHeaders?this.__fileApiXHR.getAllResponseHeaders():null==a?null:a.apply(this)}}),a("abort",function(a){return function(){return this.__fileApiXHR&&this.__fileApiXHR.abort?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),a("setRequestHeader",function(a){return function(b,d){if("__setXHR_"===b){c(this);var e=d(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[b]=d,a.apply(this,arguments)}}),a("send",function(a){return function(){var c=this;if(arguments[0]&&arguments[0].__isFileAPIShim){var d=arguments[0],e={url:c.__url,jsonp:!1,cache:!0,complete:function(a,d){c.__completed=!0,!a&&c.__listeners.load&&c.__listeners.load({type:"load",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),!a&&c.__listeners.loadend&&c.__listeners.loadend({type:"loadend",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),"abort"===a&&c.__listeners.abort&&c.__listeners.abort({type:"abort",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),void 0!==d.status&&b(c,"status",function(){return 0===d.status&&a&&"abort"!==a?500:d.status}),void 0!==d.statusText&&b(c,"statusText",function(){return d.statusText}),b(c,"readyState",function(){return 4}),void 0!==d.response&&b(c,"response",function(){return d.response});var e=d.responseText||(a&&0===d.status&&"abort"!==a?a:void 0);b(c,"responseText",function(){return e}),b(c,"response",function(){return e}),a&&b(c,"err",function(){return a}),c.__fileApiXHR=d,c.onreadystatechange&&c.onreadystatechange(),c.onload&&c.onload()},progress:function(a){if(a.target=c,c.__listeners.progress&&c.__listeners.progress(a),c.__total=a.total,c.__loaded=a.loaded,a.total===a.loaded){var b=this;setTimeout(function(){c.__completed||(c.getAllResponseHeaders=function(){},b.complete(null,{status:204,statusText:"No Content"}))},FileAPI.noContentTimeout||1e4)}},headers:c.__requestHeaders};e.data={},e.files={};for(var f=0;f<d.data.length;f++){var g=d.data[f];null!=g.val&&null!=g.val.name&&null!=g.val.size&&null!=g.val.type?e.files[g.key]=g.val:e.data[g.key]=g.val}setTimeout(function(){if(!FileAPI.hasFlash)throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';c.__fileApiXHR=FileAPI.upload(e)},1)}else{if(this.__origError)throw this.__origError;a.apply(c,arguments)}}}),window.XMLHttpRequest.__isFileAPIShim=!0,window.FormData=FormData=function(){return{append:function(a,b,c){b.__isFileAPIBlobShim&&(b=b.data[0]),this.data.push({key:a,val:b,name:c})},data:[],__isFileAPIShim:!0}},window.Blob=Blob=function(a){return{data:a,__isFileAPIBlobShim:!0}}}}(),function(){function a(a){return"input"===a[0].tagName.toLowerCase()&&a.attr("type")&&"file"===a.attr("type").toLowerCase()}function b(){try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if(a)return!0}catch(b){if(void 0!==navigator.mimeTypes["application/x-shockwave-flash"])return!0}return!1}function c(a){var b=0,c=0;if(window.jQuery)return jQuery(a).offset();if(a.offsetParent)do b+=a.offsetLeft-a.scrollLeft,c+=a.offsetTop-a.scrollTop,a=a.offsetParent;while(a);return{left:b,top:c}}if(window.XMLHttpRequest&&!window.FormData||window.FileAPI&&FileAPI.forceLoad){if(window.FileAPI||(window.FileAPI={}),FileAPI.forceLoad&&(FileAPI.html5=!1),!FileAPI.upload){var d,e,f,g,h,i=document.createElement("script"),j=document.getElementsByTagName("script");if(window.FileAPI.jsUrl)d=window.FileAPI.jsUrl;else if(window.FileAPI.jsPath)e=window.FileAPI.jsPath;else for(f=0;f<j.length;f++)if(h=j[f].src,g=h.search(/\/ng\-file\-upload[\-a-zA-z0-9\.]*\.js/),g>-1){e=h.substring(0,g+1);break}null==FileAPI.staticPath&&(FileAPI.staticPath=e),i.setAttribute("src",d||e+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(i),FileAPI.hasFlash=b()}FileAPI.ngfFixIE=function(d,e,f,g){if(!b())throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';var h=function(){if(d.attr("disabled"))d.$$ngfRefElem.removeClass("js-fileapi-wrapper");else{var b=d.$$ngfRefElem;b?f(d.$$ngfRefElem):(b=d.$$ngfRefElem=e(),b.addClass("js-fileapi-wrapper"),!a(d),setTimeout(function(){b.bind("mouseenter",h)},10),b.bind("change",function(a){i.apply(this,[a]),g.apply(this,[a])})),a(d)||b.css("position","absolute").css("top",c(d[0]).top+"px").css("left",c(d[0]).left+"px").css("width",d[0].offsetWidth+"px").css("height",d[0].offsetHeight+"px").css("filter","alpha(opacity=0)").css("display",d.css("display")).css("overflow","hidden").css("z-index","900000").css("visibility","visible")}};d.bind("mouseenter",h);var i=function(a){for(var b=FileAPI.getFiles(a),c=0;c<b.length;c++)void 0===b[c].size&&(b[c].size=0),void 0===b[c].name&&(b[c].name="file"),void 0===b[c].type&&(b[c].type="undefined");a.target||(a.target={}),a.target.files=b,a.target.files!==b&&(a.__files_=b),(a.__files_||a.target.files).item=function(b){return(a.__files_||a.target.files)[b]||null}}},FileAPI.disableFileInput=function(a,b){b?a.removeClass("js-fileapi-wrapper"):a.addClass("js-fileapi-wrapper")}}}(),window.FileReader||(window.FileReader=function(){var a=this,b=!1;this.listeners={},this.addEventListener=function(b,c){a.listeners[b]=a.listeners[b]||[],a.listeners[b].push(c)},this.removeEventListener=function(b,c){a.listeners[b]&&a.listeners[b].splice(a.listeners[b].indexOf(c),1)},this.dispatchEvent=function(b){var c=a.listeners[b.type];if(c)for(var d=0;d<c.length;d++)c[d].call(a,b)},this.onabort=this.onerror=this.onload=this.onloadstart=this.onloadend=this.onprogress=null;var c=function(b,c){var d={type:b,target:a,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d},d=function(d){b||(b=!0,a.onloadstart&&a.onloadstart(c("loadstart",d)));var e;"load"===d.type?(a.onloadend&&a.onloadend(c("loadend",d)),e=c("load",d),a.onload&&a.onload(e),a.dispatchEvent(e)):"progress"===d.type?(e=c("progress",d),a.onprogress&&a.onprogress(e),a.dispatchEvent(e)):(e=c("error",d),a.onerror&&a.onerror(e),a.dispatchEvent(e))};this.readAsArrayBuffer=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsBinaryString=function(a){FileAPI.readAsBinaryString(a,d)},this.readAsDataURL=function(a){FileAPI.readAsDataURL(a,d)},this.readAsText=function(a){FileAPI.readAsText(a,d)}}); |
/**! | ||
* AngularJS file upload/drop directive and service with progress and abort | ||
* @author Danial <danial.farid@gmail.com> | ||
* @version 5.0.0 | ||
* @version 5.0.1 | ||
*/ | ||
var ngFileUpload = angular.module('ngFileUpload', []); | ||
ngFileUpload.version = '5.0.0'; | ||
ngFileUpload.version = '5.0.1'; | ||
ngFileUpload.service('Upload', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
@@ -34,3 +34,4 @@ function patchXHR(fnName, newFn) { | ||
var deferred = $q.defer(); | ||
var deferred = | ||
$q.defer(); | ||
var promise = deferred.promise; | ||
@@ -208,262 +209,262 @@ | ||
(function () { | ||
ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', | ||
function ($parse, $timeout, $compile) { | ||
return { | ||
restrict: 'AEC', | ||
require: '?ngModel', | ||
link: function (scope, elem, attr, ngModel) { | ||
linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile); | ||
} | ||
}; | ||
}]); | ||
ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', | ||
function ($parse, $timeout, $compile) { | ||
return { | ||
restrict: 'AEC', | ||
require: '?ngModel', | ||
link: function (scope, elem, attr, ngModel) { | ||
linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile); | ||
} | ||
}; | ||
}]); | ||
function linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) { | ||
/** @namespace attr.ngfSelect */ | ||
/** @namespace attr.ngfChange */ | ||
/** @namespace attr.ngModel */ | ||
/** @namespace attr.ngModelRejected */ | ||
/** @namespace attr.ngfMultiple */ | ||
/** @namespace attr.ngfCapture */ | ||
/** @namespace attr.ngfAccept */ | ||
/** @namespace attr.ngfMaxSize */ | ||
/** @namespace attr.ngfMinSize */ | ||
/** @namespace attr.ngfResetOnClick */ | ||
/** @namespace attr.ngfResetModelOnClick */ | ||
/** @namespace attr.ngfKeep */ | ||
/** @namespace attr.ngfKeepDistinct */ | ||
function linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) { | ||
/** @namespace attr.ngfSelect */ | ||
/** @namespace attr.ngfChange */ | ||
/** @namespace attr.ngModel */ | ||
/** @namespace attr.ngModelRejected */ | ||
/** @namespace attr.ngfMultiple */ | ||
/** @namespace attr.ngfCapture */ | ||
/** @namespace attr.ngfAccept */ | ||
/** @namespace attr.ngfMaxSize */ | ||
/** @namespace attr.ngfMinSize */ | ||
/** @namespace attr.ngfResetOnClick */ | ||
/** @namespace attr.ngfResetModelOnClick */ | ||
/** @namespace attr.ngfKeep */ | ||
/** @namespace attr.ngfKeepDistinct */ | ||
if (elem.attr('__ngf_gen__')) { | ||
return; | ||
} | ||
if (elem.attr('__ngf_gen__')) { | ||
return; | ||
} | ||
scope.$on('$destroy', function () { | ||
if (elem.$$ngfRefElem) elem.$$ngfRefElem.remove(); | ||
}); | ||
scope.$on('$destroy', function () { | ||
if (elem.$$ngfRefElem) elem.$$ngfRefElem.remove(); | ||
}); | ||
var disabled = false; | ||
if (attr.ngfSelect.search(/\W+$files\W+/) === -1) { | ||
scope.$watch(attr.ngfSelect, function (val) { | ||
disabled = val === false; | ||
}); | ||
} | ||
function isInputTypeFile() { | ||
return elem[0].tagName.toLowerCase() === 'input' && attr.type && attr.type.toLowerCase() === 'file'; | ||
} | ||
var disabled = false; | ||
if (attr.ngfSelect.search(/\W+$files\W+/) === -1) { | ||
scope.$watch(attr.ngfSelect, function (val) { | ||
disabled = val === false; | ||
}); | ||
} | ||
function isInputTypeFile() { | ||
return elem[0].tagName.toLowerCase() === 'input' && attr.type && attr.type.toLowerCase() === 'file'; | ||
} | ||
var isUpdating = false; | ||
var isUpdating = false; | ||
function changeFn(evt) { | ||
if (!isUpdating) { | ||
isUpdating = true; | ||
try { | ||
var fileList = evt.__files_ || (evt.target && evt.target.files); | ||
var files = [], rejFiles = []; | ||
function changeFn(evt) { | ||
if (!isUpdating) { | ||
isUpdating = true; | ||
try { | ||
var fileList = evt.__files_ || (evt.target && evt.target.files); | ||
var files = [], rejFiles = []; | ||
for (var i = 0; i < fileList.length; i++) { | ||
var file = fileList.item(i); | ||
if (validate(scope, $parse, attr, file, evt)) { | ||
files.push(file); | ||
} else { | ||
rejFiles.push(file); | ||
} | ||
} | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, files, rejFiles, evt); | ||
if (files.length === 0) evt.target.value = files; | ||
for (var i = 0; i < fileList.length; i++) { | ||
var file = fileList.item(i); | ||
if (validate(scope, $parse, attr, file, evt)) { | ||
files.push(file); | ||
} else { | ||
rejFiles.push(file); | ||
} | ||
} | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, files, rejFiles, evt); | ||
if (files.length === 0) evt.target.value = files; | ||
// if (evt.target && evt.target.getAttribute('__ngf_gen__')) { | ||
// angular.element(evt.target).remove(); | ||
// } | ||
} finally { | ||
isUpdating = false; | ||
} finally { | ||
isUpdating = false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function bindAttrToFileInput(fileElem) { | ||
if (attr.ngfMultiple) fileElem.attr('multiple', $parse(attr.ngfMultiple)(scope)); | ||
if (attr.ngfCapture) fileElem.attr('capture', $parse(attr.ngfCapture)(scope)); | ||
if (attr.accept) fileElem.attr('accept', attr.accept); | ||
for (var i = 0; i < elem[0].attributes.length; i++) { | ||
var attribute = elem[0].attributes[i]; | ||
if ((isInputTypeFile() && attribute.name !== 'type') || | ||
(attribute.name !== 'type' && attribute.name !== 'class' && | ||
attribute.name !== 'id' && attribute.name !== 'style')) { | ||
fileElem.attr(attribute.name, attribute.value); | ||
function bindAttrToFileInput(fileElem) { | ||
if (attr.ngfMultiple) fileElem.attr('multiple', $parse(attr.ngfMultiple)(scope)); | ||
if (attr.ngfCapture) fileElem.attr('capture', $parse(attr.ngfCapture)(scope)); | ||
if (attr.accept) fileElem.attr('accept', attr.accept); | ||
for (var i = 0; i < elem[0].attributes.length; i++) { | ||
var attribute = elem[0].attributes[i]; | ||
if ((isInputTypeFile() && attribute.name !== 'type') || | ||
(attribute.name !== 'type' && attribute.name !== 'class' && | ||
attribute.name !== 'id' && attribute.name !== 'style')) { | ||
fileElem.attr(attribute.name, attribute.value); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function createFileInput(evt, resetOnClick) { | ||
if (elem.attr('disabled') || disabled) return; | ||
function createFileInput(evt, resetOnClick) { | ||
if (elem.attr('disabled') || disabled) return; | ||
if (!resetOnClick && (evt || isInputTypeFile())) return elem.$$ngfRefElem || elem; | ||
if (!resetOnClick && (evt || isInputTypeFile())) return elem.$$ngfRefElem || elem; | ||
var fileElem = angular.element('<input type="file">'); | ||
bindAttrToFileInput(fileElem); | ||
var fileElem = angular.element('<input type="file">'); | ||
bindAttrToFileInput(fileElem); | ||
if (isInputTypeFile()) { | ||
elem.replaceWith(fileElem); | ||
elem = fileElem; | ||
fileElem.attr('__ngf_gen__', true); | ||
$compile(elem)(scope); | ||
} else { | ||
fileElem.css('visibility', 'hidden').css('position', 'absolute') | ||
.css('width', '9').css('height', '1').css('z-index', '-100000') | ||
.attr('tabindex', '-1'); | ||
if (elem.$$ngfRefElem) { | ||
elem.$$ngfRefElem.remove(); | ||
if (isInputTypeFile()) { | ||
elem.replaceWith(fileElem); | ||
elem = fileElem; | ||
fileElem.attr('__ngf_gen__', true); | ||
$compile(elem)(scope); | ||
} else { | ||
fileElem.css('visibility', 'hidden').css('position', 'absolute') | ||
.css('width', '9').css('height', '1').css('z-index', '-100000') | ||
.attr('tabindex', '-1'); | ||
if (elem.$$ngfRefElem) { | ||
elem.$$ngfRefElem.remove(); | ||
} | ||
elem.$$ngfRefElem = fileElem; | ||
document.body.appendChild(fileElem[0]); | ||
} | ||
return fileElem; | ||
} | ||
elem.$$ngfRefElem = fileElem; | ||
document.body.appendChild(fileElem[0]); | ||
} | ||
return fileElem; | ||
} | ||
function resetModel(evt) { | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, [], [], evt, true); | ||
} | ||
function resetModel(evt) { | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, [], [], evt, true); | ||
} | ||
function clickHandler(evt) { | ||
if (evt != null) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var resetOnClick = $parse(attr.ngfResetOnClick)(scope) !== false; | ||
var fileElem = createFileInput(evt, resetOnClick); | ||
function clickHandler(evt) { | ||
if (evt != null) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var resetOnClick = $parse(attr.ngfResetOnClick)(scope) !== false; | ||
var fileElem = createFileInput(evt, resetOnClick); | ||
function clickAndAssign(evt) { | ||
if (evt) { | ||
fileElem[0].click(); | ||
} | ||
if (isInputTypeFile() || !evt) { | ||
elem.bind('click touchend', clickHandler); | ||
} | ||
} | ||
function clickAndAssign(evt) { | ||
if (evt) { | ||
fileElem[0].click(); | ||
if (fileElem) { | ||
if (!evt || resetOnClick) fileElem.bind('change', changeFn); | ||
if (evt && resetOnClick && $parse(attr.ngfResetModelOnClick)(scope) !== false) resetModel(evt); | ||
// fix for android native browser < 4.4 | ||
if (isAndroidBelow44(navigator.userAgent)) { | ||
setTimeout(function () { | ||
clickAndAssign(evt); | ||
}, 0); | ||
} else { | ||
clickAndAssign(evt); | ||
} | ||
} | ||
return false; | ||
} | ||
if (isInputTypeFile() || !evt) { | ||
elem.bind('click touchend', clickHandler); | ||
} | ||
} | ||
if (fileElem) { | ||
if (!evt || resetOnClick) fileElem.bind('change', changeFn); | ||
if (evt && resetOnClick && $parse(attr.ngfResetModelOnClick)(scope) !== false) resetModel(evt); | ||
// fix for android native browser < 4.4 | ||
if (isAndroidBelow44()) { | ||
setTimeout(function () { | ||
clickAndAssign(evt); | ||
}, 0); | ||
if (window.FileAPI && window.FileAPI.ngfFixIE) { | ||
window.FileAPI.ngfFixIE(elem, createFileInput, bindAttrToFileInput, changeFn); | ||
} else { | ||
clickAndAssign(evt); | ||
clickHandler(); | ||
//if (!isInputTypeFile()) { | ||
// elem.bind('click touchend', clickHandler); | ||
//} | ||
} | ||
} | ||
return false; | ||
} | ||
if (window.FileAPI && window.FileAPI.ngfFixIE) { | ||
window.FileAPI.ngfFixIE(elem, createFileInput, bindAttrToFileInput, changeFn); | ||
} else { | ||
clickHandler(); | ||
//if (!isInputTypeFile()) { | ||
// elem.bind('click touchend', clickHandler); | ||
//} | ||
} | ||
} | ||
function isAndroidBelow44(ua) { | ||
var m = ua.match(/Android[^\d]*(\d+)\.(\d+)/); | ||
if (m && m.length > 2) { | ||
return parseInt(m[1]) < 4 || (parseInt(m[1]) === 4 && parseInt(m[2]) < 4); | ||
} | ||
function isAndroidBelow44() { | ||
var match = navigator.userAgent.toLowerCase().match(/android[^\d]*(\d|.)/); | ||
if (match) { | ||
var version = match[0].split('.'); | ||
return version[0] < '4' || (version[0] === '4' && version[1] < '4'); | ||
return false; | ||
} | ||
return false; | ||
} | ||
ngFileUpload.validate = function (scope, $parse, attr, file, evt) { | ||
function globStringToRegex(str) { | ||
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 += '|'; | ||
} | ||
ngFileUpload.validate = function (scope, $parse, attr, file, evt) { | ||
function globStringToRegex(str) { | ||
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 += '|'; | ||
} | ||
} | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
} | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
var accept = $parse(attr.ngfAccept)(scope, {$file: file, $event: evt}); | ||
var fileSizeMax = $parse(attr.ngfMaxSize)(scope, {$file: file, $event: evt}) || 9007199254740991; | ||
var fileSizeMin = $parse(attr.ngfMinSize)(scope, {$file: file, $event: evt}) || -1; | ||
if (accept != null && angular.isString(accept)) { | ||
var regexp = new RegExp(globStringToRegex(accept), 'gi'); | ||
accept = (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
} | ||
return (accept == null || accept) && (file.size == null || (file.size < fileSizeMax && file.size > fileSizeMin)); | ||
}; | ||
var accept = $parse(attr.ngfAccept)(scope, {$file: file, $event: evt}); | ||
var fileSizeMax = $parse(attr.ngfMaxSize)(scope, {$file: file, $event: evt}) || 9007199254740991; | ||
var fileSizeMin = $parse(attr.ngfMinSize)(scope, {$file: file, $event: evt}) || -1; | ||
if (accept != null && angular.isString(accept)) { | ||
var regexp = new RegExp(globStringToRegex(accept), 'gi'); | ||
accept = (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
} | ||
return (accept == null || accept) && (file.size == null || (file.size < fileSizeMax && file.size > fileSizeMin)); | ||
}; | ||
ngFileUpload.updateModel = function ($parse, $timeout, scope, ngModel, attr, fileChange, | ||
files, rejFiles, evt, noDelay) { | ||
function update() { | ||
if ($parse(attr.ngfKeep)(scope) === true) { | ||
if (!files || !files.length) { | ||
return; | ||
} | ||
if ($parse(attr.ngfKeepDistinct)(scope) === true) { | ||
var prevFiles = (ngModel.$modelValue || []).slice(0), len = prevFiles.length; | ||
for (var i = 0; i < files.length; i++) { | ||
for (var j = 0; j < len; j++) { | ||
if (files[i].name === prevFiles[j].name) break; | ||
ngFileUpload.updateModel = function ($parse, $timeout, scope, ngModel, attr, fileChange, | ||
files, rejFiles, evt, noDelay) { | ||
function update() { | ||
if ($parse(attr.ngfKeep)(scope) === true) { | ||
if (!files || !files.length) { | ||
return; | ||
} | ||
if ($parse(attr.ngfKeepDistinct)(scope) === true) { | ||
var prevFiles = (ngModel.$modelValue || []).slice(0), len = prevFiles.length; | ||
for (var i = 0; i < files.length; i++) { | ||
for (var j = 0; j < len; j++) { | ||
if (files[i].name === prevFiles[j].name) break; | ||
} | ||
if (j === len) { | ||
prevFiles.push(files[i]); | ||
} | ||
} | ||
if (len === prevFiles.length) { | ||
return; | ||
} | ||
files = [].concat(prevFiles); | ||
} else { | ||
files = (ngModel.$modelValue || []).concat(files); | ||
} | ||
} | ||
if (j === len) { | ||
prevFiles.push(files[i]); | ||
if (ngModel) { | ||
$parse(attr.ngModel).assign(scope, files); | ||
$timeout(function () { | ||
if (ngModel) { | ||
ngModel.$setViewValue(files != null && files.length === 0 ? null : files); | ||
} | ||
}); | ||
} | ||
} | ||
if (len === prevFiles.length) { | ||
return; | ||
} | ||
files = [].concat(prevFiles); | ||
if (attr.ngModelRejected) { | ||
$parse(attr.ngModelRejected).assign(scope, rejFiles); | ||
} | ||
if (fileChange) { | ||
$parse(fileChange)(scope, { | ||
$files: files, | ||
$rejectedFiles: rejFiles, | ||
$event: evt | ||
}); | ||
} | ||
} | ||
if (noDelay) { | ||
update(); | ||
} else { | ||
files = (ngModel.$modelValue || []).concat(files); | ||
$timeout(function () { | ||
update(); | ||
}); | ||
} | ||
} | ||
if (ngModel) { | ||
$parse(attr.ngModel).assign(scope, files); | ||
$timeout(function () { | ||
if (ngModel) { | ||
ngModel.$setViewValue(files != null && files.length === 0 ? null : files); | ||
} | ||
}); | ||
} | ||
if (attr.ngModelRejected) { | ||
$parse(attr.ngModelRejected).assign(scope, rejFiles); | ||
} | ||
if (fileChange) { | ||
$parse(fileChange)(scope, { | ||
$files: files, | ||
$rejectedFiles: rejFiles, | ||
$event: evt | ||
}); | ||
} | ||
} | ||
}; | ||
if (noDelay) { | ||
update(); | ||
} else { | ||
$timeout(function () { | ||
update(); | ||
}); | ||
} | ||
}; | ||
var validate = ngFileUpload.validate; | ||
var updateModel = ngFileUpload.updateModel; | ||
var validate = ngFileUpload.validate; | ||
var updateModel = ngFileUpload.updateModel; | ||
})(); | ||
@@ -470,0 +471,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! 5.0.0 */ | ||
var ngFileUpload=angular.module("ngFileUpload",[]);ngFileUpload.version="5.0.0",ngFileUpload.service("Upload",["$http","$q","$timeout",function(a,b,c){function d(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function e(d){d.method=d.method||"POST",d.headers=d.headers||{};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progressFunc=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&d("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}}),this.upload=function(a){function b(c,d,e){if(void 0!==d)if(angular.isDate(d)&&(d=d.toISOString()),angular.isString(d))c.append(e,d);else if("form"===a.sendFieldsAs)if(angular.isObject(d))for(var f in d)d.hasOwnProperty(f)&&b(c,d[f],e+"["+f+"]");else c.append(e,d);else d=angular.isString(d)?d:JSON.stringify(d),"json-blob"===a.sendFieldsAs?c.append(e,new Blob([d],{type:"application/json"})):c.append(e,d)}return a.headers=a.headers||{},a.headers["Content-Type"]=void 0,a.transformRequest=a.transformRequest?angular.isArray(a.transformRequest)?a.transformRequest:[a.transformRequest]:[],a.transformRequest.push(function(c){var d,e=new FormData,f={};for(d in a.fields)a.fields.hasOwnProperty(d)&&(f[d]=a.fields[d]);c&&(f.data=c);for(d in f)if(f.hasOwnProperty(d)){var g=f[d];a.formDataAppender?a.formDataAppender(e,d,g):b(e,g,d)}if(null!=a.file){var h=a.fileFormDataName||"file";if(angular.isArray(a.file))for(var i=angular.isString(h),j=0;j<a.file.length;j++)e.append(i?h:h[j],a.file[j],a.fileName&&a.fileName[j]||a.file[j].name);else e.append(h,a.file,a.fileName||a.file.name)}return e}),e(a)},this.http=function(b){return b.transformRequest=b.transformRequest||function(b){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](arguments)},e(b)}}]),function(){function a(a,e,f,g,h,i,j){function k(){return"input"===e[0].tagName.toLowerCase()&&f.type&&"file"===f.type.toLowerCase()}function l(b){if(!r){r=!0;try{for(var e=b.__files_||b.target&&b.target.files,j=[],k=[],l=0;l<e.length;l++){var m=e.item(l);c(a,h,f,m,b)?j.push(m):k.push(m)}d(h,i,a,g,f,f.ngfChange||f.ngfSelect,j,k,b),0===j.length&&(b.target.value=j)}finally{r=!1}}}function m(b){f.ngfMultiple&&b.attr("multiple",h(f.ngfMultiple)(a)),f.ngfCapture&&b.attr("capture",h(f.ngfCapture)(a)),f.accept&&b.attr("accept",f.accept);for(var c=0;c<e[0].attributes.length;c++){var d=e[0].attributes[c];(k()&&"type"!==d.name||"type"!==d.name&&"class"!==d.name&&"id"!==d.name&&"style"!==d.name)&&b.attr(d.name,d.value)}}function n(b,c){if(!e.attr("disabled")&&!q){if(!c&&(b||k()))return e.$$ngfRefElem||e;var d=angular.element('<input type="file">');return m(d),k()?(e.replaceWith(d),e=d,d.attr("__ngf_gen__",!0),j(e)(a)):(d.css("visibility","hidden").css("position","absolute").css("width","9").css("height","1").css("z-index","-100000").attr("tabindex","-1"),e.$$ngfRefElem&&e.$$ngfRefElem.remove(),e.$$ngfRefElem=d,document.body.appendChild(d[0])),d}}function o(b){d(h,i,a,g,f,f.ngfChange||f.ngfSelect,[],[],b,!0)}function p(c){function d(a){a&&i[0].click(),(k()||!a)&&e.bind("click touchend",p)}null!=c&&(c.preventDefault(),c.stopPropagation());var g=h(f.ngfResetOnClick)(a)!==!1,i=n(c,g);return i&&((!c||g)&&i.bind("change",l),c&&g&&h(f.ngfResetModelOnClick)(a)!==!1&&o(c),b()?setTimeout(function(){d(c)},0):d(c)),!1}if(!e.attr("__ngf_gen__")){a.$on("$destroy",function(){e.$$ngfRefElem&&e.$$ngfRefElem.remove()});var q=!1;-1===f.ngfSelect.search(/\W+$files\W+/)&&a.$watch(f.ngfSelect,function(a){q=a===!1});var r=!1;window.FileAPI&&window.FileAPI.ngfFixIE?window.FileAPI.ngfFixIE(e,n,m,l):p()}}function b(){var a=navigator.userAgent.toLowerCase().match(/android[^\d]*(\d|.)/);if(a){var b=a[0].split(".");return b[0]<"4"||"4"===b[0]&&b[1]<"4"}return!1}ngFileUpload.directive("ngfSelect",["$parse","$timeout","$compile",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.validate=function(a,b,c,d,e){function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d<b.length;d++)c+="("+f(b[d])+")",d<b.length-1&&(c+="|");else 0===a.indexOf(".")&&(a="*"+a),c="^"+a.replace(new RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}var g=b(c.ngfAccept)(a,{$file:d,$event:e}),h=b(c.ngfMaxSize)(a,{$file:d,$event:e})||9007199254740991,i=b(c.ngfMinSize)(a,{$file:d,$event:e})||-1;if(null!=g&&angular.isString(g)){var j=new RegExp(f(g),"gi");g=null!=d.type&&j.test(d.type.toLowerCase())||null!=d.name&&j.test(d.name.toLowerCase())}return(null==g||g)&&(null==d.size||d.size<h&&d.size>i)},ngFileUpload.updateModel=function(a,b,c,d,e,f,g,h,i,j){function k(){if(a(e.ngfKeep)(c)===!0){if(!g||!g.length)return;if(a(e.ngfKeepDistinct)(c)===!0){for(var j=(d.$modelValue||[]).slice(0),k=j.length,l=0;l<g.length;l++){for(var m=0;k>m&&g[l].name!==j[m].name;m++);m===k&&j.push(g[l])}if(k===j.length)return;g=[].concat(j)}else g=(d.$modelValue||[]).concat(g)}d&&(a(e.ngModel).assign(c,g),b(function(){d&&d.$setViewValue(null!=g&&0===g.length?null:g)})),e.ngModelRejected&&a(e.ngModelRejected).assign(c,h),f&&a(f)(c,{$files:g,$rejectedFiles:h,$event:i})}j?k():b(function(){k()})};var c=ngFileUpload.validate,d=ngFileUpload.updateModel}(),function(){function a(a,e,f,g,h,i,j){function k(a,b,d){var e=!0,f=d.dataTransfer.items;if(null!=f)for(var g=0;g<f.length&&e;g++)e=e&&("file"===f[g].kind||""===f[g].kind)&&c(a,h,b,f[g],d);var i=h(b.ngfDragOverClass)(a,{$event:d});return i&&(i.delay&&(r=i.delay),i.accept&&(i=e?i.accept:i.reject)),i||b.ngfDragOverClass||"dragover"}function l(b,d,e,g){function k(d){c(a,h,f,d,b)?m.push(d):n.push(d)}function l(a,b,c){if(null!=b)if(b.isDirectory){var d=(c||"")+b.name;k({name:b.name,type:"directory",path:d});var e=b.createReader(),f=[];p++;var g=function(){e.readEntries(function(d){try{if(d.length)f=f.concat(Array.prototype.slice.call(d||[],0)),g();else{for(var e=0;e<f.length;e++)l(a,f[e],(c?c:"")+b.name+"/");p--}}catch(h){p--,console.error(h)}},function(){p--})};g()}else p++,b.file(function(a){try{p--,a.path=(c?c:"")+a.name,k(a)}catch(b){p--,console.error(b)}},function(){p--})}var m=[],n=[],o=b.dataTransfer.items,p=0;if(o&&o.length>0&&"file"!==j.protocol())for(var q=0;q<o.length;q++){if(o[q].webkitGetAsEntry&&o[q].webkitGetAsEntry()&&o[q].webkitGetAsEntry().isDirectory){var r=o[q].webkitGetAsEntry();if(r.isDirectory&&!e)continue;null!=r&&l(m,r)}else{var s=o[q].getAsFile();null!=s&&k(s)}if(!g&&m.length>0)break}else{var t=b.dataTransfer.files;if(null!=t)for(var u=0;u<t.length&&(k(t.item(u)),g||!(m.length>0));u++);}var v=0;!function w(a){i(function(){if(p)10*v++<2e4&&w(10);else{if(!g&&m.length>1){for(q=0;"directory"===m[q].type;)q++;m=[m[q]]}d(m,n)}},a||0)}()}var m=b();if(f.dropAvailable&&i(function(){a[f.dropAvailable]?a[f.dropAvailable].value=m:a[f.dropAvailable]=m}),!m)return void(h(f.ngfHideOnDropNotAvailable)(a)===!0&&e.css("display","none"));var n=!1;-1===f.ngfDrop.search(/\W+$files\W+/)&&a.$watch(f.ngfDrop,function(a){n=a===!1});var o,p=null,q=h(f.ngfStopPropagation),r=1;e[0].addEventListener("dragover",function(b){if(!e.attr("disabled")&&!n){if(b.preventDefault(),q(a)&&b.stopPropagation(),navigator.userAgent.indexOf("Chrome")>-1){var c=b.dataTransfer.effectAllowed;b.dataTransfer.dropEffect="move"===c||"linkMove"===c?"move":"copy"}i.cancel(p),a.actualDragOverClass||(o=k(a,f,b)),e.addClass(o)}},!1),e[0].addEventListener("dragenter",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation())},!1),e[0].addEventListener("dragleave",function(){e.attr("disabled")||n||(p=i(function(){e.removeClass(o),o=null},r||1))},!1),e[0].addEventListener("drop",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation(),e.removeClass(o),o=null,l(b,function(c,e){d(h,i,a,g,f,f.ngfChange||f.ngfDrop,c,e,b)},h(f.ngfAllowDir)(a)!==!1,f.multiple||h(f.ngfMultiple)(a)))},!1)}function b(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}var c=ngFileUpload.validate,d=ngFileUpload.updateModel;ngFileUpload.directive("ngfDrop",["$parse","$timeout","$location",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.directive("ngfNoFileDrop",function(){return function(a,c){b()&&c.css("display","none")}}),ngFileUpload.directive("ngfDropAvailable",["$parse","$timeout",function(a,c){return function(d,e,f){if(b()){var g=a(f.ngfDropAvailable);c(function(){g(d),g.assign&&g.assign(d,!0)})}}}]),ngFileUpload.directive("ngfSrc",["$parse","$timeout",function(a,b){return{restrict:"AE",link:function(d,e,f){window.FileReader&&d.$watch(f.ngfSrc,function(g){g&&c(d,a,f,g,null)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 8")||g.size<2e4)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 9")||g.size<4e6)?b(function(){var a=window.URL||window.webkitURL;if(a&&a.createObjectURL)e.attr("src",a.createObjectURL(g));else{var c=new FileReader;c.readAsDataURL(g),c.onload=function(a){b(function(){e.attr("src",a.target.result)})}}}):e.attr("src",f.ngfDefaultSrc||"")})}}}])}(); | ||
/*! 5.0.1 */ | ||
var ngFileUpload=angular.module("ngFileUpload",[]);ngFileUpload.version="5.0.1",ngFileUpload.service("Upload",["$http","$q","$timeout",function(a,b,c){function d(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])}function e(d){d.method=d.method||"POST",d.headers=d.headers||{};var e=b.defer(),f=e.promise;return d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&(a.config=d,e.notify?e.notify(a):f.progressFunc&&c(function(){f.progressFunc(a)}))},!1))}},a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)}),f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.progressFunc=a,f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}window.XMLHttpRequest&&!window.XMLHttpRequest.__isFileAPIShim&&d("setRequestHeader",function(a){return function(b,c){if("__setXHR_"===b){var d=c(this);d instanceof Function&&d(this)}else a.apply(this,arguments)}}),this.upload=function(a){function b(c,d,e){if(void 0!==d)if(angular.isDate(d)&&(d=d.toISOString()),angular.isString(d))c.append(e,d);else if("form"===a.sendFieldsAs)if(angular.isObject(d))for(var f in d)d.hasOwnProperty(f)&&b(c,d[f],e+"["+f+"]");else c.append(e,d);else d=angular.isString(d)?d:JSON.stringify(d),"json-blob"===a.sendFieldsAs?c.append(e,new Blob([d],{type:"application/json"})):c.append(e,d)}return a.headers=a.headers||{},a.headers["Content-Type"]=void 0,a.transformRequest=a.transformRequest?angular.isArray(a.transformRequest)?a.transformRequest:[a.transformRequest]:[],a.transformRequest.push(function(c){var d,e=new FormData,f={};for(d in a.fields)a.fields.hasOwnProperty(d)&&(f[d]=a.fields[d]);c&&(f.data=c);for(d in f)if(f.hasOwnProperty(d)){var g=f[d];a.formDataAppender?a.formDataAppender(e,d,g):b(e,g,d)}if(null!=a.file){var h=a.fileFormDataName||"file";if(angular.isArray(a.file))for(var i=angular.isString(h),j=0;j<a.file.length;j++)e.append(i?h:h[j],a.file[j],a.fileName&&a.fileName[j]||a.file[j].name);else e.append(h,a.file,a.fileName||a.file.name)}return e}),e(a)},this.http=function(b){return b.transformRequest=b.transformRequest||function(b){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](arguments)},e(b)}}]),function(){function a(a,e,f,g,h,i,j){function k(){return"input"===e[0].tagName.toLowerCase()&&f.type&&"file"===f.type.toLowerCase()}function l(b){if(!r){r=!0;try{for(var e=b.__files_||b.target&&b.target.files,j=[],k=[],l=0;l<e.length;l++){var m=e.item(l);c(a,h,f,m,b)?j.push(m):k.push(m)}d(h,i,a,g,f,f.ngfChange||f.ngfSelect,j,k,b),0===j.length&&(b.target.value=j)}finally{r=!1}}}function m(b){f.ngfMultiple&&b.attr("multiple",h(f.ngfMultiple)(a)),f.ngfCapture&&b.attr("capture",h(f.ngfCapture)(a)),f.accept&&b.attr("accept",f.accept);for(var c=0;c<e[0].attributes.length;c++){var d=e[0].attributes[c];(k()&&"type"!==d.name||"type"!==d.name&&"class"!==d.name&&"id"!==d.name&&"style"!==d.name)&&b.attr(d.name,d.value)}}function n(b,c){if(!e.attr("disabled")&&!q){if(!c&&(b||k()))return e.$$ngfRefElem||e;var d=angular.element('<input type="file">');return m(d),k()?(e.replaceWith(d),e=d,d.attr("__ngf_gen__",!0),j(e)(a)):(d.css("visibility","hidden").css("position","absolute").css("width","9").css("height","1").css("z-index","-100000").attr("tabindex","-1"),e.$$ngfRefElem&&e.$$ngfRefElem.remove(),e.$$ngfRefElem=d,document.body.appendChild(d[0])),d}}function o(b){d(h,i,a,g,f,f.ngfChange||f.ngfSelect,[],[],b,!0)}function p(c){function d(a){a&&i[0].click(),(k()||!a)&&e.bind("click touchend",p)}null!=c&&(c.preventDefault(),c.stopPropagation());var g=h(f.ngfResetOnClick)(a)!==!1,i=n(c,g);return i&&((!c||g)&&i.bind("change",l),c&&g&&h(f.ngfResetModelOnClick)(a)!==!1&&o(c),b(navigator.userAgent)?setTimeout(function(){d(c)},0):d(c)),!1}if(!e.attr("__ngf_gen__")){a.$on("$destroy",function(){e.$$ngfRefElem&&e.$$ngfRefElem.remove()});var q=!1;-1===f.ngfSelect.search(/\W+$files\W+/)&&a.$watch(f.ngfSelect,function(a){q=a===!1});var r=!1;window.FileAPI&&window.FileAPI.ngfFixIE?window.FileAPI.ngfFixIE(e,n,m,l):p()}}function b(a){var b=a.match(/Android[^\d]*(\d+)\.(\d+)/);return b&&b.length>2?parseInt(b[1])<4||4===parseInt(b[1])&&parseInt(b[2])<4:!1}ngFileUpload.directive("ngfSelect",["$parse","$timeout","$compile",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.validate=function(a,b,c,d,e){function f(a){if(a.length>2&&"/"===a[0]&&"/"===a[a.length-1])return a.substring(1,a.length-1);var b=a.split(","),c="";if(b.length>1)for(var d=0;d<b.length;d++)c+="("+f(b[d])+")",d<b.length-1&&(c+="|");else 0===a.indexOf(".")&&(a="*"+a),c="^"+a.replace(new RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]","g"),"\\$&")+"$",c=c.replace(/\\\*/g,".*").replace(/\\\?/g,".");return c}var g=b(c.ngfAccept)(a,{$file:d,$event:e}),h=b(c.ngfMaxSize)(a,{$file:d,$event:e})||9007199254740991,i=b(c.ngfMinSize)(a,{$file:d,$event:e})||-1;if(null!=g&&angular.isString(g)){var j=new RegExp(f(g),"gi");g=null!=d.type&&j.test(d.type.toLowerCase())||null!=d.name&&j.test(d.name.toLowerCase())}return(null==g||g)&&(null==d.size||d.size<h&&d.size>i)},ngFileUpload.updateModel=function(a,b,c,d,e,f,g,h,i,j){function k(){if(a(e.ngfKeep)(c)===!0){if(!g||!g.length)return;if(a(e.ngfKeepDistinct)(c)===!0){for(var j=(d.$modelValue||[]).slice(0),k=j.length,l=0;l<g.length;l++){for(var m=0;k>m&&g[l].name!==j[m].name;m++);m===k&&j.push(g[l])}if(k===j.length)return;g=[].concat(j)}else g=(d.$modelValue||[]).concat(g)}d&&(a(e.ngModel).assign(c,g),b(function(){d&&d.$setViewValue(null!=g&&0===g.length?null:g)})),e.ngModelRejected&&a(e.ngModelRejected).assign(c,h),f&&a(f)(c,{$files:g,$rejectedFiles:h,$event:i})}j?k():b(function(){k()})};var c=ngFileUpload.validate,d=ngFileUpload.updateModel}(),function(){function a(a,e,f,g,h,i,j){function k(a,b,d){var e=!0,f=d.dataTransfer.items;if(null!=f)for(var g=0;g<f.length&&e;g++)e=e&&("file"===f[g].kind||""===f[g].kind)&&c(a,h,b,f[g],d);var i=h(b.ngfDragOverClass)(a,{$event:d});return i&&(i.delay&&(r=i.delay),i.accept&&(i=e?i.accept:i.reject)),i||b.ngfDragOverClass||"dragover"}function l(b,d,e,g){function k(d){c(a,h,f,d,b)?m.push(d):n.push(d)}function l(a,b,c){if(null!=b)if(b.isDirectory){var d=(c||"")+b.name;k({name:b.name,type:"directory",path:d});var e=b.createReader(),f=[];p++;var g=function(){e.readEntries(function(d){try{if(d.length)f=f.concat(Array.prototype.slice.call(d||[],0)),g();else{for(var e=0;e<f.length;e++)l(a,f[e],(c?c:"")+b.name+"/");p--}}catch(h){p--,console.error(h)}},function(){p--})};g()}else p++,b.file(function(a){try{p--,a.path=(c?c:"")+a.name,k(a)}catch(b){p--,console.error(b)}},function(){p--})}var m=[],n=[],o=b.dataTransfer.items,p=0;if(o&&o.length>0&&"file"!==j.protocol())for(var q=0;q<o.length;q++){if(o[q].webkitGetAsEntry&&o[q].webkitGetAsEntry()&&o[q].webkitGetAsEntry().isDirectory){var r=o[q].webkitGetAsEntry();if(r.isDirectory&&!e)continue;null!=r&&l(m,r)}else{var s=o[q].getAsFile();null!=s&&k(s)}if(!g&&m.length>0)break}else{var t=b.dataTransfer.files;if(null!=t)for(var u=0;u<t.length&&(k(t.item(u)),g||!(m.length>0));u++);}var v=0;!function w(a){i(function(){if(p)10*v++<2e4&&w(10);else{if(!g&&m.length>1){for(q=0;"directory"===m[q].type;)q++;m=[m[q]]}d(m,n)}},a||0)}()}var m=b();if(f.dropAvailable&&i(function(){a[f.dropAvailable]?a[f.dropAvailable].value=m:a[f.dropAvailable]=m}),!m)return void(h(f.ngfHideOnDropNotAvailable)(a)===!0&&e.css("display","none"));var n=!1;-1===f.ngfDrop.search(/\W+$files\W+/)&&a.$watch(f.ngfDrop,function(a){n=a===!1});var o,p=null,q=h(f.ngfStopPropagation),r=1;e[0].addEventListener("dragover",function(b){if(!e.attr("disabled")&&!n){if(b.preventDefault(),q(a)&&b.stopPropagation(),navigator.userAgent.indexOf("Chrome")>-1){var c=b.dataTransfer.effectAllowed;b.dataTransfer.dropEffect="move"===c||"linkMove"===c?"move":"copy"}i.cancel(p),a.actualDragOverClass||(o=k(a,f,b)),e.addClass(o)}},!1),e[0].addEventListener("dragenter",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation())},!1),e[0].addEventListener("dragleave",function(){e.attr("disabled")||n||(p=i(function(){e.removeClass(o),o=null},r||1))},!1),e[0].addEventListener("drop",function(b){e.attr("disabled")||n||(b.preventDefault(),q(a)&&b.stopPropagation(),e.removeClass(o),o=null,l(b,function(c,e){d(h,i,a,g,f,f.ngfChange||f.ngfDrop,c,e,b)},h(f.ngfAllowDir)(a)!==!1,f.multiple||h(f.ngfMultiple)(a)))},!1)}function b(){var a=document.createElement("div");return"draggable"in a&&"ondrop"in a}var c=ngFileUpload.validate,d=ngFileUpload.updateModel;ngFileUpload.directive("ngfDrop",["$parse","$timeout","$location",function(b,c,d){return{restrict:"AEC",require:"?ngModel",link:function(e,f,g,h){a(e,f,g,h,b,c,d)}}}]),ngFileUpload.directive("ngfNoFileDrop",function(){return function(a,c){b()&&c.css("display","none")}}),ngFileUpload.directive("ngfDropAvailable",["$parse","$timeout",function(a,c){return function(d,e,f){if(b()){var g=a(f.ngfDropAvailable);c(function(){g(d),g.assign&&g.assign(d,!0)})}}}]),ngFileUpload.directive("ngfSrc",["$parse","$timeout",function(a,b){return{restrict:"AE",link:function(d,e,f){window.FileReader&&d.$watch(f.ngfSrc,function(g){g&&c(d,a,f,g,null)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 8")||g.size<2e4)&&(!window.FileAPI||-1===navigator.userAgent.indexOf("MSIE 9")||g.size<4e6)?b(function(){var a=window.URL||window.webkitURL;if(a&&a.createObjectURL)e.attr("src",a.createObjectURL(g));else{var c=new FileReader;c.readAsDataURL(g),c.onload=function(a){b(function(){e.attr("src",a.target.result)})}}}):e.attr("src",f.ngfDefaultSrc||"")})}}}])}(); |
'use strict'; | ||
var app = angular.module('fileUpload', [ 'ngFileUpload' ]); | ||
var app = angular.module('fileUpload', ['ngFileUpload']); | ||
var version = '5.0.0'; | ||
app.controller('MyCtrl', [ '$scope', '$http', '$timeout', '$compile', 'Upload', function($scope, $http, $timeout, $compile, Upload) { | ||
$scope.usingFlash = FileAPI && FileAPI.upload != null; | ||
app.controller('MyCtrl', ['$scope', '$http', '$timeout', '$compile', 'Upload', function ($scope, $http, $timeout, $compile, Upload) { | ||
$scope.usingFlash = FileAPI && FileAPI.upload != null; | ||
$scope.changeAngularVersion = function() { | ||
window.location.hash = $scope.angularVersion; | ||
window.location.reload(true); | ||
}; | ||
$scope.changeAngularVersion = function () { | ||
window.location.hash = $scope.angularVersion; | ||
window.location.reload(true); | ||
}; | ||
$scope.angularVersion = window.location.hash.length > 1 ? (window.location.hash.indexOf('/') === 1 ? | ||
window.location.hash.substring(2): window.location.hash.substring(1)) : '1.2.20'; | ||
$scope.angularVersion = window.location.hash.length > 1 ? (window.location.hash.indexOf('/') === 1 ? | ||
window.location.hash.substring(2) : window.location.hash.substring(1)) : '1.2.20'; | ||
$scope.$watch('files', function(files) { | ||
$scope.formUpload = false; | ||
if (files != null) { | ||
for (var i = 0; i < files.length; i++) { | ||
$scope.errorMsg = null; | ||
(function(file) { | ||
upload(file); | ||
})(files[i]); | ||
} | ||
} | ||
}); | ||
$scope.$watch('files', function (files) { | ||
$scope.formUpload = false; | ||
if (files != null) { | ||
for (var i = 0; i < files.length; i++) { | ||
$scope.errorMsg = null; | ||
(function (file) { | ||
upload(file); | ||
})(files[i]); | ||
} | ||
} | ||
}); | ||
$scope.uploadPic = function(files) { | ||
$scope.formUpload = true; | ||
if (files != null) { | ||
upload(files[0]) | ||
} | ||
}; | ||
$scope.uploadPic = function (files) { | ||
$scope.formUpload = true; | ||
if (files != null) { | ||
upload(files[0]) | ||
} | ||
}; | ||
function upload(file) { | ||
$scope.errorMsg = null; | ||
if ($scope.howToSend === 1) { | ||
uploadUsingUpload(file); | ||
} else if ($scope.howToSend == 2) { | ||
uploadUsing$http(file); | ||
} else { | ||
uploadS3(file); | ||
} | ||
} | ||
function upload(file) { | ||
$scope.errorMsg = null; | ||
if ($scope.howToSend === 1) { | ||
uploadUsingUpload(file); | ||
} else if ($scope.howToSend == 2) { | ||
uploadUsing$http(file); | ||
} else { | ||
uploadS3(file); | ||
} | ||
} | ||
function uploadUsingUpload(file) { | ||
file.upload = Upload.upload({ | ||
url: 'https://angular-file-upload-cors-srv.appspot.com/upload' + $scope.getReqParams(), | ||
method: 'POST', | ||
headers: { | ||
'my-header' : 'my-header-value' | ||
}, | ||
fields: {username: $scope.username}, | ||
file: file, | ||
fileFormDataName: 'myFile' | ||
}); | ||
function uploadUsingUpload(file) { | ||
file.upload = Upload.upload({ | ||
url: 'https://angular-file-upload-cors-srv.appspot.com/upload' + $scope.getReqParams(), | ||
method: 'POST', | ||
headers: { | ||
'my-header': 'my-header-value' | ||
}, | ||
fields: {username: $scope.username}, | ||
file: file, | ||
fileFormDataName: 'myFile' | ||
}); | ||
file.upload.then(function(response) { | ||
$timeout(function() { | ||
file.result = response.data; | ||
}); | ||
}, function(response) { | ||
if (response.status > 0) | ||
$scope.errorMsg = response.status + ': ' + response.data; | ||
}); | ||
file.upload.then(function (response) { | ||
$timeout(function () { | ||
file.result = response.data; | ||
}); | ||
}, function (response) { | ||
if (response.status > 0) | ||
$scope.errorMsg = response.status + ': ' + response.data; | ||
}); | ||
file.upload.progress(function(evt) { | ||
// Math.min is to fix IE which reports 200% sometimes | ||
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); | ||
}); | ||
file.upload.progress(function (evt) { | ||
// Math.min is to fix IE which reports 200% sometimes | ||
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); | ||
}); | ||
file.upload.xhr(function(xhr) { | ||
// xhr.upload.addEventListener('abort', function(){console.log('abort complete')}, false); | ||
}); | ||
} | ||
file.upload.xhr(function (xhr) { | ||
// xhr.upload.addEventListener('abort', function(){console.log('abort complete')}, false); | ||
}); | ||
} | ||
function uploadUsing$http(file) { | ||
file.upload = Upload.http({ | ||
url: 'https://angular-file-upload-cors-srv.appspot.com/upload' + $scope.getReqParams(), | ||
method: 'POST', | ||
headers : { | ||
'Content-Type': file.type | ||
}, | ||
data: file | ||
}); | ||
function uploadUsing$http(file) { | ||
file.upload = Upload.http({ | ||
url: 'https://angular-file-upload-cors-srv.appspot.com/upload' + $scope.getReqParams(), | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': file.type | ||
}, | ||
data: file | ||
}); | ||
file.upload.then(function(response) { | ||
file.result = response.data; | ||
}, function(response) { | ||
if (response.status > 0) | ||
$scope.errorMsg = response.status + ': ' + response.data; | ||
}); | ||
file.upload.then(function (response) { | ||
file.result = response.data; | ||
}, function (response) { | ||
if (response.status > 0) | ||
$scope.errorMsg = response.status + ': ' + response.data; | ||
}); | ||
file.upload.progress(function(evt) { | ||
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); | ||
}); | ||
} | ||
file.upload.progress(function (evt) { | ||
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); | ||
}); | ||
} | ||
function uploadS3(file) { | ||
file.upload = Upload.upload({ | ||
url : $scope.s3url, | ||
method : 'POST', | ||
fields : { | ||
key : file.name, | ||
AWSAccessKeyId : $scope.AWSAccessKeyId, | ||
acl : $scope.acl, | ||
policy : $scope.policy, | ||
signature : $scope.signature, | ||
'Content-Type' : file.type === null || file.type === '' ? 'application/octet-stream' : file.type, | ||
filename : file.name | ||
}, | ||
file : file | ||
}); | ||
function uploadS3(file) { | ||
file.upload = Upload.upload({ | ||
url: $scope.s3url, | ||
method: 'POST', | ||
fields: { | ||
key: file.name, | ||
AWSAccessKeyId: $scope.AWSAccessKeyId, | ||
acl: $scope.acl, | ||
policy: $scope.policy, | ||
signature: $scope.signature, | ||
'Content-Type': file.type === null || file.type === '' ? 'application/octet-stream' : file.type, | ||
filename: file.name | ||
}, | ||
file: file | ||
}); | ||
file.upload.then(function(response) { | ||
$timeout(function() { | ||
file.result = response.data; | ||
}); | ||
}, function(response) { | ||
if (response.status > 0) | ||
$scope.errorMsg = response.status + ': ' + response.data; | ||
}); | ||
file.upload.then(function (response) { | ||
$timeout(function () { | ||
file.result = response.data; | ||
}); | ||
}, function (response) { | ||
if (response.status > 0) | ||
$scope.errorMsg = response.status + ': ' + response.data; | ||
}); | ||
file.upload.progress(function(evt) { | ||
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); | ||
}); | ||
storeS3UploadConfigInLocalStore(); | ||
} | ||
file.upload.progress(function (evt) { | ||
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); | ||
}); | ||
storeS3UploadConfigInLocalStore(); | ||
} | ||
$scope.generateSignature = function() { | ||
$http.post('/s3sign?aws-secret-key=' + encodeURIComponent($scope.AWSSecretKey), $scope.jsonPolicy). | ||
success(function(data) { | ||
$scope.policy = data.policy; | ||
$scope.signature = data.signature; | ||
}); | ||
}; | ||
$scope.generateSignature = function () { | ||
$http.post('/s3sign?aws-secret-key=' + encodeURIComponent($scope.AWSSecretKey), $scope.jsonPolicy). | ||
success(function (data) { | ||
$scope.policy = data.policy; | ||
$scope.signature = data.signature; | ||
}); | ||
}; | ||
if (localStorage) { | ||
$scope.s3url = localStorage.getItem('s3url'); | ||
$scope.AWSAccessKeyId = localStorage.getItem('AWSAccessKeyId'); | ||
$scope.acl = localStorage.getItem('acl'); | ||
$scope.success_action_redirect = localStorage.getItem('success_action_redirect'); | ||
$scope.policy = localStorage.getItem('policy'); | ||
$scope.signature = localStorage.getItem('signature'); | ||
} | ||
if (localStorage) { | ||
$scope.s3url = localStorage.getItem('s3url'); | ||
$scope.AWSAccessKeyId = localStorage.getItem('AWSAccessKeyId'); | ||
$scope.acl = localStorage.getItem('acl'); | ||
$scope.success_action_redirect = localStorage.getItem('success_action_redirect'); | ||
$scope.policy = localStorage.getItem('policy'); | ||
$scope.signature = localStorage.getItem('signature'); | ||
} | ||
$scope.success_action_redirect = $scope.success_action_redirect || window.location.protocol + '//' + window.location.host; | ||
$scope.jsonPolicy = $scope.jsonPolicy || '{\n "expiration": "2020-01-01T00:00:00Z",\n "conditions": [\n {"bucket": "angular-file-upload"},\n ["starts-with", "$key", ""],\n {"acl": "private"},\n ["starts-with", "$Content-Type", ""],\n ["starts-with", "$filename", ""],\n ["content-length-range", 0, 524288000]\n ]\n}'; | ||
$scope.acl = $scope.acl || 'private'; | ||
$scope.success_action_redirect = $scope.success_action_redirect || window.location.protocol + '//' + window.location.host; | ||
$scope.jsonPolicy = $scope.jsonPolicy || '{\n "expiration": "2020-01-01T00:00:00Z",\n "conditions": [\n {"bucket": "angular-file-upload"},\n ["starts-with", "$key", ""],\n {"acl": "private"},\n ["starts-with", "$Content-Type", ""],\n ["starts-with", "$filename", ""],\n ["content-length-range", 0, 524288000]\n ]\n}'; | ||
$scope.acl = $scope.acl || 'private'; | ||
function storeS3UploadConfigInLocalStore() { | ||
if ($scope.howToSend === 3 && localStorage) { | ||
localStorage.setItem('s3url', $scope.s3url); | ||
localStorage.setItem('AWSAccessKeyId', $scope.AWSAccessKeyId); | ||
localStorage.setItem('acl', $scope.acl); | ||
localStorage.setItem('success_action_redirect', $scope.success_action_redirect); | ||
localStorage.setItem('policy', $scope.policy); | ||
localStorage.setItem('signature', $scope.signature); | ||
} | ||
} | ||
function storeS3UploadConfigInLocalStore() { | ||
if ($scope.howToSend === 3 && localStorage) { | ||
localStorage.setItem('s3url', $scope.s3url); | ||
localStorage.setItem('AWSAccessKeyId', $scope.AWSAccessKeyId); | ||
localStorage.setItem('acl', $scope.acl); | ||
localStorage.setItem('success_action_redirect', $scope.success_action_redirect); | ||
localStorage.setItem('policy', $scope.policy); | ||
localStorage.setItem('signature', $scope.signature); | ||
} | ||
} | ||
(function handleDynamicEditingOfScriptsAndHtml($scope) { | ||
$scope.defaultHtml = document.getElementById('editArea').innerHTML.replace(/\t\t\t\t/g, ''); | ||
(function handleDynamicEditingOfScriptsAndHtml($scope) { | ||
$scope.defaultHtml = document.getElementById('editArea').innerHTML.replace(/\t\t\t\t/g, ''); | ||
$scope.editHtml = (localStorage && localStorage.getItem('editHtml' + version)) || $scope.defaultHtml; | ||
function htmlEdit() { | ||
document.getElementById('editArea').innerHTML = $scope.editHtml; | ||
$compile(document.getElementById('editArea'))($scope); | ||
$scope.editHtml && localStorage && localStorage.setItem('editHtml' + version, $scope.editHtml); | ||
if ($scope.editHtml != $scope.htmlEditor.getValue()) $scope.htmlEditor.setValue($scope.editHtml); | ||
} | ||
$scope.$watch('editHtml', htmlEdit); | ||
$scope.editHtml = (localStorage && localStorage.getItem('editHtml' + version)) || $scope.defaultHtml; | ||
function htmlEdit() { | ||
document.getElementById('editArea').innerHTML = $scope.editHtml; | ||
$compile(document.getElementById('editArea'))($scope); | ||
$scope.editHtml && localStorage && localStorage.setItem('editHtml' + version, $scope.editHtml); | ||
if ($scope.editHtml != $scope.htmlEditor.getValue()) $scope.htmlEditor.setValue($scope.editHtml); | ||
} | ||
$scope.htmlEditor = CodeMirror(document.getElementById('htmlEdit'), { | ||
lineNumbers: true, indentUnit: 4, | ||
mode: 'htmlmixed' | ||
}); | ||
$scope.htmlEditor.on('change', function() { | ||
if ($scope.editHtml != $scope.htmlEditor.getValue()) { | ||
$scope.editHtml = $scope.htmlEditor.getValue(); | ||
htmlEdit(); | ||
} | ||
}); | ||
})($scope, $http); | ||
$scope.$watch('editHtml', htmlEdit); | ||
$scope.confirm = function() { | ||
return confirm('Are you sure? Your local changes will be lost.'); | ||
}; | ||
$scope.htmlEditor = CodeMirror(document.getElementById('htmlEdit'), { | ||
lineNumbers: true, indentUnit: 4, | ||
mode: 'htmlmixed' | ||
}); | ||
$scope.htmlEditor.on('change', function () { | ||
if ($scope.editHtml != $scope.htmlEditor.getValue()) { | ||
$scope.editHtml = $scope.htmlEditor.getValue(); | ||
htmlEdit(); | ||
} | ||
}); | ||
})($scope, $http); | ||
$scope.getReqParams = function() { | ||
return $scope.generateErrorOnServer ? '?errorCode=' + $scope.serverErrorCode + | ||
'&errorMessage=' + $scope.serverErrorMsg : ''; | ||
}; | ||
$scope.confirm = function () { | ||
return confirm('Are you sure? Your local changes will be lost.'); | ||
}; | ||
angular.element(window).bind('dragover', function(e) { | ||
e.preventDefault(); | ||
}); | ||
angular.element(window).bind('drop', function(e) { | ||
e.preventDefault(); | ||
}); | ||
$scope.getReqParams = function () { | ||
return $scope.generateErrorOnServer ? '?errorCode=' + $scope.serverErrorCode + | ||
'&errorMessage=' + $scope.serverErrorMsg : ''; | ||
}; | ||
$timeout(function(){ | ||
$scope.capture = localStorage.getItem('capture'+ version) || 'camera'; | ||
$scope.accept = localStorage.getItem('accept'+ version) || 'image/*,audio/*,video/*'; | ||
$scope.acceptSelect = localStorage.getItem('acceptSelect'+ version) || 'image/*,audio/*,video/*'; | ||
$scope.disabled = localStorage.getItem('disabled'+ version) == 'true' || false; | ||
$scope.multiple = localStorage.getItem('multiple'+ version) == 'true' || false; | ||
$scope.allowDir = localStorage.getItem('allowDir'+ version) == 'true' || true; | ||
$scope.resetOnClick = localStorage.getItem('resetOnClick'+ version) == 'true' || true; | ||
$scope.resetModelOnClick = localStorage.getItem('resetModelOnClick'+ version) == 'true' || true; | ||
$scope.keep = localStorage.getItem('keep'+ version) == 'true' || false; | ||
$scope.keepDistinct = localStorage.getItem('keepDistinct'+ version) == 'true' || false; | ||
$scope.$watch('capture+accept+acceptSelect+disabled+capture+multiple+allowDir+resetOnClick+resetModelOnClick+keep+keepDistinct', function() { | ||
localStorage.setItem('capture'+ version, $scope.capture); | ||
localStorage.setItem('accept'+ version, $scope.accept); | ||
localStorage.setItem('acceptSelect'+ version, $scope.acceptSelect); | ||
localStorage.setItem('disabled'+ version, $scope.disabled); | ||
localStorage.setItem('multiple'+ version, $scope.multiple); | ||
localStorage.setItem('allowDir'+ version, $scope.allowDir); | ||
localStorage.setItem('resetOnClick'+ version, $scope.resetOnClick); | ||
localStorage.setItem('resetModelOnClick'+ version, $scope.resetModelOnClick); | ||
localStorage.setItem('keep'+ version, $scope.keep); | ||
localStorage.setItem('keepDistinct'+ version, $scope.keepDistinct); | ||
}); | ||
}); | ||
angular.element(window).bind('dragover', function (e) { | ||
e.preventDefault(); | ||
}); | ||
angular.element(window).bind('drop', function (e) { | ||
e.preventDefault(); | ||
}); | ||
} ]); | ||
$timeout(function () { | ||
$scope.capture = localStorage.getItem('capture' + version) || 'camera'; | ||
$scope.accept = localStorage.getItem('accept' + version) || 'image/*,audio/*,video/*'; | ||
$scope.acceptSelect = localStorage.getItem('acceptSelect' + version) || 'image/*,audio/*,video/*'; | ||
$scope.disabled = localStorage.getItem('disabled' + version) == 'true' || false; | ||
$scope.multiple = localStorage.getItem('multiple' + version) == 'true' || false; | ||
$scope.allowDir = localStorage.getItem('allowDir' + version) == 'true' || true; | ||
$scope.resetOnClick = localStorage.getItem('resetOnClick' + version) == 'true' || true; | ||
$scope.resetModelOnClick = localStorage.getItem('resetModelOnClick' + version) == 'true' || true; | ||
$scope.keep = localStorage.getItem('keep' + version) == 'true' || false; | ||
$scope.keepDistinct = localStorage.getItem('keepDistinct' + version) == 'true' || false; | ||
$scope.$watch('capture+accept+acceptSelect+disabled+capture+multiple+allowDir+resetOnClick+resetModelOnClick+keep+keepDistinct', function () { | ||
localStorage.setItem('capture' + version, $scope.capture); | ||
localStorage.setItem('accept' + version, $scope.accept); | ||
localStorage.setItem('acceptSelect' + version, $scope.acceptSelect); | ||
localStorage.setItem('disabled' + version, $scope.disabled); | ||
localStorage.setItem('multiple' + version, $scope.multiple); | ||
localStorage.setItem('allowDir' + version, $scope.allowDir); | ||
localStorage.setItem('resetOnClick' + version, $scope.resetOnClick); | ||
localStorage.setItem('resetModelOnClick' + version, $scope.resetModelOnClick); | ||
localStorage.setItem('keep' + version, $scope.keep); | ||
localStorage.setItem('keepDistinct' + version, $scope.keepDistinct); | ||
}); | ||
}); | ||
}]); |
{ | ||
"name": "ng-file-upload", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"devDependencies": { | ||
@@ -5,0 +5,0 @@ "grunt": "^0.4.5", |
@@ -6,3 +6,3 @@ ng-file-upload | ||
**Migration notes**: [version 3.0.0](https://github.com/danialfarid/ng-file-upload/releases/tag/3.0.0) [version 3.1.0](https://github.com/danialfarid/ng-file-upload/releases/tag/3.1.0) [version 3.2.0](https://github.com/danialfarid/ng-file-upload/releases/tag/3.2.3) [version 4.0.0](https://github.com/danialfarid/ng-file-upload/releases/tag/4.0.0) | ||
**Migration notes**: [version 3.0.0](https://github.com/danialfarid/ng-file-upload/releases/tag/3.0.0) [version 3.1.0](https://github.com/danialfarid/ng-file-upload/releases/tag/3.1.0) [version 3.2.0](https://github.com/danialfarid/ng-file-upload/releases/tag/3.2.3) [version 4.0.0](https://github.com/danialfarid/ng-file-upload/releases/tag/4.0.0) [version 5.0.0](https://github.com/danialfarid/ng-file-upload/releases/tag/5.0.0) | ||
@@ -88,3 +88,4 @@ Table of Content: | ||
<button|div|input type="file"|ngf-select|... | ||
ngf-select ng-model="myFiles" // binds the selected files to the scope model | ||
*ngf-select="true" or "false" // default true, enables file select directive on this element | ||
ng-model="myFiles" // binds the selected files to the scope model | ||
ng-model-rejected="rejFiles" // bind to dropped files that do not match the accept wildcard | ||
@@ -98,2 +99,6 @@ ngf-change="fileSelected($files, $event)" // called when files are selected or removed | ||
ngf-max-size='10' // maximum acceptable file size in bytes | ||
ngf-keep="true" or "false" // default false, keep the previous ng-model files and append the new files | ||
ngf-keep-distinct="true" or "false" // default false, if ngf-keep is set, removes duplicate selected files | ||
ngf-reset-on-click="true" or "false" // default true, reset the model and input upon click. see note below. | ||
ngf-reset-model-on-click="true" or "false" // default true, reset the model upon click. see note below. | ||
>Upload</button> | ||
@@ -105,3 +110,4 @@ ``` | ||
<div|button|ngf-drop|... | ||
ngf-drop ng-model="myFiles" // binds the dropped files to the scope model | ||
*ngf-drop="true" or "false" // default true, enables file drop directive on this element | ||
ng-model="myFiles" // binds the dropped files to the scope model | ||
ng-model-rejected="rejFiles" // bind to dropped files that do not match the accept wildcard | ||
@@ -155,13 +161,12 @@ ngf-change="fileDropped($files, $event, $rejectedFiles)" //called when files being dropped | ||
map of extra form data fields to send along with file. each field will be sent as a form field. | ||
The values are converted to json string or jsob blob depending on 'sendObjectsAsJsonBlob' option. */ | ||
The values are converted to json string or jsob blob or nested form depending on 'sendFieldsAs' option. */ | ||
fields: {key: $scope.myValue, ...}, | ||
/* | ||
if the value of a form field is an object it will be sent as 'application/json' blob | ||
rather than json string, default false. */ | ||
sendObjectsAsJsonBlob: true|false, | ||
default is 'json', sends each field as json string plain text content type, 'json-blob' sends object fields | ||
as a blob object with content type 'application/json', 'form' sends fields as nested form fields. see #784 */ | ||
sendFieldsAs: json|json-blob|form, | ||
/* customize how data is added to the formData. See #40#issuecomment-28612000 for sample code. */ | ||
formDataAppender: function(formData, key, val){}, | ||
/* | ||
data will be sent as a separate form data field called "data". It will be converted to json string | ||
or jsob blob depending on 'sendObjectsAsJsonBlob' option*/ | ||
data will be sent as a separate form data field called "data".*/ | ||
data: {}. | ||
@@ -198,3 +203,2 @@ withCredentials: true|false, | ||
``` | ||
**Upload multiple files**: Only for HTML5 FormData browsers (not IE8-9) if you pass an array of files to `file` option it will upload all of them together in one request. In this case the `fileFormDataName` could be an array of names or a single string. For Rails or depending on your server append square brackets to the end (i.e. `file[]`). | ||
@@ -212,2 +216,7 @@ Non-html5 browsers due to flash limitation will still upload array of files one by one in a separate request. You should iterate over files and send them one by one if you want cross browser solution. | ||
**ngf-reset-on-click and ngf-reset-model-on-click**: | ||
These two options are for testing purposes or rare cases, be aware that they might make the file select behave differently on different browsers. | ||
By default since there is no cross-browser way to detect cancel on the file popup everytime you click on the file select it would create a new element and click on that and the model value will be reset to empty. This would also allow selecting the same file again which normally will not trigger a change event. | ||
Setting this to false would not create a new element, and browsers will behave differently when the user cancels the popup, for example for chrome you would recieve a change event with empty files but in FireFox there will be no event fired. This could be helpful in some rare cases or for testing when you want to keep the original elements without replacing them. Setting ngf-reset-model-on-click will not reset the model when you click on the file select, that would make reseting model when the user cancels the select popup impossible in some browsers. | ||
##<a name="old_browsers"></a> Old browsers | ||
@@ -214,0 +223,0 @@ |
(function () { | ||
ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', | ||
function ($parse, $timeout, $compile) { | ||
return { | ||
restrict: 'AEC', | ||
require: '?ngModel', | ||
link: function (scope, elem, attr, ngModel) { | ||
linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile); | ||
} | ||
}; | ||
}]); | ||
ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', | ||
function ($parse, $timeout, $compile) { | ||
return { | ||
restrict: 'AEC', | ||
require: '?ngModel', | ||
link: function (scope, elem, attr, ngModel) { | ||
linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile); | ||
} | ||
}; | ||
}]); | ||
function linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) { | ||
/** @namespace attr.ngfSelect */ | ||
/** @namespace attr.ngfChange */ | ||
/** @namespace attr.ngModel */ | ||
/** @namespace attr.ngModelRejected */ | ||
/** @namespace attr.ngfMultiple */ | ||
/** @namespace attr.ngfCapture */ | ||
/** @namespace attr.ngfAccept */ | ||
/** @namespace attr.ngfMaxSize */ | ||
/** @namespace attr.ngfMinSize */ | ||
/** @namespace attr.ngfResetOnClick */ | ||
/** @namespace attr.ngfResetModelOnClick */ | ||
/** @namespace attr.ngfKeep */ | ||
/** @namespace attr.ngfKeepDistinct */ | ||
function linkFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) { | ||
/** @namespace attr.ngfSelect */ | ||
/** @namespace attr.ngfChange */ | ||
/** @namespace attr.ngModel */ | ||
/** @namespace attr.ngModelRejected */ | ||
/** @namespace attr.ngfMultiple */ | ||
/** @namespace attr.ngfCapture */ | ||
/** @namespace attr.ngfAccept */ | ||
/** @namespace attr.ngfMaxSize */ | ||
/** @namespace attr.ngfMinSize */ | ||
/** @namespace attr.ngfResetOnClick */ | ||
/** @namespace attr.ngfResetModelOnClick */ | ||
/** @namespace attr.ngfKeep */ | ||
/** @namespace attr.ngfKeepDistinct */ | ||
if (elem.attr('__ngf_gen__')) { | ||
return; | ||
} | ||
if (elem.attr('__ngf_gen__')) { | ||
return; | ||
} | ||
scope.$on('$destroy', function () { | ||
if (elem.$$ngfRefElem) elem.$$ngfRefElem.remove(); | ||
}); | ||
scope.$on('$destroy', function () { | ||
if (elem.$$ngfRefElem) elem.$$ngfRefElem.remove(); | ||
}); | ||
var disabled = false; | ||
if (attr.ngfSelect.search(/\W+$files\W+/) === -1) { | ||
scope.$watch(attr.ngfSelect, function (val) { | ||
disabled = val === false; | ||
}); | ||
} | ||
function isInputTypeFile() { | ||
return elem[0].tagName.toLowerCase() === 'input' && attr.type && attr.type.toLowerCase() === 'file'; | ||
} | ||
var disabled = false; | ||
if (attr.ngfSelect.search(/\W+$files\W+/) === -1) { | ||
scope.$watch(attr.ngfSelect, function (val) { | ||
disabled = val === false; | ||
}); | ||
} | ||
function isInputTypeFile() { | ||
return elem[0].tagName.toLowerCase() === 'input' && attr.type && attr.type.toLowerCase() === 'file'; | ||
} | ||
var isUpdating = false; | ||
var isUpdating = false; | ||
function changeFn(evt) { | ||
if (!isUpdating) { | ||
isUpdating = true; | ||
try { | ||
var fileList = evt.__files_ || (evt.target && evt.target.files); | ||
var files = [], rejFiles = []; | ||
function changeFn(evt) { | ||
if (!isUpdating) { | ||
isUpdating = true; | ||
try { | ||
var fileList = evt.__files_ || (evt.target && evt.target.files); | ||
var files = [], rejFiles = []; | ||
for (var i = 0; i < fileList.length; i++) { | ||
var file = fileList.item(i); | ||
if (validate(scope, $parse, attr, file, evt)) { | ||
files.push(file); | ||
} else { | ||
rejFiles.push(file); | ||
} | ||
} | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, files, rejFiles, evt); | ||
if (files.length === 0) evt.target.value = files; | ||
for (var i = 0; i < fileList.length; i++) { | ||
var file = fileList.item(i); | ||
if (validate(scope, $parse, attr, file, evt)) { | ||
files.push(file); | ||
} else { | ||
rejFiles.push(file); | ||
} | ||
} | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, files, rejFiles, evt); | ||
if (files.length === 0) evt.target.value = files; | ||
// if (evt.target && evt.target.getAttribute('__ngf_gen__')) { | ||
// angular.element(evt.target).remove(); | ||
// } | ||
} finally { | ||
isUpdating = false; | ||
} finally { | ||
isUpdating = false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function bindAttrToFileInput(fileElem) { | ||
if (attr.ngfMultiple) fileElem.attr('multiple', $parse(attr.ngfMultiple)(scope)); | ||
if (attr.ngfCapture) fileElem.attr('capture', $parse(attr.ngfCapture)(scope)); | ||
if (attr.accept) fileElem.attr('accept', attr.accept); | ||
for (var i = 0; i < elem[0].attributes.length; i++) { | ||
var attribute = elem[0].attributes[i]; | ||
if ((isInputTypeFile() && attribute.name !== 'type') || | ||
(attribute.name !== 'type' && attribute.name !== 'class' && | ||
attribute.name !== 'id' && attribute.name !== 'style')) { | ||
fileElem.attr(attribute.name, attribute.value); | ||
function bindAttrToFileInput(fileElem) { | ||
if (attr.ngfMultiple) fileElem.attr('multiple', $parse(attr.ngfMultiple)(scope)); | ||
if (attr.ngfCapture) fileElem.attr('capture', $parse(attr.ngfCapture)(scope)); | ||
if (attr.accept) fileElem.attr('accept', attr.accept); | ||
for (var i = 0; i < elem[0].attributes.length; i++) { | ||
var attribute = elem[0].attributes[i]; | ||
if ((isInputTypeFile() && attribute.name !== 'type') || | ||
(attribute.name !== 'type' && attribute.name !== 'class' && | ||
attribute.name !== 'id' && attribute.name !== 'style')) { | ||
fileElem.attr(attribute.name, attribute.value); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function createFileInput(evt, resetOnClick) { | ||
if (elem.attr('disabled') || disabled) return; | ||
function createFileInput(evt, resetOnClick) { | ||
if (elem.attr('disabled') || disabled) return; | ||
if (!resetOnClick && (evt || isInputTypeFile())) return elem.$$ngfRefElem || elem; | ||
if (!resetOnClick && (evt || isInputTypeFile())) return elem.$$ngfRefElem || elem; | ||
var fileElem = angular.element('<input type="file">'); | ||
bindAttrToFileInput(fileElem); | ||
var fileElem = angular.element('<input type="file">'); | ||
bindAttrToFileInput(fileElem); | ||
if (isInputTypeFile()) { | ||
elem.replaceWith(fileElem); | ||
elem = fileElem; | ||
fileElem.attr('__ngf_gen__', true); | ||
$compile(elem)(scope); | ||
} else { | ||
fileElem.css('visibility', 'hidden').css('position', 'absolute') | ||
.css('width', '9').css('height', '1').css('z-index', '-100000') | ||
.attr('tabindex', '-1'); | ||
if (elem.$$ngfRefElem) { | ||
elem.$$ngfRefElem.remove(); | ||
if (isInputTypeFile()) { | ||
elem.replaceWith(fileElem); | ||
elem = fileElem; | ||
fileElem.attr('__ngf_gen__', true); | ||
$compile(elem)(scope); | ||
} else { | ||
fileElem.css('visibility', 'hidden').css('position', 'absolute') | ||
.css('width', '9').css('height', '1').css('z-index', '-100000') | ||
.attr('tabindex', '-1'); | ||
if (elem.$$ngfRefElem) { | ||
elem.$$ngfRefElem.remove(); | ||
} | ||
elem.$$ngfRefElem = fileElem; | ||
document.body.appendChild(fileElem[0]); | ||
} | ||
return fileElem; | ||
} | ||
elem.$$ngfRefElem = fileElem; | ||
document.body.appendChild(fileElem[0]); | ||
} | ||
return fileElem; | ||
} | ||
function resetModel(evt) { | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, [], [], evt, true); | ||
} | ||
function resetModel(evt) { | ||
updateModel($parse, $timeout, scope, ngModel, attr, attr.ngfChange || attr.ngfSelect, [], [], evt, true); | ||
} | ||
function clickHandler(evt) { | ||
if (evt != null) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var resetOnClick = $parse(attr.ngfResetOnClick)(scope) !== false; | ||
var fileElem = createFileInput(evt, resetOnClick); | ||
function clickHandler(evt) { | ||
if (evt != null) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var resetOnClick = $parse(attr.ngfResetOnClick)(scope) !== false; | ||
var fileElem = createFileInput(evt, resetOnClick); | ||
function clickAndAssign(evt) { | ||
if (evt) { | ||
fileElem[0].click(); | ||
} | ||
if (isInputTypeFile() || !evt) { | ||
elem.bind('click touchend', clickHandler); | ||
} | ||
} | ||
function clickAndAssign(evt) { | ||
if (evt) { | ||
fileElem[0].click(); | ||
if (fileElem) { | ||
if (!evt || resetOnClick) fileElem.bind('change', changeFn); | ||
if (evt && resetOnClick && $parse(attr.ngfResetModelOnClick)(scope) !== false) resetModel(evt); | ||
// fix for android native browser < 4.4 | ||
if (isAndroidBelow44(navigator.userAgent)) { | ||
setTimeout(function () { | ||
clickAndAssign(evt); | ||
}, 0); | ||
} else { | ||
clickAndAssign(evt); | ||
} | ||
} | ||
return false; | ||
} | ||
if (isInputTypeFile() || !evt) { | ||
elem.bind('click touchend', clickHandler); | ||
} | ||
} | ||
if (fileElem) { | ||
if (!evt || resetOnClick) fileElem.bind('change', changeFn); | ||
if (evt && resetOnClick && $parse(attr.ngfResetModelOnClick)(scope) !== false) resetModel(evt); | ||
// fix for android native browser < 4.4 | ||
if (isAndroidBelow44()) { | ||
setTimeout(function () { | ||
clickAndAssign(evt); | ||
}, 0); | ||
if (window.FileAPI && window.FileAPI.ngfFixIE) { | ||
window.FileAPI.ngfFixIE(elem, createFileInput, bindAttrToFileInput, changeFn); | ||
} else { | ||
clickAndAssign(evt); | ||
clickHandler(); | ||
//if (!isInputTypeFile()) { | ||
// elem.bind('click touchend', clickHandler); | ||
//} | ||
} | ||
} | ||
return false; | ||
} | ||
if (window.FileAPI && window.FileAPI.ngfFixIE) { | ||
window.FileAPI.ngfFixIE(elem, createFileInput, bindAttrToFileInput, changeFn); | ||
} else { | ||
clickHandler(); | ||
//if (!isInputTypeFile()) { | ||
// elem.bind('click touchend', clickHandler); | ||
//} | ||
} | ||
} | ||
function isAndroidBelow44(ua) { | ||
var m = ua.match(/Android[^\d]*(\d+)\.(\d+)/); | ||
if (m && m.length > 2) { | ||
return parseInt(m[1]) < 4 || (parseInt(m[1]) === 4 && parseInt(m[2]) < 4); | ||
} | ||
function isAndroidBelow44() { | ||
var match = navigator.userAgent.toLowerCase().match(/android[^\d]*(\d|.)/); | ||
if (match) { | ||
var version = match[0].split('.'); | ||
return version[0] < '4' || (version[0] === '4' && version[1] < '4'); | ||
return false; | ||
} | ||
return false; | ||
} | ||
ngFileUpload.validate = function (scope, $parse, attr, file, evt) { | ||
function globStringToRegex(str) { | ||
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 += '|'; | ||
} | ||
ngFileUpload.validate = function (scope, $parse, attr, file, evt) { | ||
function globStringToRegex(str) { | ||
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 += '|'; | ||
} | ||
} | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
} | ||
} else { | ||
if (str.indexOf('.') === 0) { | ||
str = '*' + str; | ||
var accept = $parse(attr.ngfAccept)(scope, {$file: file, $event: evt}); | ||
var fileSizeMax = $parse(attr.ngfMaxSize)(scope, {$file: file, $event: evt}) || 9007199254740991; | ||
var fileSizeMin = $parse(attr.ngfMinSize)(scope, {$file: file, $event: evt}) || -1; | ||
if (accept != null && angular.isString(accept)) { | ||
var regexp = new RegExp(globStringToRegex(accept), 'gi'); | ||
accept = (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
} | ||
result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$'; | ||
result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.'); | ||
} | ||
return result; | ||
} | ||
return (accept == null || accept) && (file.size == null || (file.size < fileSizeMax && file.size > fileSizeMin)); | ||
}; | ||
var accept = $parse(attr.ngfAccept)(scope, {$file: file, $event: evt}); | ||
var fileSizeMax = $parse(attr.ngfMaxSize)(scope, {$file: file, $event: evt}) || 9007199254740991; | ||
var fileSizeMin = $parse(attr.ngfMinSize)(scope, {$file: file, $event: evt}) || -1; | ||
if (accept != null && angular.isString(accept)) { | ||
var regexp = new RegExp(globStringToRegex(accept), 'gi'); | ||
accept = (file.type != null && regexp.test(file.type.toLowerCase())) || | ||
(file.name != null && regexp.test(file.name.toLowerCase())); | ||
} | ||
return (accept == null || accept) && (file.size == null || (file.size < fileSizeMax && file.size > fileSizeMin)); | ||
}; | ||
ngFileUpload.updateModel = function ($parse, $timeout, scope, ngModel, attr, fileChange, | ||
files, rejFiles, evt, noDelay) { | ||
function update() { | ||
if ($parse(attr.ngfKeep)(scope) === true) { | ||
if (!files || !files.length) { | ||
return; | ||
} | ||
if ($parse(attr.ngfKeepDistinct)(scope) === true) { | ||
var prevFiles = (ngModel.$modelValue || []).slice(0), len = prevFiles.length; | ||
for (var i = 0; i < files.length; i++) { | ||
for (var j = 0; j < len; j++) { | ||
if (files[i].name === prevFiles[j].name) break; | ||
ngFileUpload.updateModel = function ($parse, $timeout, scope, ngModel, attr, fileChange, | ||
files, rejFiles, evt, noDelay) { | ||
function update() { | ||
if ($parse(attr.ngfKeep)(scope) === true) { | ||
if (!files || !files.length) { | ||
return; | ||
} | ||
if ($parse(attr.ngfKeepDistinct)(scope) === true) { | ||
var prevFiles = (ngModel.$modelValue || []).slice(0), len = prevFiles.length; | ||
for (var i = 0; i < files.length; i++) { | ||
for (var j = 0; j < len; j++) { | ||
if (files[i].name === prevFiles[j].name) break; | ||
} | ||
if (j === len) { | ||
prevFiles.push(files[i]); | ||
} | ||
} | ||
if (len === prevFiles.length) { | ||
return; | ||
} | ||
files = [].concat(prevFiles); | ||
} else { | ||
files = (ngModel.$modelValue || []).concat(files); | ||
} | ||
} | ||
if (j === len) { | ||
prevFiles.push(files[i]); | ||
if (ngModel) { | ||
$parse(attr.ngModel).assign(scope, files); | ||
$timeout(function () { | ||
if (ngModel) { | ||
ngModel.$setViewValue(files != null && files.length === 0 ? null : files); | ||
} | ||
}); | ||
} | ||
} | ||
if (len === prevFiles.length) { | ||
return; | ||
} | ||
files = [].concat(prevFiles); | ||
if (attr.ngModelRejected) { | ||
$parse(attr.ngModelRejected).assign(scope, rejFiles); | ||
} | ||
if (fileChange) { | ||
$parse(fileChange)(scope, { | ||
$files: files, | ||
$rejectedFiles: rejFiles, | ||
$event: evt | ||
}); | ||
} | ||
} | ||
if (noDelay) { | ||
update(); | ||
} else { | ||
files = (ngModel.$modelValue || []).concat(files); | ||
$timeout(function () { | ||
update(); | ||
}); | ||
} | ||
} | ||
if (ngModel) { | ||
$parse(attr.ngModel).assign(scope, files); | ||
$timeout(function () { | ||
if (ngModel) { | ||
ngModel.$setViewValue(files != null && files.length === 0 ? null : files); | ||
} | ||
}); | ||
} | ||
if (attr.ngModelRejected) { | ||
$parse(attr.ngModelRejected).assign(scope, rejFiles); | ||
} | ||
if (fileChange) { | ||
$parse(fileChange)(scope, { | ||
$files: files, | ||
$rejectedFiles: rejFiles, | ||
$event: evt | ||
}); | ||
} | ||
} | ||
}; | ||
if (noDelay) { | ||
update(); | ||
} else { | ||
$timeout(function () { | ||
update(); | ||
}); | ||
} | ||
}; | ||
var validate = ngFileUpload.validate; | ||
var updateModel = ngFileUpload.updateModel; | ||
var validate = ngFileUpload.validate; | ||
var updateModel = ngFileUpload.updateModel; | ||
})(); |
@@ -21,8 +21,12 @@ (function () { | ||
function getOffset(obj) { | ||
var left, top; | ||
left = top = 0; | ||
var left = 0, top = 0; | ||
if (window.jQuery) { | ||
return jQuery(obj).offset(); | ||
} | ||
if (obj.offsetParent) { | ||
do { | ||
left += obj.offsetLeft; | ||
top += obj.offsetTop; | ||
left += (obj.offsetLeft - obj.scrollLeft); | ||
top += (obj.offsetTop - obj.scrollTop); | ||
obj = obj.offsetParent; | ||
@@ -29,0 +33,0 @@ } while (obj); |
@@ -34,3 +34,4 @@ /**! | ||
var deferred = $q.defer(); | ||
var deferred = | ||
$q.defer(); | ||
var promise = deferred.promise; | ||
@@ -37,0 +38,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2696414
97
17367
409
1