2012-06-12 00:59:26 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-differential-toggle-files
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-stratcom
|
|
|
|
*/
|
|
|
|
|
|
|
|
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');
|
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-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);
|
|
|
|
}
|
2012-06-12 00:59:26 +02:00
|
|
|
});
|
|
|
|
});
|