2012-06-12 00:59:26 +02:00
|
|
|
/**
|
|
|
|
* @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) {
|
2012-08-10 02:53:05 +02:00
|
|
|
if (JX.Stratcom.hasSigil(elt, 'differential-changeset')) {
|
|
|
|
var diffs = JX.DOM.scry(elt, 'table', 'differential-diff');
|
|
|
|
for (var i = 0; i < diffs.length; ++i) {
|
|
|
|
if (JX.Stratcom.getData(diffs[i]).hidden) {
|
|
|
|
JX.Stratcom.invoke('differential-toggle-file', null, {
|
|
|
|
diff: [ diffs[i] ],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2012-06-12 00:59:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
elt = elt.parentNode;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
2012-08-10 02:53:05 +02:00
|
|
|
'click',
|
|
|
|
'tag:a',
|
2012-06-12 00:59:26 +02:00
|
|
|
function(e) {
|
2012-08-10 02:53:05 +02:00
|
|
|
var link = e.getNode('tag:a');
|
|
|
|
var id = link.getAttribute('href');
|
|
|
|
if (!id.match(/^#.+/)) {
|
2012-06-12 00:59:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-08-10 02:53:05 +02:00
|
|
|
// The target may have either a matching name or a matching id.
|
|
|
|
var target;
|
|
|
|
try {
|
|
|
|
target = JX.$(id.substr(1));
|
|
|
|
} catch(err) {
|
|
|
|
var named = document.getElementsByName(id.substr(1));
|
|
|
|
var matches = [];
|
|
|
|
for (var i = 0; i < named.length; ++i) {
|
|
|
|
if (named[i].tagName.toLowerCase() == 'a') {
|
|
|
|
matches.push(named[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (matches.length == 1) {
|
|
|
|
target = matches[0];
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-12 00:59:26 +02:00
|
|
|
JX.Stratcom.invoke('differential-toggle-file-request', null, {
|
2012-08-10 02:53:05 +02:00
|
|
|
element: target,
|
2012-06-12 00:59:26 +02:00
|
|
|
});
|
|
|
|
// This event is processed after the hash has changed, so it doesn't
|
|
|
|
// automatically jump there like we want.
|
2012-08-10 02:53:05 +02:00
|
|
|
JX.DOM.scrollTo(target);
|
2012-06-12 00:59:26 +02:00
|
|
|
});
|
|
|
|
});
|