Handle diff comment timestamp taps with Nav API
Removes more references to page.show. Also removes a duplicate test.
Change-Id: Ib045b8f5ad1751f2cf399460d703e367f24d3811
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
index 90d465f..5165db0 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
@@ -29,6 +29,8 @@
const REPORT_UPDATE_DRAFT = 'UpdateDraftComment';
const REPORT_DISCARD_DRAFT = 'DiscardDraftComment';
+ const FILE = 'FILE';
+
Polymer({
is: 'gr-diff-comment',
@@ -64,6 +66,12 @@
* @event comment-mouse-out
*/
+ /**
+ * Fired when the comment's timestamp is tapped.
+ *
+ * @event comment-anchor-tap
+ */
+
properties: {
changeNum: String,
/** @type {?} */
@@ -333,10 +341,6 @@
}
},
- _computeLinkToComment(comment) {
- return '#' + comment.line;
- },
-
_computeDeleteButtonClass(isAdmin, draft) {
return isAdmin && !draft ? 'showDeleteButtons' : '';
},
@@ -401,15 +405,16 @@
}, STORAGE_DEBOUNCE_INTERVAL);
},
- _handleLinkTap(e) {
+ _handleAnchorTap(e) {
e.preventDefault();
- const hash = this._computeLinkToComment(this.comment);
- // Don't add the hash to the window history if it's already there.
- // Otherwise you mess up expected back button behavior.
- if (window.location.hash == hash) { return; }
- // Change the URL but don’t trigger a nav event. Otherwise it will
- // reload the page.
- page.show(window.location.pathname + hash, null, false);
+ if (!this.comment.line) { return; }
+ this.dispatchEvent(new CustomEvent('comment-anchor-tap', {
+ bubbles: true,
+ detail: {
+ number: this.comment.line || FILE,
+ side: this.side,
+ },
+ }));
},
_handleEdit(e) {