Skip to content

Commit cbbec3a

Browse files
committed
1 parent 8218d36 commit cbbec3a

18 files changed

+195
-227
lines changed

demo/src/main/webapp/js/FileAPI.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/src/main/webapp/js/ng-file-upload-all.js

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* progress, resize, thumbnail, preview, validation and CORS
44
* FileAPI Flash shim for old browsers not supporting FormData
55
* @author Danial <[email protected]>
6-
* @version 12.2.12
6+
* @version 12.2.13
77
*/
88

99
(function () {
@@ -424,7 +424,7 @@ if (!window.FileReader) {
424424
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort,
425425
* progress, resize, thumbnail, preview, validation and CORS
426426
* @author Danial <[email protected]>
427-
* @version 12.2.12
427+
* @version 12.2.13
428428
*/
429429

430430
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
@@ -445,7 +445,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
445445

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

448-
ngFileUpload.version = '12.2.12';
448+
ngFileUpload.version = '12.2.13';
449449

450450
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
451451
var upload = this;
@@ -1510,15 +1510,19 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
15101510
var size = resizeParams;
15111511
if (directiveName === 'ngfThumbnail') {
15121512
if (!size) {
1513-
size = {width: elem[0].naturalWidth || elem[0].clientWidth,
1514-
height: elem[0].naturalHeight || elem[0].clientHeight};
1513+
size = {
1514+
width: elem[0].naturalWidth || elem[0].clientWidth,
1515+
height: elem[0].naturalHeight || elem[0].clientHeight
1516+
};
15151517
}
15161518
if (size.width === 0 && window.getComputedStyle) {
15171519
var style = getComputedStyle(elem[0]);
1518-
size = {
1519-
width: parseInt(style.width.slice(0, -2)),
1520-
height: parseInt(style.height.slice(0, -2))
1521-
};
1520+
if (style.width && style.width.indexOf('px') > -1 && style.height && style.height.indexOf('px') > -1) {
1521+
size = {
1522+
width: parseInt(style.width.slice(0, -2)),
1523+
height: parseInt(style.height.slice(0, -2))
1524+
};
1525+
}
15221526
}
15231527
}
15241528

@@ -2376,46 +2380,15 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
23762380
if (stopPropagation(scope)) evt.stopPropagation();
23772381
if (actualDragOverClass) elem.removeClass(actualDragOverClass);
23782382
actualDragOverClass = null;
2379-
var items = evt.dataTransfer.items;
2380-
var html;
2381-
try {
2382-
html = evt.dataTransfer && evt.dataTransfer.getData && evt.dataTransfer.getData('text/html');
2383-
} catch (e) {/* Fix IE11 that throw error calling getData */
2384-
}
2385-
2386-
extractFiles(items, evt.dataTransfer.files, attrGetter('ngfAllowDir', scope) !== false,
2387-
attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
2388-
if (files.length) {
2389-
updateModel(files, evt);
2390-
} else {
2391-
extractFilesFromHtml('dropUrl', html).then(function (files) {
2392-
updateModel(files, evt);
2393-
});
2394-
}
2395-
});
2383+
extractFilesAndUpdateModel(evt.dataTransfer, evt, 'dropUrl');
23962384
}, false);
23972385
elem[0].addEventListener('paste', function (evt) {
23982386
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
23992387
attrGetter('ngfEnableFirefoxPaste', scope)) {
24002388
evt.preventDefault();
24012389
}
24022390
if (isDisabled() || !upload.shouldUpdateOn('paste', attr, scope)) return;
2403-
var files = [];
2404-
var clipboard = evt.clipboardData || evt.originalEvent.clipboardData;
2405-
if (clipboard && clipboard.items) {
2406-
for (var k = 0; k < clipboard.items.length; k++) {
2407-
if (clipboard.items[k].type.indexOf('image') !== -1) {
2408-
files.push(clipboard.items[k].getAsFile());
2409-
}
2410-
}
2411-
}
2412-
if (files.length) {
2413-
updateModel(files, evt);
2414-
} else {
2415-
extractFilesFromHtml('pasteUrl', clipboard).then(function (files) {
2416-
updateModel(files, evt);
2417-
});
2418-
}
2391+
extractFilesAndUpdateModel(evt.clipboardData || evt.originalEvent.clipboardData, evt, 'pasteUrl');
24192392
}, false);
24202393

24212394
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
@@ -2428,6 +2401,27 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
24282401
});
24292402
}
24302403

2404+
function extractFilesAndUpdateModel(source, evt, updateOnType) {
2405+
if (!source) return;
2406+
// html needs to be calculated on the same process otherwise the data will be wiped
2407+
// after promise resolve or setTimeout.
2408+
var html;
2409+
try {
2410+
html = source && source.getData && source.getData('text/html');
2411+
} catch (e) {/* Fix IE11 that throw error calling getData */
2412+
}
2413+
extractFiles(source.items, source.files, attrGetter('ngfAllowDir', scope) !== false,
2414+
attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
2415+
if (files.length) {
2416+
updateModel(files, evt);
2417+
} else {
2418+
extractFilesFromHtml(updateOnType, html).then(function (files) {
2419+
updateModel(files, evt);
2420+
});
2421+
}
2422+
});
2423+
}
2424+
24312425
function updateModel(files, evt) {
24322426
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), files, evt);
24332427
}

