|
15 | 15 | 'use strict'
|
16 | 16 | if (typeof define === 'function' && define.amd) {
|
17 | 17 | // Register as an anonymous AMD module:
|
18 |
| - define(['./load-image', './load-image-meta'], factory) |
| 18 | + define(['./load-image'], factory) |
19 | 19 | } else if (typeof module === 'object' && module.exports) {
|
20 |
| - factory(require('./load-image'), require('./load-image-meta')) |
| 20 | + factory(require('./load-image')) |
21 | 21 | } else {
|
22 | 22 | // Browser globals:
|
23 | 23 | factory(window.loadImage)
|
|
27 | 27 |
|
28 | 28 | if (typeof fetch !== 'undefined' && typeof Request !== 'undefined') {
|
29 | 29 | loadImage.fetchBlob = function (url, callback, options) {
|
30 |
| - if (loadImage.hasMetaOption(options)) { |
31 |
| - fetch(new Request(url, options)) |
32 |
| - .then(function (response) { |
33 |
| - return response.blob() |
34 |
| - }) |
35 |
| - .then(callback) |
36 |
| - .catch(function (err) { |
37 |
| - console.log(err) // eslint-disable-line no-console |
38 |
| - callback() |
39 |
| - }) |
40 |
| - } else { |
41 |
| - callback() |
42 |
| - } |
| 30 | + fetch(new Request(url, options)) |
| 31 | + .then(function (response) { |
| 32 | + return response.blob() |
| 33 | + }) |
| 34 | + .then(callback) |
| 35 | + .catch(function (err) { |
| 36 | + callback(null, err) |
| 37 | + }) |
43 | 38 | }
|
44 | 39 | } else if (
|
45 | 40 | // Check for XHR2 support:
|
46 | 41 | typeof XMLHttpRequest !== 'undefined' &&
|
47 | 42 | typeof ProgressEvent !== 'undefined'
|
48 | 43 | ) {
|
49 | 44 | 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() |
| 45 | + // eslint-disable-next-line no-param-reassign |
| 46 | + options = options || {} |
| 47 | + var req = new XMLHttpRequest() |
| 48 | + req.open(options.method || 'GET', url) |
| 49 | + if (options.headers) { |
| 50 | + Object.keys(options.headers).forEach(function (key) { |
| 51 | + req.setRequestHeader(key, options.headers[key]) |
| 52 | + }) |
| 53 | + } |
| 54 | + req.withCredentials = options.credentials === 'include' |
| 55 | + req.responseType = 'blob' |
| 56 | + req.onload = function () { |
| 57 | + callback(req.response) |
| 58 | + } |
| 59 | + req.onerror = req.onabort = req.ontimeout = function (err) { |
| 60 | + callback(null, err) |
72 | 61 | }
|
| 62 | + req.send(options.body) |
73 | 63 | }
|
74 | 64 | }
|
75 | 65 | })
|
0 commit comments