src/utils/ViewUtils.js
function scrollElementIntoView($view, $element, scrollHorizontal) {
        var elementOffset = $element.offset();

        // scroll minimum amount
        var elementRect = {
                top:    elementOffset.top,
                left:   elementOffset.left,
                height: $element.height(),
                width:  $element.width()
            },
            clip = getElementClipSize($view, elementRect);

        if (clip.bottom > 0) {
            // below viewport
            $view.scrollTop($view.scrollTop() + clip.bottom);
        } else if (clip.top > 0) {
            // above viewport
            $view.scrollTop($view.scrollTop() - clip.top);
        }

        if (scrollHorizontal) {
            if (clip.left > 0) {
                $view.scrollLeft($view.scrollLeft() - clip.left);
            } else if (clip.right > 0) {
                $view.scrollLeft($view.scrollLeft() + clip.right);
            }
        }
    }
function scrollElementIntoView($view, $element, scrollHorizontal) {
        var elementOffset = $element.offset();

        // scroll minimum amount
        var elementRect = {
                top:    elementOffset.top,
                left:   elementOffset.left,
                height: $element.height(),
                width:  $element.width()
            },
            clip = getElementClipSize($view, elementRect);

        if (clip.bottom > 0) {
            // below viewport
            $view.scrollTop($view.scrollTop() + clip.bottom);
        } else if (clip.top > 0) {
            // above viewport
            $view.scrollTop($view.scrollTop() - clip.top);
        }

        if (scrollHorizontal) {
            if (clip.left > 0) {
                $view.scrollLeft($view.scrollLeft() - clip.left);
            } else if (clip.right > 0) {
                $view.scrollLeft($view.scrollLeft() + clip.right);
            }
        }
    }
function scrollElementIntoView ( $view , $element , scrollHorizontal ) { var elementOffset = $element . offset ( ) ; // scroll minimum amount var elementRect = { top : elementOffset . top , left : elementOffset . left , height : $element . height ( ) , width : $element . width ( ) } , clip = getElementClipSize ( $view , elementRect ) ; if ( clip . bottom > 0 ) { // below viewport $view . scrollTop ( $view . scrollTop ( ) + clip . bottom ) ; } else if ( clip . top > 0 ) { // above viewport $view . scrollTop ( $view . scrollTop ( ) - clip . top ) ; } if ( scrollHorizontal ) { if ( clip . left > 0 ) { $view . scrollLeft ( $view . scrollLeft ( ) - clip . left ) ; } else if ( clip . right > 0 ) { $view . scrollLeft ( $view . scrollLeft ( ) + clip . right ) ; } } }
Within a scrolling DOMElement, if necessary, scroll element into viewport.

To Perform the minimum amount of scrolling necessary, cases should be handled as follows:
- element already completely in view : no scrolling
- element above    viewport          : scroll view so element is at top
- element left of  viewport          : scroll view so element is at left
- element below    viewport          : scroll view so element is at bottom
- element right of viewport          : scroll view so element is at right

Assumptions:
- $view is a scrolling container

@param {!DOMElement} $view - A jQuery scrolling container
@param {!DOMElement} $element - A jQuery element
@param {?boolean} scrollHorizontal - whether to also scroll horizontally
Within a scrolling DOMElement if necessary scroll element into viewport .