abstract_item.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.AbstractItem = void 0;
  28. var abstract_entry_js_1 = require("./abstract_entry.js");
  29. var menu_util_js_1 = require("./menu_util.js");
  30. var html_classes_js_1 = require("./html_classes.js");
  31. var AbstractItem = (function (_super) {
  32. __extends(AbstractItem, _super);
  33. function AbstractItem(menu, type, _content, id) {
  34. var _this = _super.call(this, menu, type) || this;
  35. _this._content = _content;
  36. _this.disabled = false;
  37. _this.callbacks = [];
  38. _this._id = id ? id : _content;
  39. return _this;
  40. }
  41. Object.defineProperty(AbstractItem.prototype, "content", {
  42. get: function () {
  43. return this._content;
  44. },
  45. set: function (content) {
  46. this._content = content;
  47. this.generateHtml();
  48. if (this.menu) {
  49. this.menu.generateHtml();
  50. }
  51. },
  52. enumerable: false,
  53. configurable: true
  54. });
  55. Object.defineProperty(AbstractItem.prototype, "id", {
  56. get: function () {
  57. return this._id;
  58. },
  59. enumerable: false,
  60. configurable: true
  61. });
  62. AbstractItem.prototype.press = function () {
  63. if (!this.disabled) {
  64. this.executeAction();
  65. this.executeCallbacks_();
  66. }
  67. };
  68. AbstractItem.prototype.executeAction = function () { };
  69. AbstractItem.prototype.registerCallback = function (func) {
  70. if (this.callbacks.indexOf(func) === -1) {
  71. this.callbacks.push(func);
  72. }
  73. };
  74. AbstractItem.prototype.unregisterCallback = function (func) {
  75. var index = this.callbacks.indexOf(func);
  76. if (index !== -1) {
  77. this.callbacks.splice(index, 1);
  78. }
  79. };
  80. AbstractItem.prototype.mousedown = function (event) {
  81. this.press();
  82. this.stop(event);
  83. };
  84. AbstractItem.prototype.mouseover = function (event) {
  85. this.focus();
  86. this.stop(event);
  87. };
  88. AbstractItem.prototype.mouseout = function (event) {
  89. this.deactivate();
  90. this.stop(event);
  91. };
  92. AbstractItem.prototype.generateHtml = function () {
  93. _super.prototype.generateHtml.call(this);
  94. var html = this.html;
  95. html.setAttribute('aria-disabled', 'false');
  96. html.textContent = this.content;
  97. };
  98. AbstractItem.prototype.activate = function () {
  99. if (!this.disabled) {
  100. this.html.classList.add(html_classes_js_1.HtmlClasses['MENUACTIVE']);
  101. }
  102. };
  103. AbstractItem.prototype.deactivate = function () {
  104. this.html.classList.remove(html_classes_js_1.HtmlClasses['MENUACTIVE']);
  105. };
  106. AbstractItem.prototype.focus = function () {
  107. this.menu.focused = this;
  108. _super.prototype.focus.call(this);
  109. this.activate();
  110. };
  111. AbstractItem.prototype.unfocus = function () {
  112. this.deactivate();
  113. _super.prototype.unfocus.call(this);
  114. };
  115. AbstractItem.prototype.escape = function (_event) {
  116. menu_util_js_1.MenuUtil.close(this);
  117. };
  118. AbstractItem.prototype.up = function (event) {
  119. this.menu.up(event);
  120. };
  121. AbstractItem.prototype.down = function (event) {
  122. this.menu.down(event);
  123. };
  124. AbstractItem.prototype.left = function (event) {
  125. this.menu.left(event);
  126. };
  127. AbstractItem.prototype.right = function (event) {
  128. this.menu.right(event);
  129. };
  130. AbstractItem.prototype.space = function (_event) {
  131. this.press();
  132. };
  133. AbstractItem.prototype.disable = function () {
  134. this.disabled = true;
  135. var html = this.html;
  136. html.classList.add(html_classes_js_1.HtmlClasses['MENUDISABLED']);
  137. html.setAttribute('aria-disabled', 'true');
  138. };
  139. AbstractItem.prototype.enable = function () {
  140. this.disabled = false;
  141. var html = this.html;
  142. html.classList.remove(html_classes_js_1.HtmlClasses['MENUDISABLED']);
  143. html.removeAttribute('aria-disabled');
  144. };
  145. AbstractItem.prototype.executeCallbacks_ = function () {
  146. var e_1, _a;
  147. try {
  148. for (var _b = __values(this.callbacks), _c = _b.next(); !_c.done; _c = _b.next()) {
  149. var func = _c.value;
  150. try {
  151. func(this);
  152. }
  153. catch (e) {
  154. menu_util_js_1.MenuUtil.error(e, 'Callback for menu entry ' + this.id +
  155. ' failed.');
  156. }
  157. }
  158. }
  159. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  160. finally {
  161. try {
  162. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  163. }
  164. finally { if (e_1) throw e_1.error; }
  165. }
  166. };
  167. return AbstractItem;
  168. }(abstract_entry_js_1.AbstractEntry));
  169. exports.AbstractItem = AbstractItem;
  170. //# sourceMappingURL=abstract_item.js.map