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

100% Statements 35/35
100% Branches 4/4
100% Functions 9/9
100% Lines 35/35
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   1745× 1745× 1745×   1745× 1745×   1738× 1738× 1738× 1738×   1806×   1805× 1805× 1805× 1805× 15258×   1805× 14328×   1805× 10946×   1805× 1805× 1805× 1805× 1148× 1148×          
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.parent = parent;
            this.toolbarStatus = this.prevToolbarStatus = util_1.getDefaultHtmlTbStatus();
            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.parent.off(events.toolbarRefresh, this.onRefreshHandler);
            this.parent.off(events.destroy, this.removeEventListener);
        };
        HtmlToolbarStatus.prototype.onRefreshHandler = function (args) {
            if (this.parent.readonly) {
                return;
            }
            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;
});