scroll.js 1.4 KB

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