Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/core/behavior-line-linker.js
/** | /** | ||||
* @provides javelin-behavior-phabricator-line-linker | * @provides javelin-behavior-phabricator-line-linker | ||||
* @requires javelin-behavior | * @requires javelin-behavior | ||||
* javelin-stratcom | * javelin-stratcom | ||||
* javelin-dom | * javelin-dom | ||||
* javelin-history | * javelin-history | ||||
* javelin-external-editor-link-engine | |||||
*/ | */ | ||||
JX.behavior('phabricator-line-linker', function() { | JX.behavior('phabricator-line-linker', function() { | ||||
var origin = null; | var origin = null; | ||||
var target = null; | var target = null; | ||||
var root = null; | var root = null; | ||||
var highlighted = null; | var highlighted = null; | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | function(e) { | ||||
path = uri.getPath(); | path = uri.getPath(); | ||||
path = path + '$' + lines; | path = path + '$' + lines; | ||||
uri = uri.setPath(path).toString(); | uri = uri.setPath(path).toString(); | ||||
JX.History.replace(uri); | JX.History.replace(uri); | ||||
if (editor_link) { | if (editor_link) { | ||||
var data = JX.Stratcom.getData(editor_link); | var data = JX.Stratcom.getData(editor_link); | ||||
var template = data.template; | |||||
var variables = { | var variables = { | ||||
l: parseInt(Math.min(o, t), 10), | l: parseInt(Math.min(o, t), 10), | ||||
}; | }; | ||||
var parts = []; | var template = data.template; | ||||
for (var ii = 0; ii < template.length; ii++) { | |||||
var part = template[ii]; | |||||
var value = part.value; | |||||
if (part.type === 'literal') { | |||||
parts.push(value); | |||||
continue; | |||||
} | |||||
if (part.type === 'variable') { | var editor_uri = new JX.ExternalEditorLinkEngine() | ||||
if (variables.hasOwnProperty(value)) { | .setTemplate(template) | ||||
var replacement = variables[value]; | .setVariables(variables) | ||||
replacement = encodeURIComponent(replacement); | .newURI(); | ||||
parts.push(replacement); | |||||
} | |||||
} | |||||
} | |||||
editor_link.href = parts.join(''); | editor_link.href = editor_uri; | ||||
} | } | ||||
}); | }); | ||||
// Try to jump to the highlighted lines if we don't have an explicit anchor | // Try to jump to the highlighted lines if we don't have an explicit anchor | ||||
// in the URI. | // in the URI. | ||||
if (!window.location.hash.length) { | if (!window.location.hash.length) { | ||||
try { | try { | ||||
Show All 20 Lines |