all files / rich-text-editor/actions/ toolbar-action.js

98.25% Statements 56/57
94.74% Branches 54/57
100% Functions 8/8
98.25% Lines 56/57
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   2536× 2536×   2536× 2536× 2536× 2536×   1454×       1454×   1447× 1447×   1447× 966×     1447× 48×   48× 42× 42× 42× 42×       1447× 131×       37×     1410×   1410× 1410×   328× 328×     254×   254× 30× 30×   224×     223×     328×   53× 53× 53×   2514× 2514× 2514× 2514×        
define(["require", "exports", "@syncfusion/ej2-base", "../base/constant"], function (require, exports, ej2_base_1, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ToolbarAction = (function () {
        function ToolbarAction(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        ToolbarAction.prototype.addEventListener = function () {
            this.parent.on(events.toolbarClick, this.toolbarClick, this);
            this.parent.on(events.dropDownSelect, this.dropDownSelect, this);
            this.parent.on(events.colorPickerChanged, this.renderSelection, this);
            this.parent.on(events.destroy, this.removeEventListener, this);
        };
        ToolbarAction.prototype.toolbarClick = function (args) {
            Iif (this.parent.userAgentData.isSafari() && this.parent.formatter.editorManager.nodeSelection &&
                !this.parent.inputElement.contains(this.parent.getRange().startContainer)) {
                this.parent.notify(events.selectionRestore, {});
            }
            if (ej2_base_1.isNullOrUndefined(args.item)) {
                return;
            }
            Eif (!ej2_base_1.isNullOrUndefined(args.item.controlParent)) {
                var activeEle = args.item.controlParent
                    .activeEle;
                if (activeEle) {
                    activeEle.tabIndex = -1;
                }
            }
            if (args.item.command === 'NumberFormatList' || args.item.command === 'BulletFormatList') {
                var targetEle = args.originalEvent.target.nodeName === 'SPAN' ?
                    args.originalEvent.target.closest('.e-rte-dropdown.e-split-btn') : args.originalEvent.target;
                if (targetEle) {
                    var hasNumberList = targetEle.classList.contains('e-rte-numberformatlist-dropdown');
                    Eif (hasNumberList || targetEle.classList.contains('e-rte-bulletformatlist-dropdown')) {
                        args.item.command = 'Lists';
                        args.item.subCommand = args.item.subCommand === 'NumberFormatList' ? 'OL' : 'UL';
                    }
                }
            }
            if (args.item.command === 'Lists') {
                if (((args.originalEvent.target.classList.contains('e-rte-numberformatlist-dropdown') ||
                    args.originalEvent.target.classList.contains('e-rte-bulletformatlist-dropdown')) &&
                    (args.originalEvent.target.classList.contains('e-dropdown-btn'))) ||
                    args.originalEvent.target.classList.contains('e-caret')) {
                    return;
                }
            }
            if (args.item.subCommand === 'HorizontalLine') {
                args.item.value = '<hr/>';
            }
            this.parent.notify(events.htmlToolbarClick, args);
            this.parent.notify(events.markdownToolbarClick, args);
        };
        ToolbarAction.prototype.dropDownSelect = function (e) {
            this.parent.notify(events.selectionRestore, {});
            if (!(document.body.contains(document.body.querySelector('.e-rte-quick-toolbar'))
                && e.item && (e.item.command === 'Images' || e.item.command === 'Audios' || e.item.command === 'Videos' ||
                e.item.command === 'VideoLayoutOption' || e.item.command === 'Display' || e.item.command === 'Table'))) {
                var value = e.item.controlParent && this.parent.quickToolbarModule && this.parent.quickToolbarModule.tableQTBar
                    && this.parent.quickToolbarModule.tableQTBar.element.contains(e.item.controlParent.element) ? 'Table' : null;
                if (e.item.command === 'Lists' || e.item.command === 'Checklist') {
                    var listItem = { listStyle: e.item.value, listImage: e.item.listImage, type: e.item.subCommand };
                    this.parent.formatter.process(this.parent, e, e.originalEvent, listItem);
                }
                else if (e.item.command === 'CodeBlock') {
                    var codeBlockItems = { language: e.item.text, label: e.item.label, action: 'createCodeBlock' };
                    this.parent.formatter.process(this.parent, e, e.originalEvent, codeBlockItems);
                }
                else {
                    this.parent.formatter.process(this.parent, e, e.originalEvent, value);
                }
            }
            this.parent.notify(events.selectionSave, {});
        };
        ToolbarAction.prototype.renderSelection = function (args) {
            this.parent.notify(events.selectionRestore, {});
            this.parent.formatter.process(this.parent, args, args.originalEvent, null);
            this.parent.notify(events.selectionSave, {});
        };
        ToolbarAction.prototype.removeEventListener = function () {
            this.parent.off(events.toolbarClick, this.toolbarClick);
            this.parent.off(events.dropDownSelect, this.dropDownSelect);
            this.parent.off(events.colorPickerChanged, this.renderSelection);
            this.parent.off(events.destroy, this.removeEventListener);
        };
        return ToolbarAction;
    }());
    exports.ToolbarAction = ToolbarAction;
});