All files / app/assets/javascripts/image_diff/helpers init_image_diff.js

100% Statements 9/9
100% Branches 4/4
100% Functions 1/1
100% Lines 9/9

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 20 21 22 23 24 25 26 27 28          3x               3x   3x 1x 1x 2x 1x 1x     3x        
import ImageFile from '~/commit/image_file';
import ImageDiff from '../image_diff';
import ReplacedImageDiff from '../replaced_image_diff';
 
function initImageDiff(fileEl, canCreateNote, renderCommentBadge) {
  const options = {
    canCreateNote,
    renderCommentBadge,
  };
  let diff;
 
  // ImageFile needs to be invoked before initImageDiff so that badges
  // can mount to the correct location
  new ImageFile(fileEl); // eslint-disable-line no-new
 
  if (fileEl.querySelector('.diff-file .js-single-image')) {
    diff = new ImageDiff(fileEl, options);
    diff.init();
  } else if (fileEl.querySelector('.diff-file .js-replaced-image')) {
    diff = new ReplacedImageDiff(fileEl, options);
    diff.init();
  }
 
  return diff;
}
 
export default { initImageDiff };