info.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.Info = void 0;
  17. var close_button_js_1 = require("./close_button.js");
  18. var html_classes_js_1 = require("./html_classes.js");
  19. var abstract_postable_js_1 = require("./abstract_postable.js");
  20. var Info = (function (_super) {
  21. __extends(Info, _super);
  22. function Info(title, content, signature) {
  23. var _this = _super.call(this) || this;
  24. _this.title = title;
  25. _this.signature = signature;
  26. _this.className = html_classes_js_1.HtmlClasses['INFO'];
  27. _this.role = 'dialog';
  28. _this.contentDiv = _this.generateContent();
  29. _this.close = _this.generateClose();
  30. _this.content = content || function () { return ''; };
  31. return _this;
  32. }
  33. Info.prototype.attachMenu = function (menu) {
  34. this.menu = menu;
  35. };
  36. Info.prototype.generateHtml = function () {
  37. _super.prototype.generateHtml.call(this);
  38. var html = this.html;
  39. html.appendChild(this.generateTitle());
  40. html.appendChild(this.contentDiv);
  41. html.appendChild(this.generateSignature());
  42. html.appendChild(this.close.html);
  43. html.setAttribute('tabindex', '0');
  44. };
  45. Info.prototype.post = function () {
  46. _super.prototype.post.call(this);
  47. var doc = document.documentElement;
  48. var html = this.html;
  49. var H = window.innerHeight || doc.clientHeight || doc.scrollHeight || 0;
  50. var x = Math.floor((-html.offsetWidth) / 2);
  51. var y = Math.floor((H - html.offsetHeight) / 3);
  52. html.setAttribute('style', 'margin-left: ' + x + 'px; top: ' + y + 'px;');
  53. if (window.event instanceof MouseEvent) {
  54. html.classList.add(html_classes_js_1.HtmlClasses['MOUSEPOST']);
  55. }
  56. html.focus();
  57. };
  58. Info.prototype.display = function () {
  59. this.menu.registerWidget(this);
  60. this.contentDiv.innerHTML = this.content();
  61. var html = this.menu.html;
  62. if (html.parentNode) {
  63. html.parentNode.removeChild(html);
  64. }
  65. this.menu.frame.appendChild(this.html);
  66. };
  67. Info.prototype.click = function (_event) { };
  68. Info.prototype.keydown = function (event) {
  69. this.bubbleKey();
  70. _super.prototype.keydown.call(this, event);
  71. };
  72. Info.prototype.escape = function (_event) {
  73. this.unpost();
  74. };
  75. Info.prototype.unpost = function () {
  76. _super.prototype.unpost.call(this);
  77. this.html.classList.remove(html_classes_js_1.HtmlClasses['MOUSEPOST']);
  78. this.menu.unregisterWidget(this);
  79. };
  80. Info.prototype.generateClose = function () {
  81. var close = new close_button_js_1.CloseButton(this);
  82. var html = close.html;
  83. html.classList.add(html_classes_js_1.HtmlClasses['INFOCLOSE']);
  84. html.setAttribute('aria-label', 'Close Dialog Box');
  85. return close;
  86. };
  87. Info.prototype.generateTitle = function () {
  88. var span = document.createElement('span');
  89. span.innerHTML = this.title;
  90. span.classList.add(html_classes_js_1.HtmlClasses['INFOTITLE']);
  91. return span;
  92. };
  93. Info.prototype.generateContent = function () {
  94. var div = document.createElement('div');
  95. div.classList.add(html_classes_js_1.HtmlClasses['INFOCONTENT']);
  96. div.setAttribute('tabindex', '0');
  97. return div;
  98. };
  99. Info.prototype.generateSignature = function () {
  100. var span = document.createElement('span');
  101. span.innerHTML = this.signature;
  102. span.classList.add(html_classes_js_1.HtmlClasses['INFOSIGNATURE']);
  103. return span;
  104. };
  105. Info.prototype.toJson = function () {
  106. return { type: ''
  107. };
  108. };
  109. return Info;
  110. }(abstract_postable_js_1.AbstractPostable));
  111. exports.Info = Info;
  112. //# sourceMappingURL=info.js.map