1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 17:02:41 +01:00
phorge-phorge/webroot/rsrc/js/application/differential/behavior-show-all-comments.js
epriestley 67459092d7 Expand comments on page load only when the anchor points into them
Summary:
Ref T3099. Currently, we expand comments in Differential when //any// anchor is present. This creates a scrolling issue described in T3099. Instead, expand them only when the anchor contains `comment`.

We can go further here, but this should fix the immediate issue.

Test Plan: Viewed `/D22`, `/D22#toc`, and `/D22#comment-3`. The first two did not expand comments; the last one did.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3099

Differential Revision: https://secure.phabricator.com/D5836
2013-05-06 11:44:15 -07:00

59 lines
1.4 KiB
JavaScript

/**
* @provides javelin-behavior-differential-show-all-comments
* @requires javelin-behavior
* javelin-stratcom
* javelin-dom
*/
JX.behavior('differential-show-all-comments', function(config) {
var shown = false;
function reveal(node) {
if (shown) {
return false;
}
shown = true;
node = node || JX.DOM.find(
document.body,
'div',
'differential-all-comments-container');
if (node) {
JX.DOM.setContent(node, JX.$H(config.markup));
}
return true;
}
// Reveal the hidden comments if the user clicks "Show All Comments", or if
// there's an anchor in the URL, since we don't want to link to "#comment-3"
// and have it collapsed.
function at_comment_hash() {
return window.location.hash && window.location.hash.match(/comment/);
}
if (at_comment_hash()) {
reveal();
} else {
JX.Stratcom.listen(
'hashchange',
null,
function(e) {
if (at_comment_hash() && reveal()) {
try {
var target = JX.$(window.location.hash.replace(/^#/, ''));
window.scrollTo(0, target.offsetTop);
} catch (e) {
}
}
});
}
JX.Stratcom.listen(
'click',
'differential-show-all-comments',
function(e) {
reveal(e.getNode('differential-all-comments-container'));
e.kill();
});
});