scroll.coffee 856 B

123456789101112131415161718192021222324252627282930313233343536
  1. define [
  2. "base"
  3. ], (App) ->
  4. App.directive "updateScrollBottomOn", ($timeout) ->
  5. return {
  6. restrict: "A"
  7. link: (scope, element, attrs, ctrls) ->
  8. # We keep the offset from the bottom fixed whenever the event fires
  9. #
  10. # ^ | ^
  11. # | | | scrollTop
  12. # | | v
  13. # | |-----------
  14. # | | ^
  15. # | | |
  16. # | | | clientHeight (viewable area)
  17. # | | |
  18. # | | |
  19. # | | v
  20. # | |-----------
  21. # | | ^
  22. # | | | scrollBottom
  23. # v | v
  24. # \
  25. # scrollHeight
  26. scrollBottom = 0
  27. element.on "scroll", (e) ->
  28. scrollBottom = element[0].scrollHeight - element[0].scrollTop - element[0].clientHeight
  29. scope.$on attrs.updateScrollBottomOn, () ->
  30. $timeout () ->
  31. element.scrollTop(element[0].scrollHeight - element[0].clientHeight - scrollBottom)
  32. , 0
  33. }