phorge/webroot/rsrc/js/application/repository/repository-crossreference.js
Alan Huang b43e6f2a5f Make symbol linking more lenient.
Summary:
Sometimes a symbol has a nested <span> in it. Clicks on that
should count as clicks on the symbol. So keep looking for symbols among
the ancestors of the click target.

This is a silly method because I don't know if there's a more idiomatic
way to do it in Javelin.

Test Plan:
Open a Differential revision where part of a symbol is
highlighted. Click on the highlighted part. Symbol search opens.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley

Maniphest Tasks: T1577

Differential Revision: https://secure.phabricator.com/D3113
2012-07-31 17:01:57 -07:00

41 lines
1.2 KiB
JavaScript

/**
* @provides javelin-behavior-repository-crossreference
* @requires javelin-behavior
* javelin-dom
* javelin-uri
*/
JX.behavior('repository-crossreference', function(config) {
// NOTE: Pretty much everything in this file is a worst practice. We're
// constrained by the markup generated by the syntax highlighters.
var container = JX.$(config.container);
JX.DOM.alterClass(container, 'repository-crossreference', true);
JX.DOM.listen(
container,
'click',
'tag:span',
function(e) {
var target = e.getTarget();
var map = {nc : 'class', nf : 'function'};
while (target !== document.body) {
if (JX.DOM.isNode(target, 'span') && (target.className in map)) {
var symbol = target.textContent || target.innerText;
var uri = JX.$U('/diffusion/symbol/' + symbol + '/');
uri.addQueryParams({
type : map[target.className],
lang : config.lang,
projects : config.projects.join(','),
jump : true
});
window.open(uri);
e.kill();
break;
}
target = target.parentNode;
}
});
});