objectFit = function($media) {
    // If necessary, make the parent container work with absolutely positioned elements
    var $container = $media.parentNode;
    checkParentContainer($container);

    // Check for any pre-set CSS which could mess up image calculations
    checkMediaProperties($media);

    // Mathematically figure out which side needs covering, and add CSS positioning & centering
    $media.style.position = 'absolute';
    $media.style.height = '100%';
    $media.style.width = 'auto';

    if ($media.clientWidth > $container.clientWidth) {
      $media.style.top = '0';
      $media.style.marginTop = '0';
      $media.style.left = '50%';
      $media.style.marginLeft = $media.clientWidth / -2 + 'px';
    } else {
      $media.style.width = '100%';
      $media.style.height = 'auto';
      $media.style.left = '0';
      $media.style.marginLeft = '0';
      $media.style.top = '50%';
      $media.style.marginTop = $media.clientHeight / -2 + 'px';
    }
  }
Calculate & set object-fit

@param {node} $media - img/video/picture element