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

41.82% Statements 23/55
8.33% Branches 2/24
38.46% Functions 5/13
40.74% Lines 22/54

    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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    831×
    1×
    1×
    1×
    1×
    1×
    2×
    97×
    97×
    97×
    97×
    97×
    97×

    1×
    99×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/AutoReplace.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var lists_1 = require("../core/lists");
    var dom_1 = require("../core/dom");
    var key_1 = require("../core/key");
    var AutoReplace = /** @class */ (function () {
        function AutoReplace(context) {
            var _this = this;
            this.context = context;
            this.options = context.options.replace || {};
            this.keys = [key_1["default"].code.ENTER, key_1["default"].code.SPACE, key_1["default"].code.PERIOD, key_1["default"].code.COMMA, key_1["default"].code.SEMICOLON, key_1["default"].code.SLASH];
            this.previousKeydownCode = null;
            this.events = {
                'summernote.keyup': function (we, e) {
                    if (!e.isDefaultPrevented()) {
                        _this.handleKeyup(e);
                    }
                },
                'summernote.keydown': function (we, e) {
                    _this.handleKeydown(e);
                }
            };
        }
        AutoReplace.prototype.shouldInitialize = function () {
            return !!this.options.match;
        };
        AutoReplace.prototype.initialize = function () {
            this.lastWord = null;
        };
        AutoReplace.prototype.destroy = function () {
            this.lastWord = null;
        };
        AutoReplace.prototype.replace = function () {
            if (!this.lastWord) {
                return;
            }
            var self = this;
            var keyword = this.lastWord.toString();
            this.options.match(keyword, function (match) {
                if (match) {
                    var node = '';
                    if (typeof match === 'string') {
                        node = dom_1["default"].createText(match);
                    }
                    else if (match instanceof jQuery) {
                        node = match[0];
                    }
                    else if (match instanceof Node) {
                        node = match;
                    }
                    if (!node)
                        return;
                    self.lastWord.insertNode(node);
                    self.lastWord = null;
                    self.context.invoke('editor.focus');
                }
            });
        };
        AutoReplace.prototype.handleKeydown = function (e) {
            // this forces it to remember the last whole word, even if multiple termination keys are pressed
            // before the previous key is let go.
            if (this.previousKeydownCode && lists_1["default"].contains(this.keys, this.previousKeydownCode)) {
                this.previousKeydownCode = e.keyCode;
                return;
            }
            if (lists_1["default"].contains(this.keys, e.keyCode)) {
                var wordRange = this.context.invoke('editor.createRange').getWordRange();
                this.lastWord = wordRange;
            }
            this.previousKeydownCode = e.keyCode;
        };
        AutoReplace.prototype.handleKeyup = function (e) {
            if (lists_1["default"].contains(this.keys, e.keyCode)) {
                this.replace();
            }
        };
        return AutoReplace;
    }());
    exports["default"] = AutoReplace;

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