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

72.29% Statements 60/83
40% Branches 8/20
57.14% Functions 12/21
71.95% Lines 59/82

    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    1571×
    1×
    1×
    1×
    1×
    1×
    1×
    2×
    99×
    99×
    99×
    99×
    99×
    99×
    99×

    1×
    99×
    99×

    99×
    99×
    99×

    1×
    2×
    2×

    1×
    4×

    1×
    2×

    1×
    2×
    2×
    2×
    2×
    2×
    2×

    2×
    2×

    2×

    2×
    2×

    2×

    2×

    2×

    2×

    2×
    2×
    2×
    2×

    2×
    2×

    2×

    2×

    1×
    2×
    2×
    2×
    2×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/LinkDialog.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var env_1 = require("../core/env");
    var key_1 = require("../core/key");
    var func_1 = require("../core/func");
    var LinkDialog = /** @class */ (function () {
        function LinkDialog(context) {
            this.context = context;
            this.ui = jquery_1["default"].summernote.ui;
            this.$body = jquery_1["default"](document.body);
            this.$editor = context.layoutInfo.editor;
            this.options = context.options;
            this.lang = this.options.langInfo;
            context.memo('help.linkDialog.show', this.options.langInfo.help['linkDialog.show']);
        }
        LinkDialog.prototype.initialize = function () {
            var $container = this.options.dialogsInBody ? this.$body : this.$editor;
            var body = [
                '<div class="form-group note-form-group">',
                "<label class=\"note-form-label\">" + this.lang.link.textToDisplay + "</label>",
                '<input class="note-link-text form-control note-form-control note-input" type="text" />',
                '</div>',
                '<div class="form-group note-form-group">',
                "<label class=\"note-form-label\">" + this.lang.link.url + "</label>",
                '<input class="note-link-url form-control note-form-control note-input" type="text" value="http://" />',
                '</div>',
                !this.options.disableLinkTarget
                    ? jquery_1["default"]('<div/>').append(this.ui.checkbox({
                        className: 'sn-checkbox-open-in-new-window',
                        text: this.lang.link.openInNewWindow,
                        checked: true
                    }).render()).html()
                    : '',
            ].join('');
            var buttonClass = 'btn btn-primary note-btn note-btn-primary note-link-btn';
            var footer = "<input type=\"button\" href=\"#\" class=\"" + buttonClass + "\" value=\"" + this.lang.link.insert + "\" disabled>";
            this.$dialog = this.ui.dialog({
                className: 'link-dialog',
                title: this.lang.link.insert,
                fade: this.options.dialogsFade,
                body: body,
                footer: footer
            }).render().appendTo($container);
        };
        LinkDialog.prototype.destroy = function () {
            this.ui.hideDialog(this.$dialog);
            this.$dialog.remove();
        };
        LinkDialog.prototype.bindEnterKey = function ($input, $btn) {
            $input.on('keypress', function (event) {
                if (event.keyCode === key_1["default"].code.ENTER) {
                    event.preventDefault();
                    $btn.trigger('click');
                }
            });
        };
        /**
         * toggle update button
         */
        LinkDialog.prototype.toggleLinkBtn = function ($linkBtn, $linkText, $linkUrl) {
            this.ui.toggleBtn($linkBtn, $linkText.val() && $linkUrl.val());
        };
        /**
         * Show link dialog and set event handlers on dialog controls.
         *
         * @param {Object} linkInfo
         * @return {Promise}
         */
        LinkDialog.prototype.showLinkDialog = function (linkInfo) {
            var _this = this;
            return jquery_1["default"].Deferred(function (deferred) {
                var $linkText = _this.$dialog.find('.note-link-text');
                var $linkUrl = _this.$dialog.find('.note-link-url');
                var $linkBtn = _this.$dialog.find('.note-link-btn');
                var $openInNewWindow = _this.$dialog
                    .find('.sn-checkbox-open-in-new-window input[type=checkbox]');
                _this.ui.onDialogShown(_this.$dialog, function () {
                    _this.context.triggerEvent('dialog.shown');
                    // if no url was given and given text is valid URL then copy that into URL Field
                    Iif (!linkInfo.url && func_1["default"].isValidUrl(linkInfo.text)) {
                        linkInfo.url = linkInfo.text;
                    }
                    $linkText.val(linkInfo.text);
                    var handleLinkTextUpdate = function () {
                        _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
                        // if linktext was modified by keyup,
                        // stop cloning text from linkUrl
                        linkInfo.text = $linkText.val();
                    };
                    $linkText.on('input', handleLinkTextUpdate).on('paste', function () {
                        setTimeout(handleLinkTextUpdate, 0);
                    });
                    var handleLinkUrlUpdate = function () {
                        _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
                        // display same link on `Text to display` input
                        // when create a new link
                        if (!linkInfo.text) {
                            $linkText.val($linkUrl.val());
                        }
                    };
                    $linkUrl.on('input', handleLinkUrlUpdate).on('paste', function () {
                        setTimeout(handleLinkUrlUpdate, 0);
                    }).val(linkInfo.url);
                    Iif (!env_1["default"].isSupportTouch) {
                        $linkUrl.trigger('focus');
                    }
                    _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
                    _this.bindEnterKey($linkUrl, $linkBtn);
                    _this.bindEnterKey($linkText, $linkBtn);
                    var isNewWindowChecked = linkInfo.isNewWindow !== undefined
                        ? linkInfo.isNewWindow : _this.context.options.linkTargetBlank;
                    $openInNewWindow.prop('checked', isNewWindowChecked);
                    $linkBtn.one('click', function (event) {
                        event.preventDefault();
                        deferred.resolve({
                            range: linkInfo.range,
                            url: $linkUrl.val(),
                            text: $linkText.val(),
                            isNewWindow: $openInNewWindow.is(':checked')
                        });
                        _this.ui.hideDialog(_this.$dialog);
                    });
                });
                _this.ui.onDialogHidden(_this.$dialog, function () {
                    // detach events
                    $linkText.off('input paste keypress');
                    $linkUrl.off('input paste keypress');
                    $linkBtn.off('click');
                    if (deferred.state() === 'pending') {
                        deferred.reject();
                    }
                });
                _this.ui.showDialog(_this.$dialog);
            }).promise();
        };
        /**
         * @param {Object} layoutInfo
         */
        LinkDialog.prototype.show = function () {
            var _this = this;
            var linkInfo = this.context.invoke('editor.getLinkInfo');
            this.context.invoke('editor.saveRange');
            this.showLinkDialog(linkInfo).then(function (linkInfo) {
                _this.context.invoke('editor.restoreRange');
                _this.context.invoke('editor.createLink', linkInfo);
            }).fail(function () {
                _this.context.invoke('editor.restoreRange');
            });
        };
        return LinkDialog;
    }());
    exports["default"] = LinkDialog;

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