-
Notifications
You must be signed in to change notification settings - Fork 25
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
Danial Farid
authored and
Danial Farid
committed
Sep 19, 2015
1 parent
6dc6f6a
commit 6a9df98
Showing
7 changed files
with
38 additions
and
24 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 7.3.3 | ||
* @version 7.3.4 | ||
*/ | ||
|
||
(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 7.3.3 | ||
* @version 7.3.4 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -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'; | ||
|
@@ -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 | ||
|
@@ -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(); | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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--; | ||
|
@@ -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); | ||
|
@@ -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) { | ||
|
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 7.3.3 | ||
* @version 7.3.4 | ||
*/ | ||
|
||
(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 7.3.3 | ||
* @version 7.3.4 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -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'; | ||
|
@@ -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 | ||
|
@@ -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(); | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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--; | ||
|
@@ -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); | ||
|
@@ -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) { | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.