Prevent a JS error in MergeRequestTabs
When `window.location.hash` is pointing to a note, e.g. `#note_1234`, `scrollToElement` would throw an error because a selector such as `.commits #note_1234` doesn't exist, so `offset()` returned `undefined`. This error would prevent subsequent calls from running, which caused the loading spinner to never be hidden. Now we ensure the selector returns a valid element before trying to scroll to it.
This commit is contained in:
parent
2fb02f9252
commit
fc0d92746d
|
@ -68,8 +68,8 @@ class @MergeRequestTabs
|
|||
|
||||
scrollToElement: (container) ->
|
||||
if window.location.hash
|
||||
top = $(container + " " + window.location.hash).offset().top
|
||||
$('body').scrollTo(top)
|
||||
$el = $("#{container} #{window.location.hash}")
|
||||
$('body').scrollTo($el.offset().top) if $el.length
|
||||
|
||||
# Activate a tab based on the current action
|
||||
activateTab: (action) ->
|
||||
|
@ -127,7 +127,7 @@ class @MergeRequestTabs
|
|||
document.getElementById('commits').innerHTML = data.html
|
||||
$('.js-timeago').timeago()
|
||||
@commitsLoaded = true
|
||||
@scrollToElement(".commits")
|
||||
@scrollToElement("#commits")
|
||||
|
||||
loadDiff: (source) ->
|
||||
return if @diffsLoaded
|
||||
|
@ -137,7 +137,7 @@ class @MergeRequestTabs
|
|||
success: (data) =>
|
||||
document.getElementById('diffs').innerHTML = data.html
|
||||
@diffsLoaded = true
|
||||
@scrollToElement(".diffs")
|
||||
@scrollToElement("#diffs")
|
||||
|
||||
# Show or hide the loading spinner
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue