]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Extend Xterm prototype only when `Xterm` is a function
authorParis <paris@sourcelair.com>
Tue, 3 May 2016 09:36:21 +0000 (12:36 +0300)
committerParis <paris@sourcelair.com>
Tue, 3 May 2016 09:36:21 +0000 (12:36 +0300)
Add-ons attempted to extend the `Xterm` prototype no matter what. This was an issue when importing add-ons through CommonJS, where `Xterm` is not available in the global scope.

addons/attach/attach.js
addons/attach/package.json [new file with mode: 0644]
addons/fit/fit.js
addons/fit/package.json [new file with mode: 0644]
addons/fullscreen/fullscreen.js
addons/fullscreen/package.json [new file with mode: 0644]
addons/linkify/linkify.js
addons/linkify/package.json [new file with mode: 0644]

index 2788f8e745662cb79ae2ecb078eb7230d2ed05de..775535cf30ec1003f6a6d2d6985447cf1ee196f9 100644 (file)
  */
 
 (function (attach) {
-    if (typeof exports === 'object' && typeof module === 'object') {
-        /*
-         * CommonJS environment
-         */
-        module.exports = attach.call(this);
-    } else if (typeof define == 'function') {
-        /*
-         * Require.js is available
-         */
-        define(['../../src/xterm'], attach);
-    } else {
-        /*
-         * Plain browser environment
-         */
-        attach(this.Xterm);
-    }
+  if (typeof exports === 'object' && typeof module === 'object') {
+    /*
+     * CommonJS environment
+     */
+    module.exports = attach.call(this);
+  } else if (typeof define == 'function') {
+    /*
+     * Require.js is available
+     */
+    define(['../../src/xterm'], attach);
+  } else {
+    /*
+     * Plain browser environment
+     */
+    attach(this.Xterm);
+  }
 })(function (Xterm) {
-    'use strict';
+  'use strict';
+
+  /**
+   * This module provides methods for attaching a terminal to a WebSocket
+   * stream.
+   *
+   * @module xterm/addons/attach/attach
+   */
+  var exports = {};
+
+  /**
+   * Attaches the given terminal to the given socket.
+   *
+   * @param {Xterm} term - The terminal to be attached to the given socket.
+   * @param {WebSocket} socket - The socket to attach the current terminal.
+   * @param {boolean} bidirectional - Whether the terminal should send data
+   *                                  to the socket as well.
+   * @param {boolean} buffered - Whether the rendering of incoming data
+   *                             should happen instantly or at a maximum
+   *                             frequency of 1 rendering per 10ms.
+   */
+  exports.attach = function (term, socket, bidirectional, buffered) {
+    bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
+    term.socket = socket;
+
+    term._flushBuffer = function () {
+      term.write(term._attachSocketBuffer);
+      term._attachSocketBuffer = null;
+      clearTimeout(term._attachSocketBufferTimer);
+      term._attachSocketBufferTimer = null;
+    };
 
-    /**
-     * This module provides methods for attaching a terminal to a WebSocket
-     * stream.
-     *
-     * @module xterm/addons/attach/attach
-     */
-    var exports = {};
+    term._pushToBuffer = function (data) {
+      if (term._attachSocketBuffer) {
+        term._attachSocketBuffer += data;
+      } else {
+        term._attachSocketBuffer = data;
+        setTimeout(term._flushBuffer, 10);
+      }
+    };
 
-    /**
-     * Attaches the given terminal to the given socket.
-     *
-     * @param {Xterm} term - The terminal to be attached to the given socket.
-     * @param {WebSocket} socket - The socket to attach the current terminal.
-     * @param {boolean} bidirectional - Whether the terminal should send data
-     *                                  to the socket as well.
-     * @param {boolean} buffered - Whether the rendering of incoming data
-     *                             should happen instantly or at a maximum
-     *                             frequency of 1 rendering per 10ms.
-     */
-    exports.attach = function (term, socket, bidirectional, buffered) {
-        bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
-        term.socket = socket;
-
-        term._flushBuffer = function () {
-            term.write(term._attachSocketBuffer);
-            term._attachSocketBuffer = null;
-            clearTimeout(term._attachSocketBufferTimer);
-            term._attachSocketBufferTimer = null;
-        };
-
-        term._pushToBuffer = function (data) {
-            if (term._attachSocketBuffer) {
-                term._attachSocketBuffer += data;
-            } else {
-                term._attachSocketBuffer = data;
-                setTimeout(term._flushBuffer, 10);
-            }
-        };
-
-        term._getMessage = function (ev) {
-            if (buffered) {
-                term._pushToBuffer(ev.data);
-            } else {
-                term.write(ev.data);
-            }
-        };
-
-        term._sendData = function (data) {
-            socket.send(data);
-        };
-
-        socket.addEventListener('message', term._getMessage);
-
-        if (bidirectional) {
-            term.on('data', term._sendData);
-        }
-
-        socket.addEventListener('close', term.detach.bind(term, socket));
-        socket.addEventListener('error', term.detach.bind(term, socket));
+    term._getMessage = function (ev) {
+      if (buffered) {
+        term._pushToBuffer(ev.data);
+      } else {
+        term.write(ev.data);
+      }
     };
 
-    /**
-     * Detaches the given terminal from the given socket
-     *
-     * @param {Xterm} term - The terminal to be detached from the given socket.
-     * @param {WebSocket} socket - The socket from which to detach the current
-     *                             terminal.
-     */
-    exports.detach = function (term, socket) {
-        term.off('data', term._sendData);
+    term._sendData = function (data) {
+      socket.send(data);
+    };
 
-        socket = (typeof socket == 'undefined') ? term.socket : socket;
+    socket.addEventListener('message', term._getMessage);
 
-        if (socket) {
-            socket.removeEventListener('message', term._getMessage);
-        }
+    if (bidirectional) {
+      term.on('data', term._sendData);
+    }
 
-        delete term.socket;
-    };
+    socket.addEventListener('close', term.detach.bind(term, socket));
+    socket.addEventListener('error', term.detach.bind(term, socket));
+  };
+
+  /**
+   * Detaches the given terminal from the given socket
+   *
+   * @param {Xterm} term - The terminal to be detached from the given socket.
+   * @param {WebSocket} socket - The socket from which to detach the current
+   *                             terminal.
+   */
+  exports.detach = function (term, socket) {
+    term.off('data', term._sendData);
+
+    socket = (typeof socket == 'undefined') ? term.socket : socket;
 
+    if (socket) {
+      socket.removeEventListener('message', term._getMessage);
+    }
+
+    delete term.socket;
+  };
+
+  /**
+   * Extends the given terminal prototype with the public methods of this add-on.
+   *
+   * @param {function} Xterm - The prototype to be extended.
+   */
+  exports.extendXtermPrototype = function (Xterm) {
     /**
      * Attaches the current terminal to the given socket
      *
      *                             frequency of 1 rendering per 10ms.
      */
     Xterm.prototype.attach = function (socket, bidirectional, buffered) {
-        return exports.attach(this, socket, bidirectional, buffered);
+      return exports.attach(this, socket, bidirectional, buffered);
     };
 
     /**
      *                             terminal.
      */
     Xterm.prototype.detach = function (socket) {
-        return exports.detach(this, socket);
+      return exports.detach(this, socket);
     };
+  };
+
+  /**
+   * If the Xterm parameter is a function, then extend it with the methods declared in this
+   * add-on.
+   */
+  if (typeof Xterm == 'function') {
+    exports.extendXtermPrototype(Xterm);
+  }
 
-    return exports;
+  return exports;
 });
diff --git a/addons/attach/package.json b/addons/attach/package.json
new file mode 100644 (file)
index 0000000..9e45068
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "name": "xterm.attach",
+  "main": "attach.js",
+  "private": true
+}
index c39b9cf151f40091dc859225f4d840ceef8a0aa4..3bcf09074c97cd3c990f44ee86a5504ac4cb1f6d 100644 (file)
  *               of columns)
  */
 (function (fit) {
-    if (typeof exports === 'object' && typeof module === 'object') {
-        /*
-         * CommonJS environment
-         */
-        module.exports = fit.call(this);
-    } else if (typeof define == 'function') {
-        /*
-         * Require.js is available
-         */
-        define(['../../src/xterm'], fit);
-    } else {
-        /*
-         * Plain browser environment
-         */
-        fit(this.Xterm);
-    }
+  if (typeof exports === 'object' && typeof module === 'object') {
+    /*
+     * CommonJS environment
+     */
+    module.exports = fit.call(this);
+  } else if (typeof define == 'function') {
+    /*
+     * Require.js is available
+     */
+    define(['../../src/xterm'], fit);
+  } else {
+    /*
+     * Plain browser environment
+     */
+    fit(this.Xterm);
+  }
 })(function (Xterm) {
-    Xterm.prototype.proposeGeometry = function () {
-        var parentElementStyle = window.getComputedStyle(this.element.parentElement),
-            parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
-            parentElementWidth = parseInt(parentElementStyle.getPropertyValue('width')),
-            elementStyle = window.getComputedStyle(this.element),
-            elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
-            elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')),
-            availableHeight = parentElementHeight - elementPaddingVer,
-            availableWidth = parentElementWidth - elementPaddingHor,
-            container = this.rowContainer,
-            subjectRow = this.rowContainer.firstElementChild,
-            contentBuffer = subjectRow.innerHTML,
-            characterHeight,
-            rows,
-            characterWidth,
-            cols,
-            geometry;
+  /**
+   * This module provides methods for fitting a terminal's size to a parent container.
+   *
+   * @module xterm/addons/fit/fit
+   */
+  var exports = {};
+
+  exports.proposeGeometry = function (term) {
+    var parentElementStyle = window.getComputedStyle(term.element.parentElement),
+        parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
+        parentElementWidth = parseInt(parentElementStyle.getPropertyValue('width')),
+        elementStyle = window.getComputedStyle(term.element),
+        elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
+        elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')),
+        availableHeight = parentElementHeight - elementPaddingVer,
+        availableWidth = parentElementWidth - elementPaddingHor,
+        container = term.rowContainer,
+        subjectRow = term.rowContainer.firstElementChild,
+        contentBuffer = subjectRow.innerHTML,
+        characterHeight,
+        rows,
+        characterWidth,
+        cols,
+        geometry;
+
+    subjectRow.style.display = 'inline';
+    subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
+    characterWidth = subjectRow.getBoundingClientRect().width;
+    subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
+    characterHeight = parseInt(subjectRow.offsetHeight);
+    subjectRow.innerHTML = contentBuffer;
+
+    rows = parseInt(availableHeight / characterHeight);
+    cols = parseInt(availableWidth / characterWidth) - 1;
+
+    geometry = {cols: cols, rows: rows};
+    return geometry;
+  };
 
-        subjectRow.style.display = 'inline';
-        subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
-        characterWidth = subjectRow.getBoundingClientRect().width;
-        subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
-        characterHeight = parseInt(subjectRow.offsetHeight);
-        subjectRow.innerHTML = contentBuffer;
+  exports.fit = function (term) {
+    var geometry = exports.proposeGeometry(term);
 
-        rows = parseInt(availableHeight / characterHeight);
-        cols = parseInt(availableWidth / characterWidth) - 1;
+    term.resize(geometry.cols, geometry.rows);
+  };
 
-        geometry = {cols: cols, rows: rows};
-        return geometry;
+  /**
+   * Extends the given terminal prototype with the public methods of this add-on.
+   *
+   * @param {function} Xterm - The prototype to be extended.
+   */
+  exports.extendXtermPrototype = function (Xterm) {
+    Xterm.prototype.proposeGeometry = function () {
+      return exports.proposeGeometry(this);
     };
 
     Xterm.prototype.fit = function () {
-        var geometry = this.proposeGeometry();
-
-        this.resize(geometry.cols, geometry.rows);
+      return exports.fit(this);
     };
+  };
+
+  /**
+   * If the Xterm parameter is a function, then extend it with the methods declared in this
+   * add-on.
+   */
+  if (typeof Xterm == 'function') {
+    exports.extendXtermPrototype(Xterm);
+  }
+
+  return exports;
 });
diff --git a/addons/fit/package.json b/addons/fit/package.json
new file mode 100644 (file)
index 0000000..f7cb5bc
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "name": "xterm.fit",
+  "main": "fit.js",
+  "private": true
+}
index 4e3d00283c253708ba411f818a640a2751ca2a65..1d5a568b5a64aa3c38dcfc42e204d155bd177b67 100644 (file)
  * fullscreen mode is being toggled.
  */
 (function (fullscreen) {
-    if (typeof exports === 'object' && typeof module === 'object') {
-        /*
-         * CommonJS environment
-         */
-        module.exports = fullscreen.call(this);
-    } else if (typeof define == 'function') {
-        /*
-         * Require.js is available
-         */
-        define(['../../src/xterm'], fullscreen);
+  if (typeof exports === 'object' && typeof module === 'object') {
+    /*
+     * CommonJS environment
+     */
+    module.exports = fullscreen.call(this);
+  } else if (typeof define == 'function') {
+    /*
+     * Require.js is available
+     */
+    define(['../../src/xterm'], fullscreen);
+  } else {
+    /*
+     * Plain browser environment
+     */
+    fullscreen(this.Xterm);
+  }
+})(function (Xterm) {
+  var exports = {};
+
+  exports.toggleFullScreen = function (term, fullscreen) {
+    var fn;
+
+    if (typeof fullscreen == 'undefined') {
+      fn = (term.element.classList.contains('fullscreen')) ? 'remove' : 'add';
+    } else if (!fullscreen) {
+      fn = 'remove';
     } else {
-        /*
-         * Plain browser environment
-         */
-        fullscreen(this.Xterm);
+      fn = 'add';
     }
-})(function (Xterm) {
-    Xterm.prototype.toggleFullscreen = function (fullscreen) {
-      var fn;
 
-      if (typeof fullscreen == 'undefined') {
-        fn = (this.element.classList.contains('fullscreen')) ? 'remove' : 'add';
-      } else if (!fullscreen) {
-        fn = 'remove';
-      } else {
-        fn = 'add';
-      }
+    term.element.classList[fn]('fullscreen');
+  };
 
-      this.element.classList[fn]('fullscreen');
+  /**
+   * Extends the given terminal prototype with the public methods of this add-on.
+   *
+   * @param {function} Xterm - The prototype to be extended.
+   */
+  exports.extendXtermPrototype = function (Xterm) {
+    Xterm.prototype.toggleFullscreen = function (fullscreen) {
+      exports.toggleFullScreen(this, fullscreen);
     };
+  };
+
+  /**
+   * If the Xterm parameter is a function, then extend it with the methods declared in this
+   * add-on.
+   */
+  if (typeof Xterm == 'function') {
+    exports.extendXtermPrototype(Xterm);
+  }
+
+  return exports;
 });
diff --git a/addons/fullscreen/package.json b/addons/fullscreen/package.json
new file mode 100644 (file)
index 0000000..fdaf688
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "name": "xterm.fullscreen",
+  "main": "fullscreen.js",
+  "private": true
+}
index ab3c041a9b839e39ceaea901cc1f993615b99255..86849409a734b5d701954ae03a9b72e087850470 100644 (file)
 (function (linkify) {
-    if (typeof exports === 'object' && typeof module === 'object') {
-        /*
-         * CommonJS environment
-         */
-        module.exports = linkify.call(this);
-    } else if (typeof define == 'function') {
-        /*
-         * Require.js is available
-         */
-        define(['../../src/xterm'], linkify);
-    } else {
-        /*
+  if (typeof exports === 'object' && typeof module === 'object') {
+    /*
+     * CommonJS environment
+     */
+    module.exports = linkify.call(this);
+  } else if (typeof define == 'function') {
+    /*
+     * Require.js is available
+     */
+    define(['../../src/xterm'], linkify);
+  } else {
+    /*
          * Plain browser environment
          */
-        linkify(this.Xterm);
-    }
+    linkify(this.Xterm);
+  }
 })(function (Xterm) {
-       'use strict';
-
-    /**
-     * This module provides methods for convertings valid URL substrings
-     * into HTML anchor elements (links), inside a terminal view.
-     *
-     * @module xterm/addons/linkify/linkify
-     */
-    var exports = {},
-        protocolClause = '(https?:\\/\\/)',
-        domainCharacterSet = '[\\da-z\\.-]+',
-        negatedDomainCharacterSet = '[^\\da-z\\.-]+',
-        domainBodyClause = '(' + domainCharacterSet + ')',
-        tldClause = '([a-z\\.]{2,6})',
-        hostClause = domainBodyClause + '\\.' + tldClause,
-        pathClause = '([\\/\\w\\.-]*)*\\/?',
-        negatedPathCharacterSet = '[^\\/\\w\\.-]+',
-        bodyClause = hostClause + pathClause,
-        start = '(?:^|' + negatedDomainCharacterSet + ')(',
-        end = ')($|' + negatedPathCharacterSet + ')',
-        lenientUrlClause = start + protocolClause + '?' + bodyClause + end,
-        strictUrlClause = start + protocolClause + bodyClause + end,
-        lenientUrlRegex = new RegExp(lenientUrlClause),
-        strictUrlRegex = new RegExp(strictUrlClause);
+  'use strict';
+
+  /**
+   * This module provides methods for convertings valid URL substrings
+   * into HTML anchor elements (links), inside a terminal view.
+   *
+   * @module xterm/addons/linkify/linkify
+   */
+  var exports = {},
+      protocolClause = '(https?:\\/\\/)',
+      domainCharacterSet = '[\\da-z\\.-]+',
+      negatedDomainCharacterSet = '[^\\da-z\\.-]+',
+      domainBodyClause = '(' + domainCharacterSet + ')',
+      tldClause = '([a-z\\.]{2,6})',
+      hostClause = domainBodyClause + '\\.' + tldClause,
+      pathClause = '([\\/\\w\\.-]*)*\\/?',
+      negatedPathCharacterSet = '[^\\/\\w\\.-]+',
+      bodyClause = hostClause + pathClause,
+      start = '(?:^|' + negatedDomainCharacterSet + ')(',
+      end = ')($|' + negatedPathCharacterSet + ')',
+      lenientUrlClause = start + protocolClause + '?' + bodyClause + end,
+      strictUrlClause = start + protocolClause + bodyClause + end,
+      lenientUrlRegex = new RegExp(lenientUrlClause),
+      strictUrlRegex = new RegExp(strictUrlClause);
+
+
+  /**
+   * Converts all valid URLs found in the given terminal line into
+   * hyperlinks. The terminal line can be either the HTML element itself
+   * or the index of the termina line in the children of the terminal
+   * rows container.
+   *
+   * @param {Xterm} terminal - The terminal that owns the given line.
+   * @param {number|HTMLDivElement} line - The terminal line 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.
+   * @emits linkify
+   * @emits linkify:line
+   */
+  exports.linkifyTerminalLine = function (terminal, line, lenient) {
+    if (typeof line == 'number') {
+      line = terminal.rowContainer.children[line];
+    } else if (! (line instanceof HTMLDivElement)) {
+      var message = 'The "line" argument should be either a number';
+      message += ' or an HTMLDivElement';
+
+      throw new TypeError(message);
+    }
 
+    var buffer = document.createElement('span'),
+        nodes = line.childNodes;
+
+    for (var j=0; j<nodes.length; j++) {
+      var node = nodes[j],
+          match;
+
+      /**
+       * Since we cannot access the TextNode's HTML representation
+       * from the instance itself, we assign its data as textContent
+       * to a dummy buffer span, in order to retrieve the TextNode's
+       * HTML representation from the buffer's innerHTML.
+       */
+      buffer.textContent = node.data;
+
+      var nodeHTML = buffer.innerHTML;
+
+      /**
+       * Apply function only on TextNodes
+       */
+      if (node.nodeType != node.TEXT_NODE) {
+        continue;
+      }
+
+
+      if (lenient) {
+        match = node.data.match(lenientUrlRegex);
+      } else {
+        match = node.data.match(strictUrlRegex);
+      }
+
+      /**
+       * If no URL was found in the current text, return.
+       */
+      if (!match) {
+        continue;
+      }
+
+      var url = match[1],
+          startsWithProtocol = new RegExp('^' + protocolClause),
+          urlHasProtocol = url.match(startsWithProtocol),
+          href = (urlHasProtocol) ? url : 'http://' + url,
+          link = '<a href="' +  href + '" >' + url + '</a>',
+          newHTML = nodeHTML.replace(url, link);
+
+      line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
+    }
 
     /**
-     * Converts all valid URLs found in the given terminal line into
-     * hyperlinks. The terminal line can be either the HTML element itself
-     * or the index of the termina line in the children of the terminal
-     * rows container.
+     * This event gets emitted when conversion of all URL susbtrings
+     * to HTML anchor elements (links) has finished, for a specific
+     * line of the current Xterm instance.
      *
-     * @param {Xterm} terminal - The terminal that owns the given line.
-     * @param {number|HTMLDivElement} line - The terminal line 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.
-     * @emits linkify
-     * @emits linkify:line
+     * @event linkify:line
      */
-    exports.linkifyTerminalLine = function (terminal, line, lenient) {
-        if (typeof line == 'number') {
-            line = terminal.rowContainer.children[line];
-        } else if (! (line instanceof HTMLDivElement)) {
-            var message = 'The "line" argument should be either a number';
-            message += ' or an HTMLDivElement';
-
-            throw new TypeError(message);
-        }
-
-        var buffer = document.createElement('span'),
-            nodes = line.childNodes;
-
-        for (var j=0; j<nodes.length; j++) {
-            var node = nodes[j],
-                match;
-
-            /*
-             * Since we cannot access the TextNode's HTML representation
-             * from the instance itself, we assign its data as textContent
-             * to a dummy buffer span, in order to retrieve the TextNode's
-             * HTML representation from the buffer's innerHTML.
-             */
-            buffer.textContent = node.data;
-
-            var nodeHTML = buffer.innerHTML;
-
-            /*
-             * Apply function only on TextNodes
-             */
-            if (node.nodeType != node.TEXT_NODE) {
-                continue;
-            }
-
-
-            if (lenient) {
-                match = node.data.match(lenientUrlRegex);
-            } else {
-                match = node.data.match(strictUrlRegex);
-            }
-
-            /*
-             * If no URL was found in the current text, return.
-             */
-            if (!match) {
-                continue;
-            }
-
-            var url = match[1],
-                startsWithProtocol = new RegExp('^' + protocolClause),
-                urlHasProtocol = url.match(startsWithProtocol),
-                href = (urlHasProtocol) ? url : 'http://' + url,
-                link = '<a href="' +  href + '" >' + url + '</a>',
-                newHTML = nodeHTML.replace(url, link);
-
-            line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
-        }
-
-        /**
-         * This event gets emitted when conversion of all URL susbtrings
-         * to HTML anchor elements (links) has finished, for a specific
-         * line of the current Xterm instance.
-         *
-         * @event linkify:line
-         */
-        terminal.emit('linkify:line', line);
-    };
-
+    terminal.emit('linkify:line', line);
+  };
+
+
+  /**
+   * Converts all valid URLs found in the terminal view into hyperlinks.
+   *
+   * @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.
+   * @emits linkify
+   * @emits linkify:line
+   */
+  exports.linkify = function (terminal, lenient) {
+    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);
+    }
 
     /**
-     * Converts all valid URLs found in the terminal view into hyperlinks.
+     * This event gets emitted when conversion of  all URL substrings to
+     * HTML anchor elements (links) has finished for the current Xterm
+     * instance's view.
      *
-     * @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.
-     * @emits linkify
-     * @emits linkify:line
-     */
-    exports.linkify = function (terminal, lenient) {
-        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);
-        }
-
-        /**
-         * This event gets emitted when conversion of  all URL substrings to
-         * HTML anchor elements (links) has finished for the current Xterm
-         * instance's view.
-         *
-         * @event linkify
-         */
-        terminal.emit('linkify');
-    };
-
-    /*
-     * Extend Xterm prototype.
+     * @event linkify
      */
