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

86.21% Statements 75/87
64.71% Branches 22/34
100% Functions 14/14
86.05% Lines 74/86

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

    1×
    107×

    1×
    97×
    97×
    97×

    97×

    97×

    97×
    97×
    65×

    97×
    97×

    1×
    2×
    2×

    1×
    99×
    1×

    98×
    98×
    98×
    98×

    98×
    98×

    98×
    98×
    98×
    98×
    98×
    98×

    98×

    1×
    99×
    1×

    98×

    99×

    1×
    2×
    2×

    1×
    2×
    2×
    1×

    1×

    1×
    2×
    2×
    1×

    2×

    1×
    4×
    4×
    1×

    4×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/Toolbar.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var Toolbar = /** @class */ (function () {
        function Toolbar(context) {
            this.context = context;
            this.$window = jquery_1["default"](window);
            this.$document = jquery_1["default"](document);
            this.ui = jquery_1["default"].summernote.ui;
            this.$note = context.layoutInfo.note;
            this.$editor = context.layoutInfo.editor;
            this.$toolbar = context.layoutInfo.toolbar;
            this.$editable = context.layoutInfo.editable;
            this.$statusbar = context.layoutInfo.statusbar;
            this.options = context.options;
            this.isFollowing = false;
            this.followScroll = this.followScroll.bind(this);
        }
        Toolbar.prototype.shouldInitialize = function () {
            return !this.options.airMode;
        };
        Toolbar.prototype.initialize = function () {
            var _this = this;
            this.options.toolbar = this.options.toolbar || [];
            Iif (!this.options.toolbar.length) {
                this.$toolbar.hide();
            }
            else {
                this.context.invoke('buttons.build', this.$toolbar, this.options.toolbar);
            }
            Iif (this.options.toolbarContainer) {
                this.$toolbar.appendTo(this.options.toolbarContainer);
            }
            this.changeContainer(false);
            this.$note.on('summernote.keyup summernote.mouseup summernote.change', function () {
                _this.context.invoke('buttons.updateCurrentStyle');
            });
            this.context.invoke('buttons.updateCurrentStyle');
            Iif (this.options.followingToolbar) {
                this.$window.on('scroll resize', this.followScroll);
            }
        };
        Toolbar.prototype.destroy = function () {
            this.$toolbar.children().remove();
            Iif (this.options.followingToolbar) {
                this.$window.off('scroll resize', this.followScroll);
            }
        };
        Toolbar.prototype.followScroll = function () {
            if (this.$editor.hasClass('fullscreen')) {
                return false;
            }
            var editorHeight = this.$editor.outerHeight();
            var editorWidth = this.$editor.width();
            var toolbarHeight = this.$toolbar.height();
            var statusbarHeight = this.$statusbar.height();
            // check if the web app is currently using another static bar
            var otherBarHeight = 0;
            Iif (this.options.otherStaticBar) {
                otherBarHeight = jquery_1["default"](this.options.otherStaticBar).outerHeight();
            }
            var currentOffset = this.$document.scrollTop();
            var editorOffsetTop = this.$editor.offset().top;
            var editorOffsetBottom = editorOffsetTop + editorHeight;
            var activateOffset = editorOffsetTop - otherBarHeight;
            var deactivateOffsetBottom = editorOffsetBottom - otherBarHeight - toolbarHeight - statusbarHeight;
            Iif (!this.isFollowing &&
                (currentOffset > activateOffset) && (currentOffset < deactivateOffsetBottom - toolbarHeight)) {
                this.isFollowing = true;
                this.$toolbar.css({
                    position: 'fixed',
                    top: otherBarHeight,
                    width: editorWidth
                });
                this.$editable.css({
                    marginTop: this.$toolbar.height() + 5
                });
            }
            else Iif (this.isFollowing &&
                ((currentOffset < activateOffset) || (currentOffset > deactivateOffsetBottom))) {
                this.isFollowing = false;
                this.$toolbar.css({
                    position: 'relative',
                    top: 0,
                    width: '100%'
                });
                this.$editable.css({
                    marginTop: ''
                });
            }
        };
        Toolbar.prototype.changeContainer = function (isFullscreen) {
            if (isFullscreen) {
                this.$toolbar.prependTo(this.$editor);
            }
            else {
                Iif (this.options.toolbarContainer) {
                    this.$toolbar.appendTo(this.options.toolbarContainer);
                }
            }
            this.followScroll();
        };
        Toolbar.prototype.updateFullscreen = function (isFullscreen) {
            this.ui.toggleBtnActive(this.$toolbar.find('.btn-fullscreen'), isFullscreen);
            this.changeContainer(isFullscreen);
        };
        Toolbar.prototype.updateCodeview = function (isCodeview) {
            this.ui.toggleBtnActive(this.$toolbar.find('.btn-codeview'), isCodeview);
            if (isCodeview) {
                this.deactivate();
            }
            else {
                this.activate();
            }
        };
        Toolbar.prototype.activate = function (isIncludeCodeview) {
            var $btn = this.$toolbar.find('button');
            if (!isIncludeCodeview) {
                $btn = $btn.not('.btn-codeview');
            }
            this.ui.toggleBtn($btn, true);
        };
        Toolbar.prototype.deactivate = function (isIncludeCodeview) {
            var $btn = this.$toolbar.find('button');
            if (!isIncludeCodeview) {
                $btn = $btn.not('.btn-codeview');
            }
            this.ui.toggleBtn($btn, false);
        };
        return Toolbar;
    }());
    exports["default"] = Toolbar;

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