all files / editor-manager/plugin/ lineHeight.js

100% Statements 40/40
94.74% Branches 18/19
100% Functions 8/8
100% Lines 39/39
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   2917× 2917×   2917× 2917×   2745× 2745×   19× 19× 19× 19× 23×   19×   19× 23× 23×       19× 19×       19× 19× 19×   19× 19× 17×                 2745×        
define(["require", "exports", "./../base/constant", "@syncfusion/ej2-base", "./../../common/constant", "../../common/util"], function (require, exports, CONSTANT, ej2_base_1, EVENTS, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var LineHeight = (function () {
        function LineHeight(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        LineHeight.prototype.addEventListener = function () {
            this.parent.observer.on(CONSTANT.LINE_HEIGHT_TYPE, this.applyLineHeight, this);
            this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
        };
        LineHeight.prototype.removeEventListener = function () {
            this.parent.observer.off(CONSTANT.LINE_HEIGHT_TYPE, this.applyLineHeight);
            this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
        };
        LineHeight.prototype.applyLineHeight = function (e) {
            var range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
            var save = this.parent.nodeSelection.save(range, this.parent.currentDocument);
            this.parent.domNode.setMarker(save);
            var blocks = this.parent.domNode.blockNodes();
            blocks = blocks.filter(function (node) { return node.nodeType === Node.ELEMENT_NODE &&
                ['TD', 'TH', 'TABLE'].indexOf(node.tagName) === -1; });
            if (e.enterAction === 'BR') {
                blocks = this.parent.domNode.convertToBlockNodes(blocks, false);
            }
            for (var i = 0; i < blocks.length; i++) {
                var blockElement = blocks[i];
                if (!ej2_base_1.isNullOrUndefined(e.value) && !ej2_base_1.isNullOrUndefined(e.value.selectedValue) && e.value.selectedValue === '') {
                    ej2_base_1.setStyleAttribute(blockElement, { 'line-height': '' });
                    if ((blockElement.getAttribute('style') === '')) {
                        blockElement.removeAttribute('style');
                    }
                }
                else {
                    Eif (!ej2_base_1.isNullOrUndefined(e.value) && !ej2_base_1.isNullOrUndefined(e.value.selectedValue)) {
                        ej2_base_1.setStyleAttribute(blockElement, { 'line-height': e.value.selectedValue });
                    }
                }
            }
            this.parent.editableElement.focus({ preventScroll: true });
            save = this.parent.domNode.saveMarker(save);
            if (this.parent.userAgentData.isMobileDevice()) {
                util_1.setEditFrameFocus(this.parent.editableElement, e.selector);
            }
            save.restore();
            if (e.callBack) {
                e.callBack({
                    requestType: 'LineHeight',
                    editorMode: 'HTML',
                    event: e.event,
                    range: this.parent.nodeSelection.getRange(this.parent.currentDocument),
                    elements: blocks
                });
            }
        };
        LineHeight.prototype.destroy = function () {
            this.removeEventListener();
        };
        return LineHeight;
    }());
    exports.LineHeight = LineHeight;
});