load-image-fetch.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * JavaScript Load Image Fetch
  3. * https://github.com/blueimp/JavaScript-Load-Image
  4. *
  5. * Copyright 2017, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * https://opensource.org/licenses/MIT
  10. */
  11. /* global define, module, require */
  12. ;(function(factory) {
  13. 'use strict'
  14. if (typeof define === 'function' && define.amd) {
  15. // Register as an anonymous AMD module:
  16. define(['./load-image', './load-image-meta'], factory)
  17. } else if (typeof module === 'object' && module.exports) {
  18. factory(require('./load-image'), require('./load-image-meta'))
  19. } else {
  20. // Browser globals:
  21. factory(window.loadImage)
  22. }
  23. })(function(loadImage) {
  24. 'use strict'
  25. if (typeof fetch !== 'undefined' && typeof Request !== 'undefined') {
  26. loadImage.fetchBlob = function(url, callback, options) {
  27. if (loadImage.hasMetaOption(options)) {
  28. return fetch(new Request(url, options))
  29. .then(function(response) {
  30. return response.blob()
  31. })
  32. .then(callback)
  33. .catch(function(err) {
  34. console.log(err) // eslint-disable-line no-console
  35. callback()
  36. })
  37. }
  38. callback()
  39. }
  40. }
  41. })