2011-09-06 11:35:14 -07:00
|
|
|
/**
|
|
|
|
|
* @provides javelin-behavior-repository-crossreference
|
|
|
|
|
* @requires javelin-behavior
|
|
|
|
|
* javelin-dom
|
2012-09-17 14:50:49 -07:00
|
|
|
* javelin-stratcom
|
2011-09-06 11:35:14 -07:00
|
|
|
* 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.
|
|
|
|
|
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 14:03:26 -07:00
|
|
|
function link(element, lang) {
|
|
|
|
|
JX.DOM.alterClass(element, 'repository-crossreference', true);
|
|
|
|
|
JX.DOM.listen(
|
|
|
|
|
element,
|
|
|
|
|
'click',
|
|
|
|
|
'tag:span',
|
|
|
|
|
function(e) {
|
|
|
|
|
var target = e.getTarget();
|
|
|
|
|
var map = {nc : 'class', nf : 'function', na : null};
|
|
|
|
|
while (target !== document.body) {
|
|
|
|
|
if (JX.DOM.isNode(target, 'span') && (target.className in map)) {
|
2013-02-21 09:49:06 -08:00
|
|
|
var timeout = function() {
|
|
|
|
|
if (window.getSelection && !window.getSelection().isCollapsed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-09-17 14:50:49 -07:00
|
|
|
var symbol = target.textContent || target.innerText;
|
|
|
|
|
var query = {
|
|
|
|
|
lang : lang,
|
|
|
|
|
projects : config.projects.join(','),
|
|
|
|
|
jump : true
|
|
|
|
|
};
|
|
|
|
|
if (map[target.className]) {
|
|
|
|
|
query.type = map[target.className];
|
|
|
|
|
}
|
|
|
|
|
if (target.hasAttribute('data-symbol-context')) {
|
|
|
|
|
query.context = target.getAttribute('data-symbol-context');
|
|
|
|
|
}
|
|
|
|
|
if (target.hasAttribute('data-symbol-name')) {
|
|
|
|
|
symbol = target.getAttribute('data-symbol-name');
|
|
|
|
|
}
|
|
|
|
|
var uri = JX.$U('/diffusion/symbol/' + symbol + '/');
|
|
|
|
|
uri.addQueryParams(query);
|
|
|
|
|
window.open(uri);
|
2013-02-21 09:49:06 -08:00
|
|
|
};
|
|
|
|
|
setTimeout(timeout, 250);
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 14:03:26 -07:00
|
|
|
e.kill();
|
|
|
|
|
break;
|
2012-08-09 15:19:02 -07:00
|
|
|
}
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 14:03:26 -07:00
|
|
|
target = target.parentNode;
|
2012-07-31 17:01:57 -07:00
|
|
|
}
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 14:03:26 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function linkAll(section) {
|
2013-05-12 06:52:53 -07:00
|
|
|
var blocks = JX.DOM.scry(document.body, 'div', 'remarkup-code-block');
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 14:03:26 -07:00
|
|
|
for (var i = 0; i < blocks.length; ++i) {
|
|
|
|
|
if (blocks[i].hasAttribute('data-code-lang')) {
|
|
|
|
|
var lang = blocks[i].getAttribute('data-code-lang');
|
|
|
|
|
link(blocks[i], lang);
|
2011-09-06 11:35:14 -07:00
|
|
|
}
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 14:03:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.container) {
|
|
|
|
|
link(JX.$(config.container), config.lang);
|
|
|
|
|
} else if (config.section) {
|
|
|
|
|
linkAll(JX.$(config.section));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
|
'differential-preview-update',
|
|
|
|
|
null,
|
|
|
|
|
function(e) {
|
|
|
|
|
linkAll(e.getData().container);
|
2011-09-06 11:35:14 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|