From 3113cdf0ea50bc38883fd315acd65670183b2f03 Mon Sep 17 00:00:00 2001 From: Tine Jozelj Date: Tue, 2 Aug 2016 15:57:15 +0200 Subject: [PATCH 1/4] Make linkify links open in new tab/window I believe this behavior is more appropriate. --- addons/linkify/linkify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index f02c202..04cfe18 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -100,7 +100,7 @@ var startsWithProtocol = new RegExp('^' + protocolClause), urlHasProtocol = url.match(startsWithProtocol), href = (urlHasProtocol) ? url : 'http://' + url, - link = '' + url + '', + link = '' + url + '', newHTML = nodeHTML.replace(url, link); line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML); From d9294779a6f647a2ac33b5d4c16756b501c95b4d Mon Sep 17 00:00:00 2001 From: Tine Jozelj Date: Thu, 4 Aug 2016 14:58:42 +0200 Subject: [PATCH 2/4] Add target as option You can now provide target argument if you want to modify target attribute on links. It defaults to `_self` to keep current behavior. --- addons/linkify/linkify.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 04cfe18..1d3ffaf 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -54,10 +54,11 @@ * "linkified". * @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. + * @param {string} target - Sets target="" attribute with value provided to links. Defaults to '_self' * @emits linkify * @emits linkify:line */ - exports.linkifyTerminalLine = function (terminal, line, lenient) { + exports.linkifyTerminalLine = function (terminal, line, lenient, target) { if (typeof line == 'number') { line = terminal.rowContainer.children[line]; } else if (! (line instanceof HTMLDivElement)) { @@ -67,6 +68,8 @@ throw new TypeError(message); } + if (typeof target === 'undefined') target = '_self'; + var buffer = document.createElement('span'), nodes = line.childNodes; @@ -100,7 +103,7 @@ var startsWithProtocol = new RegExp('^' + protocolClause), urlHasProtocol = url.match(startsWithProtocol), href = (urlHasProtocol) ? url : 'http://' + url, - link = '' + url + '', + link = '' + url + '', newHTML = nodeHTML.replace(url, link); line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML); @@ -137,17 +140,18 @@ * @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 * false, the regex requires a protocol clause. Defaults to true. + * @param {string} target - Sets target="" attribute with value provided to links. Defaults to '_self' * @emits linkify * @emits linkify:line */ - exports.linkify = function (terminal, lenient) { + exports.linkify = function (terminal, lenient, target) { var rows = terminal.rowContainer.children; lenient = (typeof lenient == "boolean") ? lenient : true; for (var i=0; i Date: Thu, 4 Aug 2016 15:05:09 +0200 Subject: [PATCH 3/4] Default without target atribute --- addons/linkify/linkify.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 1d3ffaf..dbb9b09 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -54,7 +54,8 @@ * "linkified". * @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. - * @param {string} target - Sets target="" attribute with value provided to links. Defaults to '_self' + * @param {string} target - Sets target="" attribute with value provided to links. + * Default doesn't set target attribute * @emits linkify * @emits linkify:line */ @@ -68,7 +69,7 @@ throw new TypeError(message); } - if (typeof target === 'undefined') target = '_self'; + typeof target === 'undefined' ? target = '' : target = 'target="' + target + '"'; var buffer = document.createElement('span'), nodes = line.childNodes; @@ -103,7 +104,7 @@ var startsWithProtocol = new RegExp('^' + protocolClause), urlHasProtocol = url.match(startsWithProtocol), href = (urlHasProtocol) ? url : 'http://' + url, - link = '' + url + '', + link = '' + url + '', newHTML = nodeHTML.replace(url, link); line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML); @@ -140,7 +141,8 @@ * @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 * false, the regex requires a protocol clause. Defaults to true. - * @param {string} target - Sets target="" attribute with value provided to links. Defaults to '_self' + * @param {string} target - Sets target="" attribute with value provided to links. + * Default doesn't set target attribute * @emits linkify * @emits linkify:line */ @@ -177,7 +179,8 @@ * "linkified". * @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. - * @param {string} target - Sets target="" attribute with value provided to links. Defaults to '_self' + * @param {string} target - Sets target="" attribute with value provided to links. + * Default doesn't set target attribute */ Xterm.prototype.linkifyTerminalLine = function (line, lenient, target) { return exports.linkifyTerminalLine(this, line, lenient, target); @@ -189,7 +192,8 @@ * @memberof Xterm * @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. - * @param {string} target - Sets target="" attribute with value provided to links. Defaults to '_self' + * @param {string} target - Sets target="" attribute with value provided to links. + * Default doesn't set target attribute */ Xterm.prototype.linkify = function (lenient, target) { return exports.linkify(this, lenient, target); From 64d77d24914747bef95759af94c8bb1f6076ebb4 Mon Sep 17 00:00:00 2001 From: Tine Jozelj Date: Thu, 4 Aug 2016 15:22:45 +0200 Subject: [PATCH 4/4] Making it more human readable --- addons/linkify/linkify.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index dbb9b09..4fc0b95 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -69,7 +69,11 @@ throw new TypeError(message); } - typeof target === 'undefined' ? target = '' : target = 'target="' + target + '"'; + if (typeof target === 'undefined') { + target = ''; + } else { + target = 'target="' + target + '"'; + } var buffer = document.createElement('span'), nodes = line.childNodes;