]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Add target as option
authorTine Jozelj <tine.jozelj@outlook.com>
Thu, 4 Aug 2016 12:58:42 +0000 (14:58 +0200)
committerGitHub <noreply@github.com>
Thu, 4 Aug 2016 12:58:42 +0000 (14:58 +0200)
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

index 04cfe18972a605e7e754fd3a78e553a79c8ce930..1d3ffaf5f1e8a1163748ad0b6af28377f14b5885 100644 (file)
    *                                                                            "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;
 
       var startsWithProtocol = new RegExp('^' + protocolClause),
           urlHasProtocol = url.match(startsWithProtocol),
           href = (urlHasProtocol) ? url : 'http://' + url,
-          link = '<a href="' +  href + '" target="_blank">' + url + '</a>',
+          link = '<a href="' +  href + '" target="' + target + '">' + url + '</a>',
           newHTML = nodeHTML.replace(url, link);
 
       line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
    * @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<rows.length; i++) {
       var line = rows[i];
 
-      exports.linkifyTerminalLine(terminal, line, lenient);
+      exports.linkifyTerminalLine(terminal, line, lenient, target);
     }
 
     /**
    *                                                                            "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'
    */
-  Xterm.prototype.linkifyTerminalLine = function (line, lenient) {
-    return exports.linkifyTerminalLine(this, line, lenient);
+  Xterm.prototype.linkifyTerminalLine = function (line, lenient, target) {
+    return exports.linkifyTerminalLine(this, line, lenient, target);
   };
 
   /**
    * @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'
    */
-  Xterm.prototype.linkify = function (lenient) {
-    return exports.linkify(this, lenient);
+  Xterm.prototype.linkify = function (lenient, target) {
+    return exports.linkify(this, lenient, target);
   };
 
   return exports;