abstract_menu.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. var __values = (this && this.__values) || function(o) {
  16. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  17. if (m) return m.call(o);
  18. if (o && typeof o.length === "number") return {
  19. next: function () {
  20. if (o && i >= o.length) o = void 0;
  21. return { value: o && o[i++], done: !o };
  22. }
  23. };
  24. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  25. };
  26. Object.defineProperty(exports, "__esModule", { value: true });
  27. exports.AbstractMenu = void 0;
  28. var abstract_postable_js_1 = require("./abstract_postable.js");
  29. var abstract_item_js_1 = require("./abstract_item.js");
  30. var html_classes_js_1 = require("./html_classes.js");
  31. var item_submenu_js_1 = require("./item_submenu.js");
  32. var AbstractMenu = (function (_super) {
  33. __extends(AbstractMenu, _super);
  34. function AbstractMenu() {
  35. var _this = _super !== null && _super.apply(this, arguments) || this;
  36. _this.className = html_classes_js_1.HtmlClasses['CONTEXTMENU'];
  37. _this.role = 'menu';
  38. _this._items = [];
  39. _this._baseMenu = null;
  40. return _this;
  41. }
  42. Object.defineProperty(AbstractMenu.prototype, "baseMenu", {
  43. get: function () {
  44. return this._baseMenu;
  45. },
  46. set: function (menu) {
  47. this._baseMenu = menu;
  48. },
  49. enumerable: false,
  50. configurable: true
  51. });
  52. Object.defineProperty(AbstractMenu.prototype, "items", {
  53. get: function () {
  54. return this._items;
  55. },
  56. set: function (items) {
  57. this._items = items;
  58. },
  59. enumerable: false,
  60. configurable: true
  61. });
  62. Object.defineProperty(AbstractMenu.prototype, "pool", {
  63. get: function () {
  64. return this.variablePool;
  65. },
  66. enumerable: false,
  67. configurable: true
  68. });
  69. Object.defineProperty(AbstractMenu.prototype, "focused", {
  70. get: function () {
  71. return this._focused;
  72. },
  73. set: function (item) {
  74. if (this._focused === item) {
  75. return;
  76. }
  77. if (!this._focused) {
  78. this.unfocus();
  79. }
  80. var old = this._focused;
  81. this._focused = item;
  82. if (old) {
  83. old.unfocus();
  84. }
  85. },
  86. enumerable: false,
  87. configurable: true
  88. });
  89. AbstractMenu.prototype.up = function (_event) {
  90. var items = this.items.filter(function (x) { return (x instanceof abstract_item_js_1.AbstractItem) && (!x.isHidden()); });
  91. if (items.length === 0) {
  92. return;
  93. }
  94. if (!this.focused) {
  95. items[items.length - 1].focus();
  96. return;
  97. }
  98. var index = items.indexOf(this.focused);
  99. if (index === -1) {
  100. return;
  101. }
  102. index = index ? --index : items.length - 1;
  103. items[index].focus();
  104. };
  105. AbstractMenu.prototype.down = function (_event) {
  106. var items = this.items.filter(function (x) { return (x instanceof abstract_item_js_1.AbstractItem) && (!x.isHidden()); });
  107. if (items.length === 0) {
  108. return;
  109. }
  110. if (!this.focused) {
  111. items[0].focus();
  112. return;
  113. }
  114. var index = items.indexOf(this.focused);
  115. if (index === -1) {
  116. return;
  117. }
  118. index++;
  119. index = (index === items.length) ? 0 : index;
  120. items[index].focus();
  121. };
  122. AbstractMenu.prototype.generateHtml = function () {
  123. _super.prototype.generateHtml.call(this);
  124. this.generateMenu();
  125. };
  126. AbstractMenu.prototype.generateMenu = function () {
  127. var e_1, _a;
  128. var html = this.html;
  129. html.classList.add(html_classes_js_1.HtmlClasses['MENU']);
  130. try {
  131. for (var _b = __values(this.items), _c = _b.next(); !_c.done; _c = _b.next()) {
  132. var item = _c.value;
  133. if (!item.isHidden()) {
  134. html.appendChild(item.html);
  135. continue;
  136. }
  137. var itemHtml = item.html;
  138. if (itemHtml.parentNode) {
  139. itemHtml.parentNode.removeChild(itemHtml);
  140. }
  141. }
  142. }
  143. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  144. finally {
  145. try {
  146. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  147. }
  148. finally { if (e_1) throw e_1.error; }
  149. }
  150. };
  151. AbstractMenu.prototype.post = function (x, y) {
  152. this.variablePool.update();
  153. _super.prototype.post.call(this, x, y);
  154. };
  155. AbstractMenu.prototype.unpostSubmenus = function () {
  156. var e_2, _a;
  157. var submenus = this.items.filter(function (x) { return x instanceof item_submenu_js_1.Submenu; });
  158. try {
  159. for (var submenus_1 = __values(submenus), submenus_1_1 = submenus_1.next(); !submenus_1_1.done; submenus_1_1 = submenus_1.next()) {
  160. var submenu = submenus_1_1.value;
  161. submenu.submenu.unpost();
  162. if (submenu !== this.focused) {
  163. submenu.unfocus();
  164. }
  165. }
  166. }
  167. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  168. finally {
  169. try {
  170. if (submenus_1_1 && !submenus_1_1.done && (_a = submenus_1.return)) _a.call(submenus_1);
  171. }
  172. finally { if (e_2) throw e_2.error; }
  173. }
  174. };
  175. AbstractMenu.prototype.unpost = function () {
  176. _super.prototype.unpost.call(this);
  177. this.unpostSubmenus();
  178. this.focused = null;
  179. };
  180. AbstractMenu.prototype.find = function (id) {
  181. var e_3, _a;
  182. try {
  183. for (var _b = __values(this.items), _c = _b.next(); !_c.done; _c = _b.next()) {
  184. var item = _c.value;
  185. if (item.type === 'rule') {
  186. continue;
  187. }
  188. if (item.id === id) {
  189. return item;
  190. }
  191. if (item.type === 'submenu') {
  192. var result = item.submenu.find(id);
  193. if (result) {
  194. return result;
  195. }
  196. }
  197. }
  198. }
  199. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  200. finally {
  201. try {
  202. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  203. }
  204. finally { if (e_3) throw e_3.error; }
  205. }
  206. return null;
  207. };
  208. return AbstractMenu;
  209. }(abstract_postable_js_1.AbstractPostable));
  210. exports.AbstractMenu = AbstractMenu;
  211. //# sourceMappingURL=abstract_menu.js.map