Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/repository/repository-crossreference.js
Show All 22 Lines | JX.behavior('repository-crossreference', function(config, statics) { | ||||
var classMouseCursor = 'crossreference-cursor'; | var classMouseCursor = 'crossreference-cursor'; | ||||
// TODO maybe move the dictionary part of this list to the server? | // TODO maybe move the dictionary part of this list to the server? | ||||
var class_map = { | var class_map = { | ||||
nc : 'class', | nc : 'class', | ||||
nf : 'function', | nf : 'function', | ||||
na : null, | na : null, | ||||
nb : 'builtin', | nb : 'builtin', | ||||
n : null, | n : null | ||||
}; | }; | ||||
function link(element, lang) { | function link(element, lang) { | ||||
JX.DOM.alterClass(element, 'repository-crossreference', true); | JX.DOM.alterClass(element, 'repository-crossreference', true); | ||||
linked.push(element); | linked.push(element); | ||||
JX.DOM.listen( | JX.DOM.listen( | ||||
element, | element, | ||||
['mouseover', 'mouseout', 'click'], | ['mouseover', 'mouseout', 'click'], | ||||
'tag:span', | 'tag:span', | ||||
Show All 12 Lines | JX.DOM.listen( | ||||
// If we're in an inline comment, don't link symbols. | // If we're in an inline comment, don't link symbols. | ||||
if (JX.DOM.findAbove(target, 'div', 'differential-inline-comment')) { | if (JX.DOM.findAbove(target, 'div', 'differential-inline-comment')) { | ||||
return; | return; | ||||
} | } | ||||
} catch (ex) { | } catch (ex) { | ||||
// Continue if we're not inside an inline comment. | // Continue if we're not inside an inline comment. | ||||
} | } | ||||
// If only part of the symbol was edited, the symbol name itself will | |||||
// have another "<span />" inside of it which highlights only the | |||||
// edited part. Skip over it. | |||||
if (JX.DOM.isNode(target, 'span') && (target.className === 'bright')) { | |||||
target = target.parentNode; | |||||
} | |||||
if (e.getType() === 'mouseover') { | if (e.getType() === 'mouseover') { | ||||
while (target !== document.body) { | while (target && target !== document.body) { | ||||
if (JX.DOM.isNode(target, 'span') && | if (JX.DOM.isNode(target, 'span') && | ||||
(target.className in class_map)) { | (target.className in class_map)) { | ||||
highlighted = target; | highlighted = target; | ||||
JX.DOM.alterClass(highlighted, classHighlight, true); | JX.DOM.alterClass(highlighted, classHighlight, true); | ||||
break; | break; | ||||
} | } | ||||
target = target.parentNode; | target = target.parentNode; | ||||
} | } | ||||
Show All 31 Lines | if (line !== null) { | ||||
query.line = line; | query.line = line; | ||||
} | } | ||||
var path = getPath(target); | var path = getPath(target); | ||||
if (path !== null) { | if (path !== null) { | ||||
query.path = path; | query.path = path; | ||||
} | } | ||||
var char = getChar(target); | |||||
if (char !== null) { | |||||
query.char = char; | |||||
} | |||||
var uri = JX.$U('/diffusion/symbol/' + symbol + '/'); | var uri = JX.$U('/diffusion/symbol/' + symbol + '/'); | ||||
uri.addQueryParams(query); | uri.addQueryParams(query); | ||||
window.open(uri); | window.open(uri); | ||||
} | } | ||||
function linkAll() { | function linkAll() { | ||||
var blocks = JX.DOM.scry(document.body, 'div', 'remarkup-code-block'); | var blocks = JX.DOM.scry(document.body, 'div', 'remarkup-code-block'); | ||||
for (var i = 0; i < blocks.length; ++i) { | for (var i = 0; i < blocks.length; ++i) { | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | function getPath(target) { | ||||
if (!changeset) { | if (!changeset) { | ||||
return null; | return null; | ||||
} | } | ||||
return JX.Stratcom.getData(changeset).path; | return JX.Stratcom.getData(changeset).path; | ||||
} | } | ||||
function getChar(target) { | |||||
var cell = JX.DOM.findAbove(target, 'td'); | |||||
if (!cell) { | |||||
return null; | |||||
} | |||||
var char = 1; | |||||
for (var ii = 0; ii < cell.childNodes.length; ii++) { | |||||
var node = cell.childNodes[ii]; | |||||
if (node === target) { | |||||
return char; | |||||
} | |||||
var content = '' + node.textContent; | |||||
// Strip off any ZWS characters. These are marker characters used to | |||||
// improve copy/paste behavior. | |||||
content = content.replace(/\u200B/g, ''); | |||||
char += content.length; | |||||
} | |||||
return null; | |||||
} | |||||
if (config.container) { | if (config.container) { | ||||
link(JX.$(config.container), config.lang); | link(JX.$(config.container), config.lang); | ||||
} else if (config.section) { | } else if (config.section) { | ||||
linkAll(JX.$(config.section)); | linkAll(JX.$(config.section)); | ||||
} | } | ||||
JX.Stratcom.listen( | JX.Stratcom.listen( | ||||
'differential-preview-update', | 'differential-preview-update', | ||||
Show All 38 Lines |