Skip to content

Commit

Permalink
7.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial Farid authored and Danial Farid committed Sep 19, 2015
1 parent 6dc6f6a commit 6a9df98
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
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.

25 changes: 16 additions & 9 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 7.3.3
* @version 7.3.4
*/

(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 7.3.3
* @version 7.3.4
*/

if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
Expand All @@ -445,10 +445,11 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {

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

ngFileUpload.version = '7.3.3';
ngFileUpload.version = '7.3.4';

ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
var sliceSupported = window.Blob && new Blob().slice;

function sendHttp(config) {
config.method = config.method || 'POST';
Expand All @@ -469,7 +470,7 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
}

function getNotifyEvent(n) {
if (config._start != null) {
if (config._start != null && sliceSupported) {
return {
loaded: n.loaded + config._start, total: config._file.size, type: n.type, config: config,
lengthComputable: true, target: n.target
Expand Down Expand Up @@ -513,7 +514,9 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
});
}

if (config._chunkSize && config._end && !config._finished) {
if (!sliceSupported) {
uploadWithAngular();
} else if (config._chunkSize && config._end && !config._finished) {
config._start = config._end;
config._end += config._chunkSize;
uploadWithAngular();
Expand All @@ -529,7 +532,6 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
}
uploadWithAngular();
}, function (e) {throw e;});
} else if (config.resumeSize) {
} else if (config.resumeSize) {
config.resumeSize().then(function(size) {
config._start = size;
Expand Down Expand Up @@ -618,7 +620,7 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
function addFileToFormData(formData, file, key) {
if (isFile(file)) {
config._file = config._file || file;
if (config._start != null) {
if (config._start != null && sliceSupported) {
if (config._end && config._end >= file.size) {
config._finished = true;
config._end = file.size;
Expand Down Expand Up @@ -822,7 +824,7 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', 'UploadResize'

function resize(files, callback) {
var param = upload.attrGetter('ngfResize', attr, scope);
if (!param) return callback();
if (!param || !upload.isResizeSupported()) return callback();
var count = files.length;
var checkCallback = function () {
count--;
Expand Down Expand Up @@ -1194,7 +1196,7 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
}
if (file && file.type && file.type.search(getTagType(elem[0])) === 0 &&
(!isBackground || file.type.indexOf('image') === 0)) {
if (size) {
if (size && Upload.isResizeSupported()) {
Upload.resize(file, size.width, size.height, size.quality).then(
function (f) {
constructDataUrl(f);
Expand Down Expand Up @@ -1720,6 +1722,11 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', '$timeout', functi
return new Blob([u8arr], {type: mime});
};

upload.isResizeSupported = function() {
var elem = document.createElement('canvas');
return window.atob && elem.getContext && elem.getContext('2d');
};

upload.resize = function (file, width, height, quality) {
var deferred = $q.defer();
if (file.type.indexOf('image') !== 0) {
Expand Down
4 changes: 2 additions & 2 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 7.3.3
* @version 7.3.4
*/

(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.

23 changes: 15 additions & 8 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 7.3.3
* @version 7.3.4
*/

if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {
Expand All @@ -23,10 +23,11 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) {

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

ngFileUpload.version = '7.3.3';
ngFileUpload.version = '7.3.4';

ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var upload = this;
var sliceSupported = window.Blob && new Blob().slice;

function sendHttp(config) {
config.method = config.method || 'POST';
Expand All @@ -47,7 +48,7 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
}

function getNotifyEvent(n) {
if (config._start != null) {
if (config._start != null && sliceSupported) {
return {
loaded: n.loaded + config._start, total: config._file.size, type: n.type, config: config,
lengthComputable: true, target: n.target
Expand Down Expand Up @@ -91,7 +92,9 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
});
}

if (config._chunkSize && config._end && !config._finished) {
if (!sliceSupported) {
uploadWithAngular();
} else if (config._chunkSize && config._end && !config._finished) {
config._start = config._end;
config._end += config._chunkSize;
uploadWithAngular();
Expand All @@ -107,7 +110,6 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
}
uploadWithAngular();
}, function (e) {throw e;});
} else if (config.resumeSize) {
} else if (config.resumeSize) {
config.resumeSize().then(function(size) {
config._start = size;
Expand Down Expand Up @@ -196,7 +198,7 @@ ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http,
function addFileToFormData(formData, file, key) {
if (isFile(file)) {
config._file = config._file || file;
if (config._start != null) {
if (config._start != null && sliceSupported) {
if (config._end && config._end >= file.size) {
config._finished = true;
config._end = file.size;
Expand Down Expand Up @@ -400,7 +402,7 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', 'UploadResize'

function resize(files, callback) {
var param = upload.attrGetter('ngfResize', attr, scope);
if (!param) return callback();
if (!param || !upload.isResizeSupported()) return callback();
var count = files.length;
var checkCallback = function () {
count--;
Expand Down Expand Up @@ -772,7 +774,7 @@ ngFileUpload.directive('ngfSelect', ['$parse', '$timeout', '$compile', 'Upload',
}
if (file && file.type && file.type.search(getTagType(elem[0])) === 0 &&
(!isBackground || file.type.indexOf('image') === 0)) {
if (size) {
if (size && Upload.isResizeSupported()) {
Upload.resize(file, size.width, size.height, size.quality).then(
function (f) {
constructDataUrl(f);
Expand Down Expand Up @@ -1298,6 +1300,11 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', '$timeout', functi
return new Blob([u8arr], {type: mime});
};

upload.isResizeSupported = function() {
var elem = document.createElement('canvas');
return window.atob && elem.getContext && elem.getContext('2d');
};

upload.resize = function (file, width, height, quality) {
var deferred = $q.defer();
if (file.type.indexOf('image') !== 0) {
Expand Down
4 changes: 2 additions & 2 deletions ng-file-upload.min.js

Large diffs are not rendered by default.

0 comments on commit 6a9df98

Please sign in to comment.