Code coverage report for src/js/base/module/Codeview.js

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

72.09% Statements 62/86
59.38% Branches 19/32
66.67% Functions 12/18
71.76% Lines 61/85

    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
    1531×
    1×
    1×
    1×
    1×
    1×

    1×
    2×
    100×
    100×
    100×
    100×
    100×

    1×
    2×
    2×

    1×
    20×

    1×
    2×
    1×

    1×

    2×

    1×
    10×

    8×

    8×
    5×
    5×

    3×
    1×

    2×
    9×

    9×
    1×

    1×

    10×

    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×

    1×

    1×

    1×

    1×

    1×
    1×
    1×
    1×
    1×
    1×

    1×
    1×

    1×
    2×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/Codeview.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var env_1 = require("../core/env");
    var dom_1 = require("../core/dom");
    var CodeMirror;
    Iif (env_1["default"].hasCodeMirror) {
        if (env_1["default"].isSupportAmd) {
            require(['codemirror'], function (cm) {
                CodeMirror = cm;
            });
        }
        else {
            CodeMirror = window.CodeMirror;
        }
    }
    /**
     * @class Codeview
     */
    var CodeView = /** @class */ (function () {
        function CodeView(context) {
            this.context = context;
            this.$editor = context.layoutInfo.editor;
            this.$editable = context.layoutInfo.editable;
            this.$codable = context.layoutInfo.codable;
            this.options = context.options;
        }
        CodeView.prototype.sync = function () {
            var isCodeview = this.isActivated();
            Iif (isCodeview && env_1["default"].hasCodeMirror) {
                this.$codable.data('cmEditor').save();
            }
        };
        /**
         * @return {Boolean}
         */
        CodeView.prototype.isActivated = function () {
            return this.$editor.hasClass('codeview');
        };
        /**
         * toggle codeview
         */
        CodeView.prototype.toggle = function () {
            if (this.isActivated()) {
                this.deactivate();
            }
            else {
                this.activate();
            }
            this.context.triggerEvent('codeview.toggled');
        };
        /**
         * purify input value
         * @param value
         * @returns {*}
         */
        CodeView.prototype.purify = function (value) {
            if (this.options.codeviewFilter) {
                // filter code view regex
                value = value.replace(this.options.codeviewFilterRegex, '');
                // allow specific iframe tag
                if (this.options.codeviewIframeFilter) {
                    var whitelist_1 = this.options.codeviewIframeWhitelistSrc.concat(this.options.codeviewIframeWhitelistSrcBase);
                    value = value.replace(/(<iframe.*?>.*?(?:<\/iframe>)?)/gi, function (tag) {
                        // remove if src attribute is duplicated
                        if (/<.+src(?==?('|"|\s)?)[\s\S]+src(?=('|"|\s)?)[^>]*?>/i.test(tag)) {
                            return '';
                        }
                        for (var _i = 0, whitelist_2 = whitelist_1; _i < whitelist_2.length; _i++) {
                            var src = whitelist_2[_i];
                            // pass if src is trusted
                            if ((new RegExp('src="(https?:)?\/\/' + src + '\/(.+)"')).test(tag)) {
                                return tag;
                            }
                        }
                        return '';
                    });
                }
            }
            return value;
        };
        /**
         * activate code view
         */
        CodeView.prototype.activate = function () {
            var _this = this;
            this.$codable.val(dom_1["default"].html(this.$editable, this.options.prettifyHtml));
            this.$codable.height(this.$editable.height());
            this.context.invoke('toolbar.updateCodeview', true);
            this.$editor.addClass('codeview');
            this.$codable.focus();
            // activate CodeMirror as codable
            Iif (env_1["default"].hasCodeMirror) {
                var cmEditor_1 = CodeMirror.fromTextArea(this.$codable[0], this.options.codemirror);
                // CodeMirror TernServer
                if (this.options.codemirror.tern) {
                    var server_1 = new CodeMirror.TernServer(this.options.codemirror.tern);
                    cmEditor_1.ternServer = server_1;
                    cmEditor_1.on('cursorActivity', function (cm) {
                        server_1.updateArgHints(cm);
                    });
                }
                cmEditor_1.on('blur', function (event) {
                    _this.context.triggerEvent('blur.codeview', cmEditor_1.getValue(), event);
                });
                cmEditor_1.on('change', function (event) {
                    _this.context.triggerEvent('change.codeview', cmEditor_1.getValue(), cmEditor_1);
                });
                // CodeMirror hasn't Padding.
                cmEditor_1.setSize(null, this.$editable.outerHeight());
                this.$codable.data('cmEditor', cmEditor_1);
            }
            else {
                this.$codable.on('blur', function (event) {
                    _this.context.triggerEvent('blur.codeview', _this.$codable.val(), event);
                });
                this.$codable.on('input', function (event) {
                    _this.context.triggerEvent('change.codeview', _this.$codable.val(), _this.$codable);
                });
            }
        };
        /**
         * deactivate code view
         */
        CodeView.prototype.deactivate = function () {
            // deactivate CodeMirror as codable
            Iif (env_1["default"].hasCodeMirror) {
                var cmEditor = this.$codable.data('cmEditor');
                this.$codable.val(cmEditor.getValue());
                cmEditor.toTextArea();
            }
            var value = this.purify(dom_1["default"].value(this.$codable, this.options.prettifyHtml) || dom_1["default"].emptyPara);
            var isChange = this.$editable.html() !== value;
            this.$editable.html(value);
            this.$editable.height(this.options.height ? this.$codable.height() : 'auto');
            this.$editor.removeClass('codeview');
            Iif (isChange) {
                this.context.triggerEvent('change', this.$editable.html(), this.$editable);
            }
            this.$editable.focus();
            this.context.invoke('toolbar.updateCodeview', false);
        };
        CodeView.prototype.destroy = function () {
            Iif (this.isActivated()) {
                this.deactivate();
            }
        };
        return CodeView;
    }());
    exports["default"] = CodeView;

    },'src/js/base/module/Codeview.js',{"../core/env":"/Users/lqez/Dev/summernote/src/js/base/core/env.js","../core/dom":"/Users/lqez/Dev/summernote/src/js/base/core/dom.js"}];})(this);
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 12240 characters]