From 2b63470f4ef9e743ae94df39162a38089dca77aa Mon Sep 17 00:00:00 2001 From: Kushal Pandya Date: Mon, 2 Jan 2017 13:01:27 +0530 Subject: [PATCH 1/4] Scroll to bottom on build completion if autoscroll was active --- app/assets/javascripts/build.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/build.js b/app/assets/javascripts/build.js index bc13c46443a..207eb639780 100644 --- a/app/assets/javascripts/build.js +++ b/app/assets/javascripts/build.js @@ -83,6 +83,10 @@ return window.location.href.split("#")[0]; }; + Build.prototype.locationHash = function() { + return window.location.href.split("#")[1]; + }; + Build.prototype.getInitialBuildTrace = function() { var removeRefreshStatuses = ['success', 'failed', 'canceled', 'skipped'] @@ -91,6 +95,9 @@ dataType: 'json', success: function(buildData) { $('.js-build-output').html(buildData.trace_html); + if (this.locationHash() === 'down-build-trace') { + $("html,body").scrollTop(this.$buildTrace.height()); + } if (removeRefreshStatuses.indexOf(buildData.status) >= 0) { this.$buildRefreshAnimation.remove(); return this.initScrollMonitor(); @@ -105,6 +112,8 @@ dataType: "json", success: (function(_this) { return function(log) { + var pageUrl; + if (log.state) { _this.state = log.state; } @@ -116,7 +125,12 @@ } return _this.checkAutoscroll(); } else if (log.status !== _this.buildStatus) { - return Turbolinks.visit(_this.pageUrl); + pageUrl = _this.pageUrl; + if (_this.$autoScrollStatus.data('state') === 'enabled') { + pageUrl += '#down-build-trace'; + } + + return Turbolinks.visit(pageUrl); } }; })(this) From a9e253b569d225823b0748bcf6e3855d99b53e14 Mon Sep 17 00:00:00 2001 From: Kushal Pandya Date: Mon, 2 Jan 2017 14:52:53 +0530 Subject: [PATCH 2/4] Feature changelog entry --- .../26109-preserve-scroll-position-on-autoreload.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/unreleased/26109-preserve-scroll-position-on-autoreload.yml diff --git a/changelogs/unreleased/26109-preserve-scroll-position-on-autoreload.yml b/changelogs/unreleased/26109-preserve-scroll-position-on-autoreload.yml new file mode 100644 index 00000000000..cde0d114d7c --- /dev/null +++ b/changelogs/unreleased/26109-preserve-scroll-position-on-autoreload.yml @@ -0,0 +1,4 @@ +--- +title: Scroll to bottom on build completion if autoscroll was active +merge_request: 8391 +author: From c69931f0f0199818689aba26519b14b6e462df83 Mon Sep 17 00:00:00 2001 From: Kushal Pandya Date: Sat, 7 Jan 2017 14:13:19 +0530 Subject: [PATCH 3/4] Use better approach to access hash --- app/assets/javascripts/build.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/build.js b/app/assets/javascripts/build.js index 207eb639780..e6831b77d1c 100644 --- a/app/assets/javascripts/build.js +++ b/app/assets/javascripts/build.js @@ -5,6 +5,7 @@ (function() { var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; var AUTO_SCROLL_OFFSET = 75; + var DOWN_BUILD_TRACE = 'down-build-trace'; this.Build = (function() { Build.interval = null; @@ -83,10 +84,6 @@ return window.location.href.split("#")[0]; }; - Build.prototype.locationHash = function() { - return window.location.href.split("#")[1]; - }; - Build.prototype.getInitialBuildTrace = function() { var removeRefreshStatuses = ['success', 'failed', 'canceled', 'skipped'] @@ -95,7 +92,7 @@ dataType: 'json', success: function(buildData) { $('.js-build-output').html(buildData.trace_html); - if (this.locationHash() === 'down-build-trace') { + if (window.location.hash.substring(1) === DOWN_BUILD_TRACE) { $("html,body").scrollTop(this.$buildTrace.height()); } if (removeRefreshStatuses.indexOf(buildData.status) >= 0) { From c254d05953fbf31425f934a349a65e8866ccf07a Mon Sep 17 00:00:00 2001 From: Kushal Pandya Date: Thu, 12 Jan 2017 10:49:49 -0500 Subject: [PATCH 4/4] Use string constant variable for `#down-build-trace` --- app/assets/javascripts/build.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/build.js b/app/assets/javascripts/build.js index e6831b77d1c..fca47002870 100644 --- a/app/assets/javascripts/build.js +++ b/app/assets/javascripts/build.js @@ -5,7 +5,7 @@ (function() { var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; var AUTO_SCROLL_OFFSET = 75; - var DOWN_BUILD_TRACE = 'down-build-trace'; + var DOWN_BUILD_TRACE = '#down-build-trace'; this.Build = (function() { Build.interval = null; @@ -27,7 +27,7 @@ this.$autoScrollStatus = $('#autoscroll-status'); this.$autoScrollStatusText = this.$autoScrollStatus.find('.status-text'); this.$upBuildTrace = $('#up-build-trace'); - this.$downBuildTrace = $('#down-build-trace'); + this.$downBuildTrace = $(DOWN_BUILD_TRACE); this.$scrollTopBtn = $('#scroll-top'); this.$scrollBottomBtn = $('#scroll-bottom'); this.$buildRefreshAnimation = $('.js-build-refresh'); @@ -92,7 +92,7 @@ dataType: 'json', success: function(buildData) { $('.js-build-output').html(buildData.trace_html); - if (window.location.hash.substring(1) === DOWN_BUILD_TRACE) { + if (window.location.hash === DOWN_BUILD_TRACE) { $("html,body").scrollTop(this.$buildTrace.height()); } if (removeRefreshStatuses.indexOf(buildData.status) >= 0) { @@ -124,7 +124,7 @@ } else if (log.status !== _this.buildStatus) { pageUrl = _this.pageUrl; if (_this.$autoScrollStatus.data('state') === 'enabled') { - pageUrl += '#down-build-trace'; + pageUrl += DOWN_BUILD_TRACE; } return Turbolinks.visit(pageUrl);