     checkWhenEnabled = null
     container = null
     immediateCheck = true
+    useDocumentBottom = false
 
     # infinite-scroll specifies a function to call when the window,
     # or some other container specified by infinite-scroll-container,

    # If I don't explicitly call the handler here, tests fail. Don't know why yet.
    handleInfiniteScrollDisabled scope.infiniteScrollDisabled

    # infinite-scroll-container sets the container which we want to be
    # infinte scrolled, instead of the whole window. Must be an
    # Angular or jQuery element, or, if jQuery is loaded,

        if container.offset() != undefined
          containerTopOffset = container.offset().top
        elementBottom = elem.offset().top - containerTopOffset + elem.height()

      if(useDocumentBottom)
        elementBottom = $(document).height()

      remaining = elementBottom - containerBottom
      shouldScroll = remaining <= container.height() * scrollDistance + 1

