All files / lib/tools image.js

100% Statements 6/6
50% Branches 1/2
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19                    2x 2x 2x 2x 2x   2x    
/**
 * Create and return an image Object, with assigned load/error
 * eventhadles and source.
 * @param {functstringion} src Optinal image path url
 * @param {function} load Function to be called on successfully
 * @param {function} error Function to be called on error
 * @module
 * @return {HTMLImageElement}
 */
export function newImage(src, load, error) {
  const img = document.createElement('img');
  img.addEventListener('load', load);
  img.addEventListener('error', error, false);
  Eif (src) {
    img.src = src;
  }
  return img;
}