Permalink
Browse files

fixed #1633, fixed #1748

1 parent 8218d36 commit cbbec3a6c6b0b74d1502f3a32d5c6e575360886c @danialfarid committed Nov 5, 2016
@@ -1,4 +1,4 @@
-/*! 12.2.12 */
+/*! 12.2.13 */
/*! FileAPI 2.0.7 - BSD | git://github.com/mailru/FileAPI.git
* 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.
*/
@@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <danial.farid@gmail.com>
- * @version 12.2.12
+ * @version 12.2.13
*/
(function () {
@@ -424,7 +424,7 @@ if (!window.FileReader) {
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort,
* progress, resize, thumbnail, preview, validation and CORS
* @author Danial <danial.farid@gmail.com>
- * @version 12.2.12
+ * @version 12.2.13
*/
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
@@ -445,7 +445,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
var ngFileUpload = angular.module('ngFileUpload', []);
-ngFileUpload.version = '12.2.12';
+ngFileUpload.version = '12.2.13';
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
@@ -1510,15 +1510,19 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
var size = resizeParams;
if (directiveName === 'ngfThumbnail') {
if (!size) {
- size = {width: elem[0].naturalWidth || elem[0].clientWidth,
- height: elem[0].naturalHeight || elem[0].clientHeight};
+ size = {
+ width: elem[0].naturalWidth || elem[0].clientWidth,
+ height: elem[0].naturalHeight || elem[0].clientHeight
+ };
}
if (size.width === 0 && window.getComputedStyle) {
var style = getComputedStyle(elem[0]);
- size = {
- width: parseInt(style.width.slice(0, -2)),
- height: parseInt(style.height.slice(0, -2))
- };
+ if (style.width && style.width.indexOf('px') > -1 && style.height && style.height.indexOf('px') > -1) {
+ size = {
+ width: parseInt(style.width.slice(0, -2)),
+ height: parseInt(style.height.slice(0, -2))
+ };
+ }
}
}
@@ -2376,46 +2380,15 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
if (stopPropagation(scope)) evt.stopPropagation();
if (actualDragOverClass) elem.removeClass(actualDragOverClass);
actualDragOverClass = null;
- var items = evt.dataTransfer.items;
- var html;
- try {
- html = evt.dataTransfer && evt.dataTransfer.getData && evt.dataTransfer.getData('text/html');
- } catch (e) {/* Fix IE11 that throw error calling getData */
- }
-
- extractFiles(items, evt.dataTransfer.files, attrGetter('ngfAllowDir', scope) !== false,
- attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
- if (files.length) {
- updateModel(files, evt);
- } else {
- extractFilesFromHtml('dropUrl', html).then(function (files) {
- updateModel(files, evt);
- });
- }
- });
+ extractFilesAndUpdateModel(evt.dataTransfer, evt, 'dropUrl');
}, false);
elem[0].addEventListener('paste', function (evt) {
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
attrGetter('ngfEnableFirefoxPaste', scope)) {
evt.preventDefault();
}
if (isDisabled() || !upload.shouldUpdateOn('paste', attr, scope)) return;
- var files = [];
- var clipboard = evt.clipboardData || evt.originalEvent.clipboardData;
- if (clipboard && clipboard.items) {
- for (var k = 0; k < clipboard.items.length; k++) {
- if (clipboard.items[k].type.indexOf('image') !== -1) {
- files.push(clipboard.items[k].getAsFile());
- }
- }
- }
- if (files.length) {
- updateModel(files, evt);
- } else {
- extractFilesFromHtml('pasteUrl', clipboard).then(function (files) {
- updateModel(files, evt);
- });
- }
+ extractFilesAndUpdateModel(evt.clipboardData || evt.originalEvent.clipboardData, evt, 'pasteUrl');
}, false);
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
@@ -2428,6 +2401,27 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
});
}
+ function extractFilesAndUpdateModel(source, evt, updateOnType) {
+ if (!source) return;
+ // html needs to be calculated on the same process otherwise the data will be wiped
+ // after promise resolve or setTimeout.
+ var html;
+ try {
+ html = source && source.getData && source.getData('text/html');
+ } catch (e) {/* Fix IE11 that throw error calling getData */
+ }
+ extractFiles(source.items, source.files, attrGetter('ngfAllowDir', scope) !== false,
+ attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
+ if (files.length) {
+ updateModel(files, evt);
+ } else {
+ extractFilesFromHtml(updateOnType, html).then(function (files) {
+ updateModel(files, evt);
+ });
+ }
+ });
+ }
+
function updateModel(files, evt) {
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), files, evt);
}
Oops, something went wrong.
@@ -3,7 +3,7 @@
* progress, resize, thumbnail, preview, validation and CORS
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <danial.farid@gmail.com>
- * @version 12.2.12
+ * @version 12.2.13
*/
(function () {
@@ -1,2 +1,2 @@
-/*! 12.2.12 */
+/*! 12.2.13 */
!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.FileAPI||(window.FileAPI={}),!window.XMLHttpRequest)throw"AJAX is not supported. XMLHttpRequest is not defined.";if(FileAPI.shouldLoad=!window.FormData||FileAPI.forceLoad,FileAPI.shouldLoad){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){a&&angular.isString(a)&&-1!==a.indexOf("#2174")&&(a=null),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(FileAPI.shouldLoad){if(FileAPI.hasFlash=b(),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.ngfFixIE=function(d,e,f){if(!b())throw'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';var g=function(){var b=e.parent();d.attr("disabled")?b&&b.removeClass("js-fileapi-wrapper"):(e.attr("__ngf_flash_")||(e.unbind("change"),e.unbind("click"),e.bind("change",function(a){h.apply(this,[a]),f.apply(this,[a])}),e.attr("__ngf_flash_","true")),b.addClass("js-fileapi-wrapper"),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"),e.css("width",d[0].offsetWidth+"px").css("height",d[0].offsetHeight+"px").css("position","absolute").css("top","0px").css("left","0px")))};d.bind("mouseenter",g);var h=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.readAsDataURL=function(a){FileAPI.readAsDataURL(a,d)},this.readAsText=function(a){FileAPI.readAsText(a,d)}});
@@ -2,7 +2,7 @@
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort,
* progress, resize, thumbnail, preview, validation and CORS
* @author Danial <danial.farid@gmail.com>
- * @version 12.2.12
+ * @version 12.2.13
*/
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
@@ -23,7 +23,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
var ngFileUpload = angular.module('ngFileUpload', []);
-ngFileUpload.version = '12.2.12';
+ngFileUpload.version = '12.2.13';
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
@@ -1088,15 +1088,19 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
var size = resizeParams;
if (directiveName === 'ngfThumbnail') {
if (!size) {
- size = {width: elem[0].naturalWidth || elem[0].clientWidth,
- height: elem[0].naturalHeight || elem[0].clientHeight};
+ size = {
+ width: elem[0].naturalWidth || elem[0].clientWidth,
+ height: elem[0].naturalHeight || elem[0].clientHeight
+ };
}
if (size.width === 0 && window.getComputedStyle) {
var style = getComputedStyle(elem[0]);
- size = {
- width: parseInt(style.width.slice(0, -2)),
- height: parseInt(style.height.slice(0, -2))
- };
+ if (style.width && style.width.indexOf('px') > -1 && style.height && style.height.indexOf('px') > -1) {
+ size = {
+ width: parseInt(style.width.slice(0, -2)),
+ height: parseInt(style.height.slice(0, -2))
+ };
+ }
}
}
@@ -1954,46 +1958,15 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
if (stopPropagation(scope)) evt.stopPropagation();
if (actualDragOverClass) elem.removeClass(actualDragOverClass);
actualDragOverClass = null;
- var items = evt.dataTransfer.items;
- var html;
- try {
- html = evt.dataTransfer && evt.dataTransfer.getData && evt.dataTransfer.getData('text/html');
- } catch (e) {/* Fix IE11 that throw error calling getData */
- }
-
- extractFiles(items, evt.dataTransfer.files, attrGetter('ngfAllowDir', scope) !== false,
- attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
- if (files.length) {
- updateModel(files, evt);
- } else {
- extractFilesFromHtml('dropUrl', html).then(function (files) {
- updateModel(files, evt);
- });
- }
- });
+ extractFilesAndUpdateModel(evt.dataTransfer, evt, 'dropUrl');
}, false);
elem[0].addEventListener('paste', function (evt) {
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
attrGetter('ngfEnableFirefoxPaste', scope)) {
evt.preventDefault();
}
if (isDisabled() || !upload.shouldUpdateOn('paste', attr, scope)) return;
- var files = [];
- var clipboard = evt.clipboardData || evt.originalEvent.clipboardData;
- if (clipboard && clipboard.items) {
- for (var k = 0; k < clipboard.items.length; k++) {
- if (clipboard.items[k].type.indexOf('image') !== -1) {
- files.push(clipboard.items[k].getAsFile());
- }
- }
- }
- if (files.length) {
- updateModel(files, evt);
- } else {
- extractFilesFromHtml('pasteUrl', clipboard).then(function (files) {
- updateModel(files, evt);
- });
- }
+ extractFilesAndUpdateModel(evt.clipboardData || evt.originalEvent.clipboardData, evt, 'pasteUrl');
}, false);
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
@@ -2006,6 +1979,27 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
});
}
+ function extractFilesAndUpdateModel(source, evt, updateOnType) {
+ if (!source) return;
+ // html needs to be calculated on the same process otherwise the data will be wiped
+ // after promise resolve or setTimeout.
+ var html;
+ try {
+ html = source && source.getData && source.getData('text/html');
+ } catch (e) {/* Fix IE11 that throw error calling getData */
+ }
+ extractFiles(source.items, source.files, attrGetter('ngfAllowDir', scope) !== false,
+ attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
+ if (files.length) {
+ updateModel(files, evt);
+ } else {
+ extractFilesFromHtml(updateOnType, html).then(function (files) {
+ updateModel(files, evt);
+ });
+ }
+ });
+ }
+
function updateModel(files, evt) {
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), files, evt);
}
Oops, something went wrong.
View
@@ -1,4 +1,4 @@
-/*! 12.2.12 */
+/*! 12.2.13 */
/*! FileAPI 2.0.7 - BSD | git://github.com/mailru/FileAPI.git
* 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.
*/
Oops, something went wrong.

0 comments on commit cbbec3a

Please sign in to comment.