all files / rich-text-editor/actions/ html-toolbar-status.js

93.62% Statements 44/47
86.67% Branches 13/15
90.91% Functions 10/11
93.62% Lines 44/47
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   2446× 2446× 2446× 2446× 2446×   2446× 2446×   2437× 2437× 2437× 2437× 2437×   3240× 3240×   3233× 3233×                 3233× 3233×     3233× 3233× 3233× 3233× 27682×   3233× 25767×   3233× 19524×   3233× 3233× 3233× 3233× 1922× 1922×          
define(["require", "exports", "../base/constant", "../../editor-manager/plugin/toolbar-status", "../../common/util"], function (require, exports, events, toolbar_status_1, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var HtmlToolbarStatus = (function () {
        function HtmlToolbarStatus(parent) {
            this.debounceDelay = 100;
            this.parent = parent;
            this.toolbarStatus = this.prevToolbarStatus = util_1.getDefaultHtmlTbStatus();
            this.debounceDelay = this.debounceDelay !== undefined ? this.debounceDelay : 100;
            this.addEventListener();
        }
        HtmlToolbarStatus.prototype.addEventListener = function () {
            this.parent.on(events.toolbarRefresh, this.onRefreshHandler, this);
            this.parent.on(events.destroy, this.removeEventListener, this);
        };
        HtmlToolbarStatus.prototype.removeEventListener = function () {
            this.toolbarStatus = null;
            this.prevToolbarStatus = null;
            this.debounceTimer = null;
            this.parent.off(events.toolbarRefresh, this.onRefreshHandler);
            this.parent.off(events.destroy, this.removeEventListener);
        };
        HtmlToolbarStatus.prototype.onRefreshHandler = function (args) {
            var _this = this;
            if (this.parent.readonly) {
                return;
            }
            var event = !!(args['args'] && args['args'].isKeyboardEvent);
            Iif (event && !(this.parent.element &&
                this.parent.element.dataset &&
                this.parent.element.dataset.rteUnitTesting === 'true')) {
                clearTimeout(this.debounceTimer);
                this.debounceTimer = window.setTimeout(function () {
                    _this.getToolbarStatus(args);
                }, this.debounceDelay);
            }
            else {
                clearTimeout(this.debounceTimer);
                this.getToolbarStatus(args);
            }
        };
        HtmlToolbarStatus.prototype.getToolbarStatus = function (args) {
            var fontsize = [];
            var fontName = [];
            var formats = [];
            this.parent.fontSize.items.forEach(function (item) {
                fontsize.push(item.value);
            });
            this.parent.fontFamily.items.forEach(function (item) {
                fontName.push(item.value);
            });
            this.parent.format.types.forEach(function (item) {
                formats.push(item.value.toLocaleLowerCase());
            });
            this.toolbarStatus = toolbar_status_1.ToolbarStatus.get(this.parent.contentModule.getDocument(), this.parent.contentModule.getEditPanel(), formats, fontsize, fontName, args.documentNode);
            var tbStatusString = JSON.stringify(this.toolbarStatus);
            this.parent.notify(events.toolbarUpdated, this.toolbarStatus);
            if (JSON.stringify(this.prevToolbarStatus) !== tbStatusString) {
                this.parent.notify(events.updateTbItemsStatus, { html: JSON.parse(tbStatusString), markdown: null });
                this.prevToolbarStatus = JSON.parse(tbStatusString);
            }
        };
        return HtmlToolbarStatus;
    }());
    exports.HtmlToolbarStatus = HtmlToolbarStatus;
});