2012-06-12 00:59:26 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-differential-toggle-files
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-stratcom
|
2013-08-14 01:05:09 +02:00
|
|
|
* phabricator-phtize
|
2012-06-12 00:59:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('differential-toggle-files', function(config) {
|
2013-08-14 01:05:09 +02:00
|
|
|
var pht = JX.phtize(config.pht);
|
2012-06-12 00:59:26 +02:00
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'differential-toggle-file',
|
|
|
|
null,
|
|
|
|
function(e) {
|
|
|
|
if (e.getData().diff.length != 1) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-14 01:05:09 +02:00
|
|
|
|
2012-06-12 00:59:26 +02:00
|
|
|
var diff = e.getData().diff[0],
|
2013-08-14 01:14:26 +02:00
|
|
|
data = JX.Stratcom.getData(diff);
|
2013-08-14 01:05:09 +02:00
|
|
|
if (data.hidden) {
|
2012-06-12 00:59:26 +02:00
|
|
|
data.hidden = false;
|
|
|
|
JX.DOM.show(diff);
|
2013-08-14 01:14:26 +02:00
|
|
|
JX.DOM.remove(data.undo);
|
|
|
|
data.undo = null;
|
2012-06-12 00:59:26 +02:00
|
|
|
} else {
|
|
|
|
data.hidden = true;
|
2013-08-14 01:14:26 +02:00
|
|
|
data.undo = render_collapse_undo();
|
2012-06-12 00:59:26 +02:00
|
|
|
JX.DOM.hide(diff);
|
2013-08-14 01:14:26 +02:00
|
|
|
JX.DOM.listen(
|
|
|
|
data.undo,
|
|
|
|
'click',
|
|
|
|
'differential-collapse-undo',
|
|
|
|
function(e) {
|
|
|
|
e.kill();
|
|
|
|
data.hidden = false;
|
|
|
|
JX.DOM.show(diff);
|
|
|
|
JX.DOM.remove(data.undo);
|
|
|
|
data.undo = null;
|
|
|
|
});
|
|
|
|
JX.DOM.appendContent(diff.parentNode, data.undo);
|
2012-06-12 00:59:26 +02:00
|
|
|
}
|
|
|
|
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');
|
2012-08-18 01:36:42 +02:00
|
|
|
var invoked = false;
|
2012-08-10 02:53:05 +02:00
|
|
|
for (var i = 0; i < diffs.length; ++i) {
|
|
|
|
if (JX.Stratcom.getData(diffs[i]).hidden) {
|
|
|
|
JX.Stratcom.invoke('differential-toggle-file', null, {
|
2012-08-18 01:36:42 +02:00
|
|
|
diff: [ diffs[i] ]
|
2012-08-10 02:53:05 +02:00
|
|
|
});
|
2012-08-18 01:36:42 +02:00
|
|
|
invoked = true;
|
2012-08-10 02:53:05 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-18 01:36:42 +02:00
|
|
|
if (!invoked) {
|
|
|
|
e.prevent();
|
|
|
|
}
|
2012-06-12 00:59:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
elt = elt.parentNode;
|
|
|
|
}
|
2012-08-18 01:36:42 +02:00
|
|
|
e.prevent();
|
2012-06-12 00:59:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
2012-08-20 23:20:13 +02:00
|
|
|
if (!id || !id.match(/^#.+/)) {
|
2012-06-12 00:59:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-08-23 07:38:04 +02:00
|
|
|
var raw = e.getRawEvent();
|
|
|
|
if (raw.altKey || raw.ctrlKey || raw.metaKey || raw.shiftKey) {
|
|
|
|
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));
|
|
|
|
for (var i = 0; i < named.length; ++i) {
|
|
|
|
if (named[i].tagName.toLowerCase() == 'a') {
|
2012-08-18 01:36:42 +02:00
|
|
|
if (target) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
target = named[i];
|
2012-08-10 02:53:05 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-18 01:36:42 +02:00
|
|
|
if (!target) {
|
2012-08-10 02:53:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-08-18 01:36:42 +02:00
|
|
|
var event = JX.Stratcom.invoke('differential-toggle-file-request', null, {
|
|
|
|
element: target
|
2012-06-12 00:59:26 +02:00
|
|
|
});
|
2012-08-18 01:36:42 +02:00
|
|
|
if (!event.getPrevented()) {
|
|
|
|
// This event is processed after the hash has changed, so it doesn't
|
|
|
|
// automatically jump there like we want.
|
|
|
|
JX.DOM.scrollTo(target);
|
|
|
|
}
|
2013-08-14 01:05:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var render_collapse_undo = function() {
|
|
|
|
var link = JX.$N(
|
|
|
|
'a',
|
|
|
|
{href: '#', sigil: 'differential-collapse-undo'},
|
|
|
|
pht('undo'));
|
|
|
|
|
|
|
|
return JX.$N(
|
|
|
|
'div',
|
|
|
|
{className: 'differential-collapse-undo',
|
|
|
|
sigil: 'differential-collapse-undo-div'},
|
|
|
|
[pht('collapsed'), ' ', link]);
|
|
|
|
};
|
|
|
|
|
2012-06-12 00:59:26 +02:00
|
|
|
});
|