# all files / src/js/base/module/ AutoLink.js

64.29% Statements 27/42
17.65% Branches 3/17
90.91% Functions 10/11
63.41% Lines 26/41

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    631×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    2×
    97×
    97×
    97×

    1×
    1×

    1×

    1×
    97×

    1×
    2×

    1×

    1×
    1×

    1×
    1×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/AutoLink.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var lists_1 = require("../core/lists");
    var key_1 = require("../core/key");
    var defaultScheme = 'http://';
    var linkPattern = /^([A-Za-z][A-Za-z0-9+-.]*\:[\/]{2}|mailto:[A-Z0-9._%+-]+@)?(www\.)?(.+)$/i;
    var AutoLink = /** @class */ (function () {
        function AutoLink(context) {
            var _this = this;
            this.context = context;
            this.events = {
                'summernote.keyup': function (we, e) {
                    Eif (!e.isDefaultPrevented()) {
                        _this.handleKeyup(e);
                    }
                },
                'summernote.keydown': function (we, e) {
                    _this.handleKeydown(e);
                }
            };
        }
        AutoLink.prototype.initialize = function () {
            this.lastWordRange = null;
        };
        AutoLink.prototype.destroy = function () {
            this.lastWordRange = null;
        };
        AutoLink.prototype.replace = function () {
            if (!this.lastWordRange) {
                return;
            }
            var keyword = this.lastWordRange.toString();
            var match = keyword.match(linkPattern);
            if (match && (match[1] || match[2])) {
                var link = match[1] ? keyword : defaultScheme + keyword;
                var node = jquery_1["default"]('<a />').html(keyword).attr('href', link)[0];
                if (this.context.options.linkTargetBlank) {
                    jquery_1["default"](node).attr('target', '_blank');
                }
                this.lastWordRange.insertNode(node);
                this.lastWordRange = null;
                this.context.invoke('editor.focus');
            }
        };
        AutoLink.prototype.handleKeydown = function (e) {
            Iif (lists_1["default"].contains([key_1["default"].code.ENTER, key_1["default"].code.SPACE], e.keyCode)) {
                var wordRange = this.context.invoke('editor.createRange').getWordRange();
                this.lastWordRange = wordRange;
            }
        };
        AutoLink.prototype.handleKeyup = function (e) {
            Iif (lists_1["default"].contains([key_1["default"].code.ENTER, key_1["default"].code.SPACE], e.keyCode)) {
                this.replace();
            }
        };
        return AutoLink;
    }());
    exports["default"] = AutoLink;

    },'src/js/base/module/AutoLink.js',{"jquery":"/Users/lqez/Dev/summernote/node_modules/jquery/dist/jquery.js","../core/lists":"/Users/lqez/Dev/summernote/src/js/base/core/lists.js","../core/key":"/Users/lqez/Dev/summernote/src/js/base/core/key.js"}];})(this);
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,