Check if an element is visible in the browser viewport.

"use strict";

/**
 * Is element visible in viewport
 *
 * Use Element.getBoundingClientRect() and the window.inner(Width|Height) values
 * to determine if a given element is visible in the viewport. Omit the second
 * argument to determine if the element is entirely visible, or specify true to
 * determine if it is partially visible.
 *
 * @param {DOM.Element} el
 * @return {Bool} true if the element is in the current viewport, otherwise
 *     false
 */
var isElementVisibleInViewport = function isElementVisibleInViewport(el) {
    var partiallyVisible =
        arguments.length > 1 && arguments[1] !== undefined
            ? arguments[1]
            : false;

    var _el$getBoundingClient = el.getBoundingClientRect(),
        top = _el$getBoundingClient.top,
        left = _el$getBoundingClient.left,
        bottom = _el$getBoundingClient.bottom,
        right = _el$getBoundingClient.right;

    return partiallyVisible
        ? ((top > 0 && top < innerHeight) ||
              (bottom > 0 && bottom < innerHeight)) &&
              ((left > 0 && left < innerWidth) ||
                  (right > 0 && right < innerWidth))
        : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
};