scroll.js 1.5 KB

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