diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-11-08 16:48:30 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-11-08 16:58:09 +0000 |
commit | 0b5eda180ce18783a7385817220cc101c666af3e (patch) | |
tree | 287fa1d36b62ccafd397f8e4ff96c344c986d3f6 | |
parent | 62527afd2297a36c2de9e9394e56a9191980b479 (diff) | |
download | gitlab-ce-39109-reenable-scroll-job.tar.gz |
Improve naming and cache variables39109-reenable-scroll-job
-rw-r--r-- | app/assets/javascripts/job.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/app/assets/javascripts/job.js b/app/assets/javascripts/job.js index 4342f94c040..cf8fda9a4fa 100644 --- a/app/assets/javascripts/job.js +++ b/app/assets/javascripts/job.js @@ -14,6 +14,7 @@ export default class Job { this.state = this.options.logState; this.buildStage = this.options.buildStage; this.$document = $(document); + this.$window = $(window); this.logBytes = 0; this.updateDropdown = this.updateDropdown.bind(this); @@ -53,18 +54,18 @@ export default class Job { this.scrollThrottled = _.throttle(this.toggleScroll.bind(this), 100); - $(window) + this.$window .off('scroll') .on('scroll', () => { - if (!Job.getIsScrollInBottom()) { + if (!this.isScrolledToBottom()) { this.toggleScrollAnimation(false); - } else if (Job.getIsScrollInBottom() && !this.isLogComplete) { + } else if (this.isScrolledToBottom() && !this.isLogComplete) { this.toggleScrollAnimation(true); } this.scrollThrottled(); }); - $(window) + this.$window .off('resize.build') .on('resize.build', _.throttle(this.sidebarOnResize.bind(this), 100)); @@ -93,14 +94,14 @@ export default class Job { // eslint-disable-next-line class-methods-use-this canScroll() { - return $(document).height() > $(window).height(); + return this.$document.height() > this.$window.height(); } toggleScroll() { - const currentPosition = $(document).scrollTop(); - const scrollHeight = $(document).height(); + const currentPosition = this.$document.scrollTop(); + const scrollHeight = this.$document.height(); - const windowHeight = $(window).height(); + const windowHeight = this.$window.height(); if (this.canScroll()) { if (currentPosition > 0 && (scrollHeight - currentPosition !== windowHeight)) { @@ -113,7 +114,7 @@ export default class Job { this.toggleDisableButton(this.$scrollTopBtn, true); this.toggleDisableButton(this.$scrollBottomBtn, false); - } else if (Job.getIsScrollInBottom()) { + } else if (this.isScrolledToBottom()) { // User is at the bottom of the build log. this.toggleDisableButton(this.$scrollTopBtn, false); @@ -125,17 +126,17 @@ export default class Job { } } - static getIsScrollInBottom() { - const currentPosition = $(document).scrollTop(); - const scrollHeight = $(document).height(); + isScrolledToBottom() { + const currentPosition = this.$document.scrollTop(); + const scrollHeight = this.$document.height(); - const windowHeight = $(window).height(); + const windowHeight = this.$window.height(); return scrollHeight - currentPosition === windowHeight; } // eslint-disable-next-line class-methods-use-this scrollDown() { - $(document).scrollTop($(document).height()); + this.$document.scrollTop(this.$document.height()); } scrollToBottom() { @@ -145,7 +146,7 @@ export default class Job { } scrollToTop() { - $(document).scrollTop(0); + this.$document.scrollTop(0); this.hasBeenScrolled = true; this.toggleScroll(); } @@ -176,7 +177,7 @@ export default class Job { this.state = log.state; } - this.isScrollInBottom = Job.getIsScrollInBottom(); + this.isScrollInBottom = this.isScrolledToBottom(); if (log.append) { this.$buildTraceOutput.append(log.html); |