Commit c02945ac authored by Kushal Pandya's avatar Kushal Pandya

Cache commonly referenced DOM elements, cleaning up

parent a8fa87ce
...@@ -31,6 +31,15 @@ ...@@ -31,6 +31,15 @@
this.buildStage = options.buildStage; this.buildStage = options.buildStage;
this.updateDropdown = bind(this.updateDropdown, this); this.updateDropdown = bind(this.updateDropdown, this);
this.$document = $(document); this.$document = $(document);
this.$body = $('body');
this.$buildTrace = $('#build-trace');
this.$autoScrollContainer = $('.autoscroll-container');
this.$autoScrollStatus = $('#autoscroll-status');
this.$upBuildTrace = $('#up-build-trace');
this.$downBuildTrace = $('#down-build-trace');
this.$scrollTopBtn = $('#scroll-top');
this.$scrollBottomBtn = $('#scroll-bottom');
clearInterval(Build.interval); clearInterval(Build.interval);
// Init breakpoint checker // Init breakpoint checker
this.bp = Breakpoints.get(); this.bp = Breakpoints.get();
...@@ -123,24 +132,15 @@ ...@@ -123,24 +132,15 @@
}; };
Build.prototype.checkAutoscroll = function() { Build.prototype.checkAutoscroll = function() {
if ("enabled" === $("#autoscroll-status").data("state")) { if ($("#autoscroll-status").data("state") === "enabled") {
return $("html,body").scrollTop($("#build-trace").height()); return $("html,body").scrollTop($("#build-trace").height());
} }
}; };
Build.prototype.initScrollButtonAffix = function() { Build.prototype.initScrollButtonAffix = function() {
var $body = $('body'); this.$scrollTopBtn.hide().removeClass('sticky');
var $buildTrace = $('#build-trace'); this.$scrollBottomBtn.show().addClass('sticky');
var $scrollTopBtn = $('#scroll-top'); this.$autoScrollContainer.hide();
var $scrollBottomBtn = $('#scroll-bottom');
var $autoScrollContainer = $('.autoscroll-container');
$scrollTopBtn.hide().removeClass('sticky');
$scrollBottomBtn.show().addClass('sticky');
if ($autoScrollContainer.length) {
$autoScrollContainer.hide();
}
} }
// Page scroll listener to detect if user has scrolling page // Page scroll listener to detect if user has scrolling page
...@@ -158,43 +158,32 @@ ...@@ -158,43 +158,32 @@
// - Show Bottom Arrow button // - Show Bottom Arrow button
// - Disable Autoscroll and hide indicator (when build is running) // - Disable Autoscroll and hide indicator (when build is running)
Build.prototype.initScrollMonitor = function() { Build.prototype.initScrollMonitor = function() {
var $body = $('body'); if (isInViewport(this.$upBuildTrace)) { // User is at Top of Build Log
var $buildTrace = $('#build-trace'); this.$scrollTopBtn.hide().removeClass('sticky');
var $autoScrollContainer = $('.autoscroll-container'); this.$scrollBottomBtn.show().addClass('sticky');
var $autoScrollStatus = $('#autoscroll-status');
var $upBuildTrace = $('#up-build-trace');
var $downBuildTrace = $('#down-build-trace');
var $scrollTopBtn = $('#scroll-top');
var $scrollBottomBtn = $('#scroll-bottom');
if (isInViewport($upBuildTrace)) { // User is at Top of Build Log
$scrollTopBtn.hide().removeClass('sticky');
$scrollBottomBtn.show().addClass('sticky');
} }
if (isInViewport($downBuildTrace)) { // User is at Bottom of Build Log if (isInViewport(this.$downBuildTrace)) { // User is at Bottom of Build Log
$scrollTopBtn.show().addClass('sticky'); this.$scrollTopBtn.show().addClass('sticky');
$scrollBottomBtn.hide().removeClass('sticky'); this.$scrollBottomBtn.hide().removeClass('sticky');
if ($autoScrollContainer.length) { // Show and Reposition Autoscroll Status Message // Show and Reposition Autoscroll Status Indicator
$autoScrollContainer.show().css({ top: $body.outerHeight() - 75 }); this.$autoScrollContainer.css({ top: this.$body.outerHeight() - 75 }).fadeIn(100);
$autoScrollStatus.find('.status-text').addClass('animate'); this.$autoScrollStatus.find('.status-text').addClass('animate');
}
} }
if (!isInViewport($upBuildTrace) && !isInViewport($downBuildTrace)) { // User is somewhere in middle of Build Log if (!isInViewport(this.$upBuildTrace) && !isInViewport(this.$downBuildTrace)) { // User is somewhere in middle of Build Log
$scrollTopBtn.show().addClass('sticky'); this.$scrollTopBtn.show().addClass('sticky');
$scrollBottomBtn.show().addClass('sticky'); this.$scrollBottomBtn.show().addClass('sticky');
if ($autoScrollContainer.length) { // Hide Autoscroll Status Indicator
$autoScrollContainer.hide(); this.$autoScrollContainer.hide();
$autoScrollStatus.find('.status-text').removeClass('animate'); this.$autoScrollStatus.find('.status-text').removeClass('animate');
}
} }
if (this.buildStatus === "running" || this.buildStatus === "pending") { if (this.buildStatus === "running" || this.buildStatus === "pending") {
// Check if Refresh Animation is in Viewport and enable Autoscroll, disable otherwise. // Check if Refresh Animation is in Viewport and enable Autoscroll, disable otherwise.
$autoScrollStatus.data("state", isInViewport($('.js-build-refresh')) ? 'enabled' : 'disabled'); this.$autoScrollStatus.data("state", isInViewport($('.js-build-refresh')) ? 'enabled' : 'disabled');
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment