1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 23:32:40 +01:00
phorge-phorge/webroot/rsrc/js/application/differential/behavior-toggle-files.js
Alan Huang d5e61f5250 Let the viewer collapse/expand individual files in a diff.
Summary:
Added a dropdown menu button and the keyboard shortcut 'h' to the
web diff view. These hide or show the annotated code display.

Test Plan:
Viewed an example diff that changed a large number of source files
and played around with keyboard shortcuts. Everything seemed to
work as expected.

Reviewers: nh, epriestley

Reviewed By: epriestley

CC: aran, epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D2714
2012-06-13 16:52:42 -07:00

62 lines
1.6 KiB
JavaScript

/**
* @provides javelin-behavior-differential-toggle-files
* @requires javelin-behavior
* javelin-dom
* javelin-stratcom
* phabricator-keyboard-shortcut
*/
JX.behavior('differential-toggle-files', function(config) {
JX.Stratcom.listen(
'differential-toggle-file',
null,
function(e) {
if (e.getData().diff.length != 1) {
return;
}
var diff = e.getData().diff[0],
data = JX.Stratcom.getData(diff);
if(data.hidden) {
data.hidden = false;
JX.DOM.show(diff);
} else {
data.hidden = true;
JX.DOM.hide(diff);
}
JX.Stratcom.invoke('differential-toggle-file-toggled');
});
JX.Stratcom.listen(
'differential-toggle-file-request',
null,
function(e) {
var elt = e.getData().element;
while (elt !== document.body) {
if (JX.Stratcom.hasSigil(elt, 'differential-diff') &&
JX.Stratcom.getData(elt).hidden) {
JX.Stratcom.invoke('differential-toggle-file', null, {
diff: [ elt ],
});
return;
}
elt = elt.parentNode;
}
});
JX.Stratcom.listen(
'hashchange',
null,
function(e) {
var id = window.location.hash;
if (!id.match(/^#/)) {
return;
}
JX.Stratcom.invoke('differential-toggle-file-request', null, {
element: JX.$(id.substr(1)),
});
// This event is processed after the hash has changed, so it doesn't
// automatically jump there like we want.
JX.DOM.scrollTo(JX.$(id.substr(1)));
});
});