summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/scroll_utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/lib/utils/scroll_utils.js')
-rw-r--r--app/assets/javascripts/lib/utils/scroll_utils.js29
1 files changed, 4 insertions, 25 deletions
diff --git a/app/assets/javascripts/lib/utils/scroll_utils.js b/app/assets/javascripts/lib/utils/scroll_utils.js
index 01e43fd3b93..bab84448657 100644
--- a/app/assets/javascripts/lib/utils/scroll_utils.js
+++ b/app/assets/javascripts/lib/utils/scroll_utils.js
@@ -7,14 +7,11 @@ export const canScroll = () => $(document).height() > $(window).height();
* @returns {Boolean}
*/
export const isScrolledToBottom = () => {
- const $document = $(document);
-
- const currentPosition = $document.scrollTop();
- const scrollHeight = $document.height();
-
- const windowHeight = $(window).height();
+ // Use clientHeight to account for any horizontal scrollbar.
+ const { scrollHeight, scrollTop, clientHeight } = document.documentElement;
- return scrollHeight - currentPosition === windowHeight;
+ // scrollTop can be a float, so round up to next integer.
+ return Math.ceil(scrollTop + clientHeight) >= scrollHeight;
};
/**
@@ -31,21 +28,3 @@ export const scrollDown = () => {
export const scrollUp = () => {
$(document).scrollTop(0);
};
-
-/**
- * Checks if scroll position is in the middle of the page
- * @returns {Boolean}
- */
-export const isScrolledToMiddle = () => {
- const $document = $(document);
- const currentPosition = $document.scrollTop();
- const scrollHeight = $document.height();
- const windowHeight = $(window).height();
-
- return currentPosition > 0 && scrollHeight - currentPosition !== windowHeight;
-};
-
-export const toggleDisableButton = ($button, disable) => {
- if (disable && $button.prop('disabled')) return;
- $button.prop('disabled', disable);
-};