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;
});
|