Skip to content

Commit

Permalink
12.2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
danialfarid committed Nov 5, 2016
1 parent 1c5d9ef commit 4ba3e7e
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular:[email protected]
danialf:[email protected].11
danialf:[email protected].12
[email protected]
[email protected]
2 changes: 1 addition & 1 deletion FileAPI.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 36 additions & 42 deletions ng-file-upload-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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))
};
}
}
}

Expand Down Expand Up @@ -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 &&
Expand All @@ -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);
}
Expand Down
7 changes: 3 additions & 4 deletions ng-file-upload-all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ng-file-upload-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion ng-file-upload-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 35 additions & 41 deletions ng-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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))
};
}
}
}

Expand Down Expand Up @@ -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 &&
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions ng-file-upload.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: "danialf:ng-file-upload",
"version": "12.2.12",
"version": "12.2.13",
summary: "Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support",
git: "https://github.com/danialfarid/ng-file-upload.git"
});
Expand Down

0 comments on commit 4ba3e7e

Please sign in to comment.