all files / rich-text-editor/renderer/ render.js

97.87% Statements 46/47
92% Branches 23/25
100% Functions 9/9
97.83% Lines 45/46
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   1833× 1833× 1833× 1833×   1833× 1833× 1833×   289× 289×   1832×     1832× 1832× 1832×   1834×   1833× 1833×   1833×   1832× 1832×   124× 118×     24× 24×               24×            
define(["require", "exports", "../base/enum", "../base/constant", "@syncfusion/ej2-base"], function (require, exports, enum_1, events, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Render = (function () {
        function Render(parent, locator) {
            this.parent = parent;
            this.locator = locator;
            this.renderer = this.locator.getService('rendererFactory');
            this.addEventListener();
        }
        Render.prototype.render = function () {
            var rteObj = this.parent;
            this.contentRenderer = this.renderer.getRenderer(enum_1.RenderType.Content);
            this.contentRenderer.renderPanel();
        };
        Render.prototype.refresh = function (e) {
            if (e === void 0) { e = { requestType: 'refresh' }; }
            this.parent.notify(e.requestType + "-begin", e);
        };
        Render.prototype.destroy = function () {
            Iif (ej2_base_1.isNullOrUndefined(this.parent)) {
                return;
            }
            this.removeEventListener();
            this.locator.destroy();
            this.renderer.destroy();
        };
        Render.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.modelChanged, this.refresh, this);
            this.parent.on(events.keyUp, this.keyUp, this);
        };
        Render.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.modelChanged, this.refresh);
            this.parent.off(events.keyUp, this.keyUp);
        };
        Render.prototype.keyUp = function (e) {
            if (this.parent.editorMode === 'HTML') {
                switch (e.args.which) {
                    case 46:
                    case 8:
                        var childNodes = this.parent.contentModule.getEditPanel().childNodes;
                        if ((childNodes.length === 0) ||
                            (childNodes.length === 1 && childNodes[0].childNodes.length === 0 && ((childNodes[0].tagName === 'BR') ||
                                ((childNodes[0].tagName === 'P' || childNodes[0].tagName === 'DIV') && childNodes[0].textContent === '')))) {
                            var node = this.parent.contentModule.getEditPanel();
                            if (this.parent.enterKey === 'DIV') {
                                node.innerHTML = '<div><br/></div>';
                            }
                            else if (this.parent.enterKey === 'BR') {
                                node.innerHTML = '<br/>';
                            }
                            else {
                                node.innerHTML = '<p><br/></p>';
                            }
                            this.parent.formatter.editorManager.nodeSelection.setCursorPoint(this.parent.contentModule.getDocument(), node.childNodes[0], 0);
                        }
                        break;
                }
            }
        };
        return Render;
    }());
    exports.Render = Render;
});