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

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

58.21% Statements 39/67
42.86% Branches 6/14
75% Functions 12/16
57.58% Lines 38/66

    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
    1331×
    1×
    1×
    1×
    1×
    2×
    97×
    97×
    97×
    97×
    97×
    97×
    97×

    1×

    69×

    4×

    2×

    1×
    97×
    97×

    97×

    97×

    1×
    2×

    1×
    72×
    1×

    71×
    71×
    71×
    71×

    71×

    71×

    1×
    75×
    75×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/Handle.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var dom_1 = require("../core/dom");
    var Handle = /** @class */ (function () {
        function Handle(context) {
            var _this = this;
            this.context = context;
            this.$document = jquery_1["default"](document);
            this.$editingArea = context.layoutInfo.editingArea;
            this.options = context.options;
            this.lang = this.options.langInfo;
            this.events = {
                'summernote.mousedown': function (we, e) {
                    Iif (_this.update(e.target, e)) {
                        e.preventDefault();
                    }
                },
                'summernote.keyup summernote.scroll summernote.change summernote.dialog.shown': function () {
                    _this.update();
                },
                'summernote.disable': function () {
                    _this.hide();
                },
                'summernote.codeview.toggled': function () {
                    _this.update();
                }
            };
        }
        Handle.prototype.initialize = function () {
            var _this = this;
            this.$handle = jquery_1["default"]([
                '<div class="note-handle">',
                '<div class="note-control-selection">',
                '<div class="note-control-selection-bg"></div>',
                '<div class="note-control-holder note-control-nw"></div>',
                '<div class="note-control-holder note-control-ne"></div>',
                '<div class="note-control-holder note-control-sw"></div>',
                '<div class="',
                (this.options.disableResizeImage ? 'note-control-holder' : 'note-control-sizing'),
                ' note-control-se"></div>',
                (this.options.disableResizeImage ? '' : '<div class="note-control-selection-info"></div>'),
                '</div>',
                '</div>',
            ].join('')).prependTo(this.$editingArea);
            this.$handle.on('mousedown', function (event) {
                if (dom_1["default"].isControlSizing(event.target)) {
                    event.preventDefault();
                    event.stopPropagation();
                    var $target_1 = _this.$handle.find('.note-control-selection').data('target');
                    var posStart_1 = $target_1.offset();
                    var scrollTop_1 = _this.$document.scrollTop();
                    var onMouseMove_1 = function (event) {
                        _this.context.invoke('editor.resizeTo', {
                            x: event.clientX - posStart_1.left,
                            y: event.clientY - (posStart_1.top - scrollTop_1)
                        }, $target_1, !event.shiftKey);
                        _this.update($target_1[0]);
                    };
                    _this.$document
                        .on('mousemove', onMouseMove_1)
                        .one('mouseup', function (e) {
                        e.preventDefault();
                        _this.$document.off('mousemove', onMouseMove_1);
                        _this.context.invoke('editor.afterCommand');
                    });
                    if (!$target_1.data('ratio')) { // original ratio.
                        $target_1.data('ratio', $target_1.height() / $target_1.width());
                    }
                }
            });
            // Listen for scrolling on the handle overlay.
            this.$handle.on('wheel', function (e) {
                e.preventDefault();
                _this.update();
            });
        };
        Handle.prototype.destroy = function () {
            this.$handle.remove();
        };
        Handle.prototype.update = function (target, event) {
            if (this.context.isDisabled()) {
                return false;
            }
            var isImage = dom_1["default"].isImg(target);
            var $selection = this.$handle.find('.note-control-selection');
            this.context.invoke('imagePopover.update', target, event);
            Iif (isImage) {
                var $image = jquery_1["default"](target);
                var position = $image.position();
                var pos = {
                    left: position.left + parseInt($image.css('marginLeft'), 10),
                    top: position.top + parseInt($image.css('marginTop'), 10)
                };
                // exclude margin
                var imageSize = {
                    w: $image.outerWidth(false),
                    h: $image.outerHeight(false)
                };
                $selection.css({
                    display: 'block',
                    left: pos.left,
                    top: pos.top,
                    width: imageSize.w,
                    height: imageSize.h
                }).data('target', $image); // save current image element.
                var origImageObj = new Image();
                origImageObj.src = $image.attr('src');
                var sizingText = imageSize.w + 'x' + imageSize.h + ' (' + this.lang.image.original + ': ' + origImageObj.width + 'x' + origImageObj.height + ')';
                $selection.find('.note-control-selection-info').text(sizingText);
                this.context.invoke('editor.saveTarget', target);
            }
            else {
                this.hide();
            }
            return isImage;
        };
        /**
         * hide
         *
         * @param {jQuery} $handle
         */
        Handle.prototype.hide = function () {
            this.context.invoke('editor.clearTarget');
            this.$handle.children().hide();
        };
        return Handle;
    }());
    exports["default"] = Handle;

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