scroll.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. import App from '../base'
  13. export default App.directive('updateScrollBottomOn', $timeout => ({
  14. restrict: 'A',
  15. link(scope, element, attrs, ctrls) {
  16. // We keep the offset from the bottom fixed whenever the event fires
  17. //
  18. // ^ | ^
  19. // | | | scrollTop
  20. // | | v
  21. // | |-----------
  22. // | | ^
  23. // | | |
  24. // | | | clientHeight (viewable area)
  25. // | | |
  26. // | | |
  27. // | | v
  28. // | |-----------
  29. // | | ^
  30. // | | | scrollBottom
  31. // v | v
  32. // \
  33. // scrollHeight
  34. let scrollBottom = 0
  35. element.on(
  36. 'scroll',
  37. e =>
  38. (scrollBottom =
  39. element[0].scrollHeight -
  40. element[0].scrollTop -
  41. element[0].clientHeight)
  42. )
  43. return scope.$on(attrs.updateScrollBottomOn, () =>
  44. $timeout(
  45. () =>
  46. element.scrollTop(
  47. element[0].scrollHeight - element[0].clientHeight - scrollBottom
  48. ),
  49. 0
  50. )
  51. )
  52. },
  53. }))