-
-   /**
+    terminal.emit('linkify');
+  };
+
+  /**
+   * Extend Xterm prototype.
+   */
+
+  /**
+   * Extends the given terminal prototype with the public methods of this add-on.
+   *
+   * @param {function} Xterm - The prototype to be extended.
+   */
+  exports.extendXtermPrototype = function (Xterm) {
+    /**
      * Converts all valid URLs found in the current terminal linte into
      * hyperlinks.
      *
      *                            false, the regex requires a protocol clause. Defaults to true.
      */
     Xterm.prototype.linkifyTerminalLine = function (line, lenient) {
-        return exports.linkifyTerminalLine(this, line, lenient);
+      return exports.linkifyTerminalLine(this, line, lenient);
     };
 
-   /**
+    /**
      * Converts all valid URLs found in the current terminal into hyperlinks.
      *
      * @memberof Xterm
      *                            false, the regex requires a protocol clause. Defaults to true.
      */
     Xterm.prototype.linkify = function (lenient) {
-        return exports.linkify(this, lenient);
+      return exports.linkify(this, lenient);
     };
+  };
+
+  /**
+   * If the Xterm parameter is a function, then extend it with the methods declared in this
+   * add-on.
+   */
+  if (typeof Xterm == 'function') {
+    exports.extendXtermPrototype(Xterm);
+  }
 
-    return exports;
+  return exports;
 });
diff --git a/addons/linkify/package.json b/addons/linkify/package.json
new file mode 100644 (file)
index 0000000..53dbba4
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "name": "xterm.linkify",
+  "main": "linkify.js",
+  "private": true
+}