Merge pull request #214 from mentos1386/mentos1386-linkify
Make linkify links open in new tab/window
This commit is contained in:
@@ -54,10 +54,12 @@
|
|||||||
* "linkified".
|
* "linkified".
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
* @param {string} target - Sets target="" attribute with value provided to links.
|
||||||
|
* Default doesn't set target attribute
|
||||||
* @emits linkify
|
* @emits linkify
|
||||||
* @emits linkify:line
|
* @emits linkify:line
|
||||||
*/
|
*/
|
||||||
exports.linkifyTerminalLine = function (terminal, line, lenient) {
|
exports.linkifyTerminalLine = function (terminal, line, lenient, target) {
|
||||||
if (typeof line == 'number') {
|
if (typeof line == 'number') {
|
||||||
line = terminal.rowContainer.children[line];
|
line = terminal.rowContainer.children[line];
|
||||||
} else if (! (line instanceof HTMLDivElement)) {
|
} else if (! (line instanceof HTMLDivElement)) {
|
||||||
@@ -67,6 +69,12 @@
|
|||||||
throw new TypeError(message);
|
throw new TypeError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof target === 'undefined') {
|
||||||
|
target = '';
|
||||||
|
} else {
|
||||||
|
target = 'target="' + target + '"';
|
||||||
|
}
|
||||||
|
|
||||||
var buffer = document.createElement('span'),
|
var buffer = document.createElement('span'),
|
||||||
nodes = line.childNodes;
|
nodes = line.childNodes;
|
||||||
|
|
||||||
@@ -100,7 +108,7 @@
|
|||||||
var startsWithProtocol = new RegExp('^' + protocolClause),
|
var startsWithProtocol = new RegExp('^' + protocolClause),
|
||||||
urlHasProtocol = url.match(startsWithProtocol),
|
urlHasProtocol = url.match(startsWithProtocol),
|
||||||
href = (urlHasProtocol) ? url : 'http://' + url,
|
href = (urlHasProtocol) ? url : 'http://' + url,
|
||||||
link = '<a href="' + href + '" >' + url + '</a>',
|
link = '<a href="' + href + '" ' + target + '>' + url + '</a>',
|
||||||
newHTML = nodeHTML.replace(url, link);
|
newHTML = nodeHTML.replace(url, link);
|
||||||
|
|
||||||
line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
|
line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
|
||||||
@@ -137,17 +145,19 @@
|
|||||||
* @param {Xterm} terminal - The terminal that should get "linkified".
|
* @param {Xterm} terminal - The terminal that should get "linkified".
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
* @param {string} target - Sets target="" attribute with value provided to links.
|
||||||
|
* Default doesn't set target attribute
|
||||||
* @emits linkify
|
* @emits linkify
|
||||||
* @emits linkify:line
|
* @emits linkify:line
|
||||||
*/
|
*/
|
||||||
exports.linkify = function (terminal, lenient) {
|
exports.linkify = function (terminal, lenient, target) {
|
||||||
var rows = terminal.rowContainer.children;
|
var rows = terminal.rowContainer.children;
|
||||||
|
|
||||||
lenient = (typeof lenient == "boolean") ? lenient : true;
|
lenient = (typeof lenient == "boolean") ? lenient : true;
|
||||||
for (var i=0; i<rows.length; i++) {
|
for (var i=0; i<rows.length; i++) {
|
||||||
var line = rows[i];
|
var line = rows[i];
|
||||||
|
|
||||||
exports.linkifyTerminalLine(terminal, line, lenient);
|
exports.linkifyTerminalLine(terminal, line, lenient, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,9 +183,11 @@
|
|||||||
* "linkified".
|
* "linkified".
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
* @param {string} target - Sets target="" attribute with value provided to links.
|
||||||
|
* Default doesn't set target attribute
|
||||||
*/
|
*/
|
||||||
Xterm.prototype.linkifyTerminalLine = function (line, lenient) {
|
Xterm.prototype.linkifyTerminalLine = function (line, lenient, target) {
|
||||||
return exports.linkifyTerminalLine(this, line, lenient);
|
return exports.linkifyTerminalLine(this, line, lenient, target);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,9 +196,11 @@
|
|||||||
* @memberof Xterm
|
* @memberof Xterm
|
||||||
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
|
||||||
* false, the regex requires a protocol clause. Defaults to true.
|
* false, the regex requires a protocol clause. Defaults to true.
|
||||||
|
* @param {string} target - Sets target="" attribute with value provided to links.
|
||||||
|
* Default doesn't set target attribute
|
||||||
*/
|
*/
|
||||||
Xterm.prototype.linkify = function (lenient) {
|
Xterm.prototype.linkify = function (lenient, target) {
|
||||||
return exports.linkify(this, lenient);
|
return exports.linkify(this, lenient, target);
|
||||||
};
|
};
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
|
|||||||
Reference in New Issue
Block a user