mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
45 lines
No EOL
1.3 KiB
CoffeeScript
45 lines
No EOL
1.3 KiB
CoffeeScript
define [
|
|
"base"
|
|
], (App) ->
|
|
App.directive "infiniteScroll", () ->
|
|
return {
|
|
link: (scope, element, attrs, ctrl) ->
|
|
innerElement = element.find(".infinite-scroll-inner")
|
|
element.css 'overflow-y': 'auto'
|
|
|
|
atEndOfListView = () ->
|
|
element.scrollTop() + element.height() >= innerElement.height() - 30
|
|
|
|
listShorterThanContainer = () ->
|
|
element.innerHeight() > @$(".change-list").outerHeight()
|
|
|
|
loadUntilFull = () ->
|
|
if (listShorterThanContainer() or atEndOfListView()) and not scope.$eval(attrs.infiniteScrollDisabled)
|
|
console.log "Loading more"
|
|
promise = scope.$eval(attrs.infiniteScroll)
|
|
console.log promise
|
|
promise.then () ->
|
|
loadUntilFull()
|
|
# @collection.fetchNextBatch
|
|
# error: (error) =>
|
|
# @hideLoading()
|
|
# @showEmptyMessageIfCollectionEmpty()
|
|
# callback(error)
|
|
# success: (collection, response) =>
|
|
# @hideLoading()
|
|
# if @collection.isAtEnd()
|
|
# @atEndOfCollection = true
|
|
# @showEmptyMessageIfCollectionEmpty()
|
|
# callback()
|
|
# else
|
|
# @loadUntilFull(callback)
|
|
|
|
element.on "scroll", (event) ->
|
|
loadUntilFull()
|
|
|
|
scope.$watch attrs.infiniteScrollInitialize, (value) ->
|
|
console.log "INITIALIZE", value
|
|
if value
|
|
loadUntilFull()
|
|
|
|
} |