summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/merge_request_tabs.js
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-05-16 09:22:52 +0000
committerFatih Acet <acetfatih@gmail.com>2017-05-16 09:22:52 +0000
commit1a24a6704f342d41cb9c70bbb282c57fdf76033c (patch)
tree5848cead0296d9ccf8c59fe35e24bd1c3e571282 /app/assets/javascripts/merge_request_tabs.js
parentb0ce5e1e307f5696aa3d9b030a3bce424becb3b5 (diff)
parent16da7f2365fe67c078a2f10766662b93fe8576fc (diff)
downloadgitlab-ce-1a24a6704f342d41cb9c70bbb282c57fdf76033c.tar.gz
Merge branch '32125-fix-link-to-note-in-diff' into 'master'
Fix linking to resolved note in diff Closes #32125 See merge request !11327
Diffstat (limited to 'app/assets/javascripts/merge_request_tabs.js')
-rw-r--r--app/assets/javascripts/merge_request_tabs.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js
index ebb217ab13a..37822dac064 100644
--- a/app/assets/javascripts/merge_request_tabs.js
+++ b/app/assets/javascripts/merge_request_tabs.js
@@ -1,6 +1,7 @@
/* eslint-disable no-new, class-methods-use-this */
/* global Breakpoints */
/* global Flash */
+/* global notes */
import Cookies from 'js-cookie';
import './breakpoints';
@@ -251,7 +252,8 @@ import BlobForkSuggestion from './blob/blob_fork_suggestion';
this.ajaxGet({
url: `${urlPathname}.json${location.search}`,
success: (data) => {
- $('#diffs').html(data.html);
+ const $container = $('#diffs');
+ $container.html(data.html);
if (typeof gl.diffNotesCompileComponents !== 'undefined') {
gl.diffNotesCompileComponents();
@@ -278,6 +280,20 @@ import BlobForkSuggestion from './blob/blob_fork_suggestion';
})
.init();
});
+
+ // Scroll any linked note into view
+ // Similar to `toggler_behavior` in the discussion tab
+ const hash = window.gl.utils.getLocationHash();
+ const anchor = hash && $container.find(`[id="${hash}"]`);
+ if (anchor) {
+ const notesContent = anchor.closest('.notes_content');
+ const lineType = notesContent.hasClass('new') ? 'new' : 'old';
+ notes.addDiffNote(anchor, lineType, false);
+ anchor[0].scrollIntoView();
+ // We have multiple elements on the page with `#note_xxx`
+ // (discussion and diff tabs) and `:target` only applies to the first
+ anchor.addClass('target');
+ }
},
});
}