1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-29 08:50:58 +01:00
phorge-phorge/webroot/rsrc/js/application/differential/behavior-show-all-comments.js
epriestley 0569218201 Use JsShrink if jsxmin is not available
Summary: If `jsxmin` is not available, use a pure PHP implementation instead (JsShrink).

Test Plan:
  - Ran `arc lint --lintall` on all JS and fixed every relevant warning.
  - Forced minification on and browsed around the site using JS behaviors. Didn't hit anything problematic.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5670
2013-05-18 17:04:22 -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 (ex) {
}
}
});
}
JX.Stratcom.listen(
'click',
'differential-show-all-comments',
function(e) {
reveal(e.getNode('differential-all-comments-container'));
e.kill();
});
});