mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 20:33:12 -05:00
1c9abd35f8
Conflicts: app/views/project/editor/history.jade
40 lines
No EOL
1 KiB
CoffeeScript
40 lines
No EOL
1 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 = () ->
|
|
if attrs.infiniteScrollUpwards?
|
|
atTopOfListView()
|
|
else
|
|
atBottomOfListView()
|
|
|
|
atTopOfListView = () ->
|
|
element.scrollTop() < 30
|
|
|
|
atBottomOfListView = () ->
|
|
element.scrollTop() + element.height() >= innerElement.height() - 30
|
|
|
|
listShorterThanContainer = () ->
|
|
element.height() > innerElement.height()
|
|
|
|
loadUntilFull = () ->
|
|
if (listShorterThanContainer() or atEndOfListView()) and not scope.$eval(attrs.infiniteScrollDisabled)
|
|
promise = scope.$eval(attrs.infiniteScroll)
|
|
promise.then () ->
|
|
setTimeout () ->
|
|
loadUntilFull()
|
|
, 0
|
|
|
|
element.on "scroll", (event) ->
|
|
loadUntilFull()
|
|
|
|
scope.$watch attrs.infiniteScrollInitialize, (value) ->
|
|
if value
|
|
loadUntilFull()
|
|
|
|
} |