sub_menu.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.SubMenu = void 0;
  17. var abstract_menu_js_1 = require("./abstract_menu.js");
  18. var SubMenu = (function (_super) {
  19. __extends(SubMenu, _super);
  20. function SubMenu(_anchor) {
  21. var _this = _super.call(this) || this;
  22. _this._anchor = _anchor;
  23. _this.variablePool = _this.anchor.menu.pool;
  24. _this.setBaseMenu();
  25. return _this;
  26. }
  27. SubMenu.fromJson = function (factory, _a, anchor) {
  28. var its = _a.items;
  29. var submenu = new this(anchor);
  30. var itemList = factory.get('items')(factory, its, submenu);
  31. submenu.items = itemList;
  32. return submenu;
  33. };
  34. Object.defineProperty(SubMenu.prototype, "anchor", {
  35. get: function () {
  36. return this._anchor;
  37. },
  38. enumerable: false,
  39. configurable: true
  40. });
  41. SubMenu.prototype.post = function () {
  42. if (!this.anchor.menu.isPosted()) {
  43. return;
  44. }
  45. var mobileFlag = false;
  46. var rtlFlag = false;
  47. var margin = 5;
  48. var parent = this.anchor.html;
  49. var menu = this.html;
  50. var base = this.baseMenu.frame;
  51. var mw = parent.offsetWidth;
  52. var x = (mobileFlag ? 30 : mw - 2);
  53. var y = 0;
  54. while (parent && parent !== base) {
  55. x += parent.offsetLeft;
  56. y += parent.offsetTop;
  57. parent = parent.parentNode;
  58. }
  59. if (!mobileFlag) {
  60. if ((rtlFlag && x - mw - menu.offsetWidth > margin) ||
  61. (!rtlFlag && x + menu.offsetWidth >
  62. document.body.offsetWidth - margin)) {
  63. x = Math.max(margin, x - mw - menu.offsetWidth + 6);
  64. }
  65. }
  66. _super.prototype.post.call(this, x, y);
  67. };
  68. SubMenu.prototype.display = function () {
  69. this.baseMenu.frame.appendChild(this.html);
  70. };
  71. SubMenu.prototype.setBaseMenu = function () {
  72. var menu = this;
  73. do {
  74. menu = menu.anchor.menu;
  75. } while (menu instanceof SubMenu);
  76. this.baseMenu = menu;
  77. };
  78. SubMenu.prototype.left = function (_event) {
  79. this.focused = null;
  80. this.anchor.focus();
  81. };
  82. SubMenu.prototype.toJson = function () {
  83. return { type: ''
  84. };
  85. };
  86. return SubMenu;
  87. }(abstract_menu_js_1.AbstractMenu));
  88. exports.SubMenu = SubMenu;
  89. //# sourceMappingURL=sub_menu.js.map