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

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import $ from 'jquery';
2018-12-05 23:21:45 +05:30
import {
canScroll,
isScrolledToBottom,
isScrolledToTop,
isScrolledToMiddle,
toggleDisableButton,
} from './scroll_utils';
2018-11-08 19:23:39 +05:30
export default class LogOutputBehaviours {
constructor() {
// Scroll buttons
this.$scrollTopBtn = $('.js-scroll-up');
this.$scrollBottomBtn = $('.js-scroll-down');
this.$scrollTopBtn.off('click').on('click', this.scrollToTop.bind(this));
this.$scrollBottomBtn.off('click').on('click', this.scrollToBottom.bind(this));
}
toggleScroll() {
if (canScroll()) {
2018-12-05 23:21:45 +05:30
if (isScrolledToMiddle()) {
2018-11-08 19:23:39 +05:30
// User is in the middle of the log
toggleDisableButton(this.$scrollTopBtn, false);
toggleDisableButton(this.$scrollBottomBtn, false);
2018-12-05 23:21:45 +05:30
} else if (isScrolledToTop()) {
2018-11-08 19:23:39 +05:30
// User is at Top of Log
toggleDisableButton(this.$scrollTopBtn, true);
toggleDisableButton(this.$scrollBottomBtn, false);
} else if (isScrolledToBottom()) {
// User is at the bottom of the build log.
toggleDisableButton(this.$scrollTopBtn, false);
toggleDisableButton(this.$scrollBottomBtn, true);
}
} else {
toggleDisableButton(this.$scrollTopBtn, true);
toggleDisableButton(this.$scrollBottomBtn, true);
}
}
toggleScrollAnimation(toggle) {
this.$scrollBottomBtn.toggleClass('animate', toggle);
}
}