-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8218d36
commit cbbec3a
Showing
18 changed files
with
195 additions
and
227 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 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 <[email protected]> | ||
* @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); | ||
} | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 12.2.12 | ||
* @version 12.2.13 | ||
*/ | ||
|
||
(function () { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort, | ||
* progress, resize, thumbnail, preview, validation and CORS | ||
* @author Danial <[email protected]> | ||
* @version 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); | ||
} | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.