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

97.14% Statements 68/70
90.32% Branches 28/31
100% Functions 15/15
97.14% Lines 68/70
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106   1833× 1833×   1834×   1833× 1833×   1833×   1832× 1832×   449× 449× 449× 449×         449× 110×   449× 449× 449× 449×   448× 448× 448×     448×       448× 11×     374×   17×   348×     348× 348× 348× 344×       348×   439× 439×           437×     352×        
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "../base/constant"], function (require, exports, ej2_popups_1, ej2_base_1, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DialogRenderer = (function () {
        function DialogRenderer(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        DialogRenderer.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.destroy, this.removeEventListener, this);
            this.parent.on(events.documentClickClosedBy, this.documentClickClosedBy, this);
        };
        DialogRenderer.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.destroy, this.removeEventListener);
            this.parent.off(events.documentClickClosedBy, this.documentClickClosedBy);
        };
        DialogRenderer.prototype.render = function (e) {
            var dlgObj;
            e.beforeOpen = this.beforeOpen.bind(this);
            e.open = this.open.bind(this);
            e.position = {
                X: 'center',
                Y: (e.target !== 'string' && e.target.nodeName === 'BODY' &&
                    !ej2_base_1.isNullOrUndefined(e.position)) ? e.position.Y : this.getDialogPosition()
            };
            if (ej2_base_1.isNullOrUndefined(e.close)) {
                e.close = this.close.bind(this);
            }
            e.beforeClose = this.beforeClose.bind(this);
            dlgObj = new ej2_popups_1.Dialog(e);
            dlgObj.isStringTemplate = true;
            return dlgObj;
        };
        DialogRenderer.prototype.beforeOpen = function (args) {
            Eif (args.element.classList.contains('e-dialog')) {
                var formEle = ej2_base_1.closest(args.target, 'form');
                if (!ej2_base_1.isNullOrUndefined(formEle)) {
                    this.dialogEle = args.element;
                    this.dialogEle.addEventListener('keydown', this.handleEnterKeyDown);
                }
            }
            this.parent.trigger(events.beforeDialogOpen, args, this.beforeOpenCallback.bind(this, args));
        };
        DialogRenderer.prototype.handleEnterKeyDown = function (args) {
            if (args.key === 'Enter') {
                args.preventDefault();
            }
        };
        DialogRenderer.prototype.beforeOpenCallback = function (args) {
            if (args.cancel) {
                this.parent.notify(events.clearDialogObj, null);
            }
        };
        DialogRenderer.prototype.open = function (args) {
            this.parent.trigger(events.dialogOpen, args);
        };
        DialogRenderer.prototype.documentClickClosedBy = function (args) {
            this.outsideClickClosedBy = args.closedBy;
        };
        DialogRenderer.prototype.beforeClose = function (args) {
            Iif (this.dialogEle) {
                this.dialogEle.removeEventListener('keydown', this.handleEnterKeyDown);
            }
            args.closedBy = this.outsideClickClosedBy === 'outside click' ? this.outsideClickClosedBy : args.closedBy;
            this.parent.trigger(events.beforeDialogClose, args, function (closeArgs) {
                if (!closeArgs.cancel) {
                    if (closeArgs.container.classList.contains('e-popup-close')) {
                        closeArgs.cancel = true;
                    }
                }
            });
            this.outsideClickClosedBy = '';
        };
        DialogRenderer.prototype.getDialogPosition = function () {
            var distanceFromVisibleTop = this.parent.element.getBoundingClientRect().top;
            if (distanceFromVisibleTop < 0) {
                var topHeight = 0;
                var parentElement = this.parent.element;
                while (parentElement.nodeName !== 'BODY') {
                    var top_1 = parentElement.getBoundingClientRect().top;
                    Iif (top_1 > 0) {
                        topHeight = top_1;
                    }
                    parentElement = parentElement.parentElement;
                }
                distanceFromVisibleTop = Math.abs(distanceFromVisibleTop) + topHeight;
                return distanceFromVisibleTop.toString();
            }
            else {
                return 'top';
            }
        };
        DialogRenderer.prototype.close = function (args) {
            this.parent.trigger(events.dialogClose, args);
        };
        return DialogRenderer;
    }());
    exports.DialogRenderer = DialogRenderer;
});