debian-mirror-gitlab/app/assets/javascripts/lib/utils/scroll_utils.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import $ from 'jquery';
export const canScroll = () => $(document).height() > $(window).height();
/**
* Checks if the entire page is scrolled down all the way to the bottom
2018-12-05 23:21:45 +05:30
* @returns {Boolean}
2018-11-08 19:23:39 +05:30
*/
export const isScrolledToBottom = () => {
const $document = $(document);
const currentPosition = $document.scrollTop();
const scrollHeight = $document.height();
const windowHeight = $(window).height();
return scrollHeight - currentPosition === windowHeight;
};
2018-12-05 23:21:45 +05:30
/**
* Checks if page is scrolled to the top
* @returns {Boolean}
*/
export const isScrolledToTop = () => $(document).scrollTop() === 0;
2018-11-08 19:23:39 +05:30
export const scrollDown = () => {
const $document = $(document);
$document.scrollTop($document.height());
};
2018-12-05 23:21:45 +05:30
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;
};
2018-11-08 19:23:39 +05:30
export const toggleDisableButton = ($button, disable) => {
if (disable && $button.prop('disabled')) return;
$button.prop('disabled', disable);
};