# all files / src/js/lite/ui/ TooltipUI.js

5.88% Statements 3/51
0% Branches 0/23
12.5% Functions 1/8
4% Lines 2/50

    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
    951×

    2×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/lite/ui/TooltipUI.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var TooltipUI = /** @class */ (function () {
        function TooltipUI($node, options) {
            this.$node = $node;
            this.options = $.extend({}, {
                title: '',
                target: options.container,
                trigger: 'hover focus',
                placement: 'bottom'
            }, options);
            // create tooltip node
            this.$tooltip = $([
                '<div class="note-tooltip in">',
                '  <div class="note-tooltip-arrow"/>',
                '  <div class="note-tooltip-content"/>',
                '</div>',
            ].join(''));
            // define event
            if (this.options.trigger !== 'manual') {
                var showCallback_1 = this.show.bind(this);
                var hideCallback_1 = this.hide.bind(this);
                var toggleCallback_1 = this.toggle.bind(this);
                this.options.trigger.split(' ').forEach(function (eventName) {
                    if (eventName === 'hover') {
                        $node.off('mouseenter mouseleave');
                        $node.on('mouseenter', showCallback_1).on('mouseleave', hideCallback_1);
                    }
                    else if (eventName === 'click') {
                        $node.on('click', toggleCallback_1);
                    }
                    else if (eventName === 'focus') {
                        $node.on('focus', showCallback_1).on('blur', hideCallback_1);
                    }
                });
            }
        }
        TooltipUI.prototype.show = function () {
            var $node = this.$node;
            var offset = $node.offset();
            var $tooltip = this.$tooltip;
            var title = this.options.title || $node.attr('title') || $node.data('title');
            var placement = this.options.placement || $node.data('placement');
            $tooltip.addClass(placement);
            $tooltip.addClass('in');
            $tooltip.find('.note-tooltip-content').text(title);
            $tooltip.appendTo(this.options.target);
            var nodeWidth = $node.outerWidth();
            var nodeHeight = $node.outerHeight();
            var tooltipWidth = $tooltip.outerWidth();
            var tooltipHeight = $tooltip.outerHeight();
            if (placement === 'bottom') {
                $tooltip.css({
                    top: offset.top + nodeHeight,
                    left: offset.left + (nodeWidth / 2 - tooltipWidth / 2)
                });
            }
            else if (placement === 'top') {
                $tooltip.css({
                    top: offset.top - tooltipHeight,
                    left: offset.left + (nodeWidth / 2 - tooltipWidth / 2)
                });
            }
            else if (placement === 'left') {
                $tooltip.css({
                    top: offset.top + (nodeHeight / 2 - tooltipHeight / 2),
                    left: offset.left - tooltipWidth
                });
            }
            else if (placement === 'right') {
                $tooltip.css({
                    top: offset.top + (nodeHeight / 2 - tooltipHeight / 2),
                    left: offset.left + nodeWidth
                });
            }
        };
        TooltipUI.prototype.hide = function () {
            this.$tooltip.removeClass('in');
            this.$tooltip.remove();
        };
        TooltipUI.prototype.toggle = function () {
            if (this.$tooltip.hasClass('in')) {
                this.hide();
            }
            else {
                this.show();
            }
        };
        return TooltipUI;
    }());
    exports["default"] = TooltipUI;

    },'src/js/lite/ui/TooltipUI.js',{}];})(this);
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,