demo/src/main/webapp/js/ng-file-upload-all.min.js

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/src/main/webapp/js/ng-file-upload-shim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* progress, resize, thumbnail, preview, validation and CORS
44
* FileAPI Flash shim for old browsers not supporting FormData
55
* @author Danial <[email protected]>
6-
* @version 12.2.12
6+
* @version 12.2.13
77
*/
88

99
(function () {

demo/src/main/webapp/js/ng-file-upload-shim.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/src/main/webapp/js/ng-file-upload.js

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort,
33
* progress, resize, thumbnail, preview, validation and CORS
44
* @author Danial <[email protected]>
5-
* @version 12.2.12
5+
* @version 12.2.13
66
*/
77

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

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

26-
ngFileUpload.version = '12.2.12';
26+
ngFileUpload.version = '12.2.13';
2727

2828
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
2929
var upload = this;
@@ -1088,15 +1088,19 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
10881088
var size = resizeParams;
10891089
if (directiveName === 'ngfThumbnail') {
10901090
if (!size) {
1091-
size = {width: elem[0].naturalWidth || elem[0].clientWidth,
1092-
height: elem[0].naturalHeight || elem[0].clientHeight};
1091+
size = {
1092+
width: elem[0].naturalWidth || elem[0].clientWidth,
1093+
height: elem[0].naturalHeight || elem[0].clientHeight
1094+
};
10931095
}
10941096
if (size.width === 0 && window.getComputedStyle) {
10951097
var style = getComputedStyle(elem[0]);
1096-
size = {
1097-
width: parseInt(style.width.slice(0, -2)),
1098-
height: parseInt(style.height.slice(0, -2))
1099-
};
1098+
if (style.width && style.width.indexOf('px') > -1 && style.height && style.height.indexOf('px') > -1) {
1099+
size = {
1100+
width: parseInt(style.width.slice(0, -2)),
1101+
height: parseInt(style.height.slice(0, -2))
1102+
};
1103+
}
11001104
}
11011105
}
11021106

@@ -1954,46 +1958,15 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
19541958
if (stopPropagation(scope)) evt.stopPropagation();
19551959
if (actualDragOverClass) elem.removeClass(actualDragOverClass);
19561960
actualDragOverClass = null;
1957-
var items = evt.dataTransfer.items;
1958-
var html;
1959-
try {
1960-
html = evt.dataTransfer && evt.dataTransfer.getData && evt.dataTransfer.getData('text/html');
1961-
} catch (e) {/* Fix IE11 that throw error calling getData */
1962-
}
1963-
1964-
extractFiles(items, evt.dataTransfer.files, attrGetter('ngfAllowDir', scope) !== false,
1965-
attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
1966-
if (files.length) {
1967-
updateModel(files, evt);
1968-
} else {
1969-
extractFilesFromHtml('dropUrl', html).then(function (files) {
1970-
updateModel(files, evt);
1971-
});
1972-
}
1973-
});
1961+
extractFilesAndUpdateModel(evt.dataTransfer, evt, 'dropUrl');
19741962
}, false);
19751963
elem[0].addEventListener('paste', function (evt) {
19761964
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
19771965
attrGetter('ngfEnableFirefoxPaste', scope)) {
19781966
evt.preventDefault();
19791967
}
19801968
if (isDisabled() || !upload.shouldUpdateOn('paste', attr, scope)) return;
1981-
var files = [];
1982-
var clipboard = evt.clipboardData || evt.originalEvent.clipboardData;
1983-
if (clipboard && clipboard.items) {
1984-
for (var k = 0; k < clipboard.items.length; k++) {
1985-
if (clipboard.items[k].type.indexOf('image') !== -1) {
1986-
files.push(clipboard.items[k].getAsFile());
1987-
}
1988-
}
1989-
}
1990-
if (files.length) {
1991-
updateModel(files, evt);
1992-
} else {
1993-
extractFilesFromHtml('pasteUrl', clipboard).then(function (files) {
1994-
updateModel(files, evt);
1995-
});
1996-
}
1969+
extractFilesAndUpdateModel(evt.clipboardData || evt.originalEvent.clipboardData, evt, 'pasteUrl');
19971970
}, false);
19981971

19991972
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 &&
@@ -2006,6 +1979,27 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa
20061979
});
20071980
}
20081981

1982+
function extractFilesAndUpdateModel(source, evt, updateOnType) {
1983+
if (!source) return;
1984+
// html needs to be calculated on the same process otherwise the data will be wiped
1985+
// after promise resolve or setTimeout.
1986+
var html;
1987+
try {
1988+
html = source && source.getData && source.getData('text/html');
1989+
} catch (e) {/* Fix IE11 that throw error calling getData */
1990+
}
1991+
extractFiles(source.items, source.files, attrGetter('ngfAllowDir', scope) !== false,
1992+
attrGetter('multiple') || attrGetter('ngfMultiple', scope)).then(function (files) {
1993+
if (files.length) {
1994+
updateModel(files, evt);
1995+
} else {
1996+
extractFilesFromHtml(updateOnType, html).then(function (files) {
1997+
updateModel(files, evt);
1998+
});
1999+
}
2000+
});
2001+
}
2002+
20092003
function updateModel(files, evt) {
20102004
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), files, evt);
20112005
}

demo/src/main/webapp/js/ng-file-upload.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/FileAPI.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)