Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scroll_utils.js « utils « lib « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01e43fd3b93513742a9f7b6b3b87e7b5f978b64c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import $ from 'jquery';

export const canScroll = () => $(document).height() > $(window).height();

/**
 * Checks if the entire page is scrolled down all the way to the bottom
 *  @returns {Boolean}
 */
export const isScrolledToBottom = () => {
  const $document = $(document);

  const currentPosition = $document.scrollTop();
  const scrollHeight = $document.height();

  const windowHeight = $(window).height();

  return scrollHeight - currentPosition === windowHeight;
};

/**
 * Checks if page is scrolled to the top
 * @returns {Boolean}
 */
export const isScrolledToTop = () => $(document).scrollTop() === 0;

export const scrollDown = () => {
  const $document = $(document);
  $document.scrollTop($document.height());
};

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);
};