scroll.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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', [
  14. '$timeout',
  15. $timeout => ({
  16. restrict: 'A',
  17. link(scope, element, attrs, ctrls) {
  18. // We keep the offset from the bottom fixed whenever the event fires
  19. //
  20. // ^ | ^
  21. // | | | scrollTop
  22. // | | v
  23. // | |-----------
  24. // | | ^
  25. // | | |
  26. // | | | clientHeight (viewable area)
  27. // | | |
  28. // | | |
  29. // | | v
  30. // | |-----------
  31. // | | ^
  32. // | | | scrollBottom
  33. // v | v
  34. // \
  35. // scrollHeight
  36. let scrollBottom = 0
  37. element.on(
  38. 'scroll',
  39. e =>
  40. (scrollBottom =
  41. element[0].scrollHeight -
  42. element[0].scrollTop -
  43. element[0].clientHeight)
  44. )
  45. return scope.$on(attrs.updateScrollBottomOn, () =>
  46. $timeout(
  47. () =>
  48. element.scrollTop(
  49. element[0].scrollHeight - element[0].clientHeight - scrollBottom
  50. ),
  51. 0
  52. )
  53. )
  54. },
  55. }),
  56. ])