Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
153dddef
Commit
153dddef
authored
Nov 27, 2018
by
Sam Bigelow
Committed by
Phil Hughes
Nov 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Jump to top in merge request"
parent
a99f342b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
0 deletions
+61
-0
app/assets/javascripts/merge_request_tabs.js
app/assets/javascripts/merge_request_tabs.js
+22
-0
changelogs/unreleased/52276-jump-to-top-in-merge-request.yml
changelogs/unreleased/52276-jump-to-top-in-merge-request.yml
+5
-0
spec/javascripts/merge_request_tabs_spec.js
spec/javascripts/merge_request_tabs_spec.js
+34
-0
No files found.
app/assets/javascripts/merge_request_tabs.js
View file @
153dddef
...
...
@@ -217,6 +217,28 @@ export default class MergeRequestTabs {
}
this
.
eventHub
.
$emit
(
'
MergeRequestTabChange
'
,
this
.
getCurrentAction
());
}
else
if
(
action
===
this
.
currentAction
)
{
// ContentTop is used to handle anything at the top of the page before the main content
const
mainContentContainer
=
document
.
querySelector
(
'
.content-wrapper
'
);
const
tabContentContainer
=
document
.
querySelector
(
'
.tab-content
'
);
if
(
mainContentContainer
&&
tabContentContainer
)
{
const
mainContentTop
=
mainContentContainer
.
getBoundingClientRect
().
top
;
const
tabContentTop
=
tabContentContainer
.
getBoundingClientRect
().
top
;
// 51px is the height of the navbar buttons, e.g. `Discussion | Commits | Changes`
const
scrollDestination
=
tabContentTop
-
mainContentTop
-
51
;
// scrollBehavior is only available in browsers that support scrollToOptions
if
(
'
scrollBehavior
'
in
document
.
documentElement
.
style
)
{
window
.
scrollTo
({
top
:
scrollDestination
,
behavior
:
'
smooth
'
,
});
}
else
{
window
.
scrollTo
(
0
,
scrollDestination
);
}
}
}
}
...
...
changelogs/unreleased/52276-jump-to-top-in-merge-request.yml
0 → 100644
View file @
153dddef
---
title
:
Allow user to scroll to top of tab on MR page
merge_request
:
author
:
type
:
added
spec/javascripts/merge_request_tabs_spec.js
View file @
153dddef
...
...
@@ -239,4 +239,38 @@ describe('MergeRequestTabs', function() {
expect
(
$
(
'
.content-wrapper
'
)).
toContainElement
(
'
.container-limited
'
);
});
});
describe
(
'
tabShown
'
,
function
()
{
const
mainContent
=
document
.
createElement
(
'
div
'
);
const
tabContent
=
document
.
createElement
(
'
div
'
);
beforeEach
(
function
()
{
spyOn
(
mainContent
,
'
getBoundingClientRect
'
).
and
.
returnValue
({
top
:
10
});
spyOn
(
tabContent
,
'
getBoundingClientRect
'
).
and
.
returnValue
({
top
:
100
});
spyOn
(
document
,
'
querySelector
'
).
and
.
callFake
(
function
(
selector
)
{
return
selector
===
'
.content-wrapper
'
?
mainContent
:
tabContent
;
});
this
.
class
.
currentAction
=
'
commits
'
;
});
it
(
'
calls window scrollTo with options if document has scrollBehavior
'
,
function
()
{
document
.
documentElement
.
style
.
scrollBehavior
=
''
;
spyOn
(
window
,
'
scrollTo
'
);
this
.
class
.
tabShown
(
'
commits
'
,
'
foobar
'
);
expect
(
window
.
scrollTo
.
calls
.
first
().
args
[
0
]).
toEqual
({
top
:
39
,
behavior
:
'
smooth
'
});
});
it
(
'
calls window scrollTo with two args if document does not have scrollBehavior
'
,
function
()
{
spyOnProperty
(
document
.
documentElement
,
'
style
'
,
'
get
'
).
and
.
returnValue
({});
spyOn
(
window
,
'
scrollTo
'
);
this
.
class
.
tabShown
(
'
commits
'
,
'
foobar
'
);
expect
(
window
.
scrollTo
.
calls
.
first
().
args
).
toEqual
([
0
,
39
]);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment