item_combo.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.Combo = void 0;
  17. var abstract_variable_item_js_1 = require("./abstract_variable_item.js");
  18. var menu_util_js_1 = require("./menu_util.js");
  19. var html_classes_js_1 = require("./html_classes.js");
  20. var key_navigatable_js_1 = require("./key_navigatable.js");
  21. var Combo = (function (_super) {
  22. __extends(Combo, _super);
  23. function Combo(menu, content, variable, id) {
  24. var _this = _super.call(this, menu, 'combobox', content, id) || this;
  25. _this.role = 'combobox';
  26. _this.inputEvent = false;
  27. _this.variable = menu.pool.lookup(variable);
  28. _this.register();
  29. return _this;
  30. }
  31. Combo.fromJson = function (_factory, _a, menu) {
  32. var content = _a.content, variable = _a.variable, id = _a.id;
  33. return new this(menu, content, variable, id);
  34. };
  35. Combo.prototype.executeAction = function () {
  36. this.variable.setValue(this.input.value, menu_util_js_1.MenuUtil.getActiveElement(this));
  37. };
  38. Combo.prototype.space = function (event) {
  39. _super.prototype.space.call(this, event);
  40. menu_util_js_1.MenuUtil.close(this);
  41. };
  42. Combo.prototype.focus = function () {
  43. _super.prototype.focus.call(this);
  44. this.input.focus();
  45. };
  46. Combo.prototype.unfocus = function () {
  47. _super.prototype.unfocus.call(this);
  48. this.updateSpan();
  49. };
  50. Combo.prototype.generateHtml = function () {
  51. _super.prototype.generateHtml.call(this);
  52. var html = this.html;
  53. html.classList.add(html_classes_js_1.HtmlClasses['MENUCOMBOBOX']);
  54. };
  55. Combo.prototype.generateSpan = function () {
  56. this.span = document.createElement('span');
  57. this.span.classList.add(html_classes_js_1.HtmlClasses['MENUINPUTBOX']);
  58. this.input = document.createElement('input');
  59. this.input.addEventListener('keydown', this.inputKey.bind(this));
  60. this.input.setAttribute('size', '10em');
  61. this.input.setAttribute('type', 'text');
  62. this.input.setAttribute('tabindex', '-1');
  63. this.span.appendChild(this.input);
  64. };
  65. Combo.prototype.inputKey = function (_event) {
  66. this.bubbleKey();
  67. this.inputEvent = true;
  68. };
  69. Combo.prototype.keydown = function (event) {
  70. if (this.inputEvent &&
  71. event.keyCode !== key_navigatable_js_1.KEY.ESCAPE &&
  72. event.keyCode !== key_navigatable_js_1.KEY.RETURN) {
  73. this.inputEvent = false;
  74. event.stopPropagation();
  75. return;
  76. }
  77. _super.prototype.keydown.call(this, event);
  78. event.stopPropagation();
  79. };
  80. Combo.prototype.updateAria = function () { };
  81. Combo.prototype.updateSpan = function () {
  82. var initValue;
  83. try {
  84. initValue = this.variable.getValue(menu_util_js_1.MenuUtil.getActiveElement(this));
  85. }
  86. catch (e) {
  87. initValue = '';
  88. }
  89. this.input.value = initValue;
  90. };
  91. Combo.prototype.toJson = function () {
  92. return { type: ''
  93. };
  94. };
  95. return Combo;
  96. }(abstract_variable_item_js_1.AbstractVariableItem));
  97. exports.Combo = Combo;
  98. //# sourceMappingURL=item_combo.js.map