|
28 | 28 | if (typeof fetch !== 'undefined' && typeof Request !== 'undefined') {
|
29 | 29 | loadImage.fetchBlob = function(url, callback, options) {
|
30 | 30 | if (loadImage.hasMetaOption(options)) {
|
31 |
| - return fetch(new Request(url, options)) |
| 31 | + fetch(new Request(url, options)) |
32 | 32 | .then(function(response) {
|
33 | 33 | return response.blob()
|
34 | 34 | })
|
|
37 | 37 | console.log(err) // eslint-disable-line no-console
|
38 | 38 | callback()
|
39 | 39 | })
|
| 40 | + } else { |
| 41 | + callback() |
| 42 | + } |
| 43 | + } |
| 44 | + } else if ( |
| 45 | + // Check for XHR2 support: |
| 46 | + typeof XMLHttpRequest !== 'undefined' && |
| 47 | + typeof ProgressEvent !== 'undefined' |
| 48 | + ) { |
| 49 | + loadImage.fetchBlob = function(url, callback, options) { |
| 50 | + if (loadImage.hasMetaOption(options)) { |
| 51 | + // eslint-disable-next-line no-param-reassign |
| 52 | + options = options || {} |
| 53 | + var req = new XMLHttpRequest() |
| 54 | + req.open(options.method || 'GET', url) |
| 55 | + if (options.headers) { |
| 56 | + Object.keys(options.headers).forEach(function(key) { |
| 57 | + req.setRequestHeader(key, options.headers[key]) |
| 58 | + }) |
| 59 | + } |
| 60 | + req.withCredentials = options.credentials === 'include' |
| 61 | + req.responseType = 'blob' |
| 62 | + req.onload = function() { |
| 63 | + callback(req.response) |
| 64 | + } |
| 65 | + req.onerror = req.onabort = req.ontimeout = function(e) { |
| 66 | + console.log(e) // eslint-disable-line no-console |
| 67 | + callback() |
| 68 | + } |
| 69 | + req.send(options.body) |
| 70 | + } else { |
| 71 | + callback() |
40 | 72 | }
|
41 |
| - callback() |
42 | 73 | }
|
43 | 74 | }
|
44 | 75 | })
|
0 commit comments