popup.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. exports.Popup = void 0;
  17. var abstract_postable_js_1 = require("./abstract_postable.js");
  18. var Popup = (function (_super) {
  19. __extends(Popup, _super);
  20. function Popup(title, content) {
  21. var _this = _super.call(this) || this;
  22. _this.title = title;
  23. _this.window = null;
  24. _this.localSettings = {
  25. left: Math.round((screen.width - 400) / 2),
  26. top: Math.round((screen.height - 300) / 3)
  27. };
  28. _this.windowList = [];
  29. _this.mobileFlag = false;
  30. _this.active = null;
  31. _this.content = content || function () { return ''; };
  32. return _this;
  33. }
  34. Popup.fromJson = function () {
  35. };
  36. Popup.prototype.attachMenu = function (menu) {
  37. this.menu = menu;
  38. };
  39. Popup.prototype.post = function () {
  40. this.display();
  41. };
  42. Popup.prototype.display = function () {
  43. this.active = this.menu.store.active;
  44. var settings = [];
  45. for (var setting in Popup.popupSettings) {
  46. settings.push(setting + '=' + Popup.popupSettings[setting]);
  47. }
  48. for (var setting in this.localSettings) {
  49. settings.push(setting + '=' + this.localSettings[setting]);
  50. }
  51. this.window = window.open('', '_blank', settings.join(','));
  52. this.windowList.push(this.window);
  53. var doc = this.window.document;
  54. if (this.mobileFlag) {
  55. doc.open();
  56. doc.write('<html><head><meta name="viewport" ' +
  57. 'content="width=device-width, initial-scale=1.0" /><title>' +
  58. this.title +
  59. '</title></head><body style="font-size:85%">');
  60. doc.write('<pre>' + this.generateContent() + '</pre>');
  61. doc.write('<hr><input type="button" value="' +
  62. 'Close' + '" onclick="window.close()" />');
  63. doc.write('</body></html>');
  64. doc.close();
  65. }
  66. else {
  67. doc.open();
  68. doc.write('<html><head><title>' + this.title +
  69. '</title></head><body style="font-size:85%">');
  70. doc.write('<table><tr><td><pre>' + this.generateContent() +
  71. '</pre></td></tr></table>');
  72. doc.write('</body></html>');
  73. doc.close();
  74. setTimeout(this.resize.bind(this), 50);
  75. }
  76. };
  77. Popup.prototype.unpost = function () {
  78. this.windowList.forEach(function (x) { return x.close(); });
  79. this.window = null;
  80. };
  81. Popup.prototype.generateContent = function () {
  82. return this.content(this.active);
  83. };
  84. Popup.prototype.resize = function () {
  85. var table = this.window.document.body.firstChild;
  86. var H = (this.window.outerHeight - this.window.innerHeight) || 30;
  87. var W = (this.window.outerWidth - this.window.innerWidth) || 30;
  88. W = Math.max(140, Math.min(Math.floor(.5 * this.window.screen.width), table.offsetWidth + W + 25));
  89. H = Math.max(40, Math.min(Math.floor(.5 * this.window.screen.height), table.offsetHeight + H + 25));
  90. this.window.resizeTo(W, H);
  91. var bb = this.active.getBoundingClientRect();
  92. if (bb) {
  93. var x = Math.max(0, Math.min(bb.right - Math.floor(W / 2), this.window.screen.width - W - 20));
  94. var y = Math.max(0, Math.min(bb.bottom - Math.floor(H / 2), this.window.screen.height - H - 20));
  95. this.window.moveTo(x, y);
  96. }
  97. this.active = null;
  98. };
  99. Popup.prototype.toJson = function () {
  100. return { type: ''
  101. };
  102. };
  103. Popup.popupSettings = {
  104. status: 'no',
  105. toolbar: 'no',
  106. locationbar: 'no',
  107. menubar: 'no',
  108. directories: 'no',
  109. personalbar: 'no',
  110. resizable: 'yes',
  111. scrollbars: 'yes',
  112. width: 400,
  113. height: 300,
  114. };
  115. return Popup;
  116. }(abstract_postable_js_1.AbstractPostable));
  117. exports.Popup = Popup;
  118. //# sourceMappingURL=popup.js.map