UNPKG

@venly/connect

Version:

Venly Connect SDK

100 lines 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PopupWindow = void 0; var tslib_1 = require("tslib"); var DialogWindow_1 = require("../dialog/DialogWindow"); var Utils_1 = tslib_1.__importDefault(require("../utils/Utils")); var PopupWindow = /** @class */ (function () { function PopupWindow(url, target, features, useOverlay, replace) { this.id = "id-" + Utils_1.default.uuidv4(); this.useOverlay = typeof useOverlay !== 'undefined' ? useOverlay : true; this.win = window.open(url, target, features); if (this.win) { this.setCloseInterval(); } else { throw new Error('Something went wrong while trying to open the popup'); } this.openOverlay(); } PopupWindow.openNew = function (url, options) { var mergedOptions = Object.assign({ title: 'Venly Connect', w: 350, h: 700, useOverlay: true }, options); var left = (screen.width / 2) - (mergedOptions.w / 2); var top = (screen.height / 2) - (mergedOptions.h / 2); var features = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, '; features += "copyhistory=no, width=" + mergedOptions.w + ", height=" + mergedOptions.h + ", top=" + top + ", left=" + left; return new PopupWindow(url, mergedOptions.title, features, mergedOptions.useOverlay); }; PopupWindow.prototype.setCloseInterval = function () { var _this = this; this.interval = window.setInterval(function () { if (!_this.win || _this.win.closed) { _this.clearCloseInterval(); _this.close(); } }, 100); }; PopupWindow.prototype.clearCloseInterval = function () { window.clearInterval(this.interval); }; PopupWindow.prototype.close = function () { if (this.win) { this.win.close(); this.closeOverlay(); } }; Object.defineProperty(PopupWindow.prototype, "closed", { get: function () { if (this.win) { return this.win.closed; } else { return true; } }, enumerable: false, configurable: true }); PopupWindow.prototype.focus = function () { if (this.win) { this.win.focus(); } }; PopupWindow.prototype.postMessage = function (message, targetOrigin, transfer) { if (this.win) { this.win.postMessage(message, targetOrigin, transfer); } }; PopupWindow.prototype.closeOverlay = function () { PopupWindow.closeOverlay(this.id, this.useOverlay); }; PopupWindow.prototype.openOverlay = function () { PopupWindow.openOverlay(this.id, this.useOverlay, this.focus.bind(this), this.close.bind(this)); }; PopupWindow.closeOverlay = function (id, useOverlay) { var overlayContainer = document.querySelector("#venly-overlay-container, #" + id); if (overlayContainer) overlayContainer.remove(); }; PopupWindow.openOverlay = function (id, useOverlay, focus, close) { if (useOverlay) { DialogWindow_1.DialogWindow.showRefocusLayout(id, focus); } }; PopupWindow.CONST = { overlayClassName: 'venly-connect__overlay', overlayLinkClassName: 'venly-connect__reopen-link', overlayCloseLinkClassName: 'venly-connect__close-link', overlayMessage: 'Don’t see the popup? We’ll help you re-open the popup to complete your action.', overlayLinkMessage: 'Click to continue', overlayLinkStyle: 'color: white; text-decoration: underline; font-weight: bold;', }; return PopupWindow; }()); exports.PopupWindow = PopupWindow; //# sourceMappingURL=PopupWindow.js.map