You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preloadImage.web.js 535B

123456789101112131415161718192021222324
  1. // @flow
  2. declare var config: Object;
  3. /**
  4. * Tries to preload an image.
  5. *
  6. * @param {string} src - Source of the avatar.
  7. * @returns {Promise}
  8. */
  9. export function preloadImage(src: string): Promise<string> {
  10. if (typeof config === 'object' && config.disableThirdPartyRequests) {
  11. return Promise.reject();
  12. }
  13. return new Promise((resolve, reject) => {
  14. const image = document.createElement('img');
  15. image.onload = () => resolve(src);
  16. image.onerror = reject;
  17. image.src = src;
  18. });
  19. }