2012-08-04 18:47:51 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-diffusion-line-linker
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-stratcom
|
|
|
|
* javelin-dom
|
2013-03-01 03:58:00 +01:00
|
|
|
* javelin-history
|
2012-08-04 18:47:51 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('diffusion-line-linker', function() {
|
|
|
|
|
|
|
|
var origin = null;
|
|
|
|
var target = null;
|
|
|
|
var root = null;
|
|
|
|
|
|
|
|
function getRowNumber(tr) {
|
|
|
|
var th = JX.DOM.find(tr, 'th', 'diffusion-line-link');
|
|
|
|
return +(th.textContent || th.innerText);
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mousedown',
|
|
|
|
'diffusion-line-link',
|
|
|
|
function(e) {
|
|
|
|
if (e.isRightButton()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
origin = e.getNode('tag:tr');
|
|
|
|
target = origin;
|
|
|
|
root = e.getNode('diffusion-source');
|
|
|
|
e.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
2013-03-01 03:58:00 +01:00
|
|
|
'click',
|
|
|
|
'diffusion-line-link',
|
2012-08-04 18:47:51 +02:00
|
|
|
function(e) {
|
2013-03-01 03:58:00 +01:00
|
|
|
e.kill();
|
|
|
|
});
|
2012-08-04 18:47:51 +02:00
|
|
|
|
2013-03-01 03:58:00 +01:00
|
|
|
var highlight = function(e) {
|
|
|
|
if (!origin || e.getNode('diffusion-source') !== root) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
target = e.getNode('tag:tr');
|
|
|
|
|
|
|
|
var highlighting = false;
|
|
|
|
var source = null;
|
|
|
|
var trs = JX.DOM.scry(root, 'tr');
|
|
|
|
for (var i = 0; i < trs.length; i++) {
|
|
|
|
if (!highlighting && (trs[i] === origin || trs[i] === target)) {
|
|
|
|
highlighting = true;
|
|
|
|
source = trs[i];
|
2012-08-04 18:47:51 +02:00
|
|
|
}
|
2013-03-01 03:58:00 +01:00
|
|
|
JX.DOM.alterClass(trs[i], 'highlighted', highlighting);
|
|
|
|
if (trs[i] === (source === origin ? target : origin)) {
|
|
|
|
highlighting = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
JX.Stratcom.listen('mouseover', 'diffusion-source', highlight);
|
2012-08-04 18:47:51 +02:00
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseup',
|
|
|
|
null,
|
|
|
|
function(e) {
|
|
|
|
if (!origin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-01 03:58:00 +01:00
|
|
|
highlight(e);
|
|
|
|
|
2012-08-04 18:47:51 +02:00
|
|
|
var o = getRowNumber(origin);
|
|
|
|
var t = getRowNumber(target);
|
|
|
|
var lines = (o == t ? o : Math.min(o, t) + '-' + Math.max(o, t));
|
|
|
|
var th = JX.DOM.find(origin, 'th', 'diffusion-line-link');
|
|
|
|
var uri = JX.DOM.find(th, 'a').href;
|
|
|
|
uri = uri.replace(/(.*\$)\d+/, '$1' + lines);
|
|
|
|
|
|
|
|
origin = null;
|
|
|
|
target = null;
|
|
|
|
e.kill();
|
2013-03-01 03:58:00 +01:00
|
|
|
JX.History.replace(uri);
|
2012-08-04 18:47:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|