SelectableInfo.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.SelectableInfo = void 0;
  19. var info_js_1 = require("mj-context-menu/js/info.js");
  20. var html_classes_js_1 = require("mj-context-menu/js/html_classes.js");
  21. var SelectableInfo = (function (_super) {
  22. __extends(SelectableInfo, _super);
  23. function SelectableInfo() {
  24. return _super !== null && _super.apply(this, arguments) || this;
  25. }
  26. SelectableInfo.prototype.addEvents = function (element) {
  27. var _this = this;
  28. element.addEventListener('keypress', function (event) {
  29. if (event.key === 'a' && (event.ctrlKey || event.metaKey)) {
  30. _this.selectAll();
  31. _this.stop(event);
  32. }
  33. });
  34. };
  35. SelectableInfo.prototype.selectAll = function () {
  36. var selection = document.getSelection();
  37. selection.selectAllChildren(this.html.querySelector('pre'));
  38. };
  39. SelectableInfo.prototype.copyToClipboard = function () {
  40. this.selectAll();
  41. try {
  42. document.execCommand('copy');
  43. }
  44. catch (err) {
  45. alert('Can\'t copy to clipboard: ' + err.message);
  46. }
  47. document.getSelection().removeAllRanges();
  48. };
  49. SelectableInfo.prototype.generateHtml = function () {
  50. var _this = this;
  51. _super.prototype.generateHtml.call(this);
  52. var footer = this.html.querySelector('span.' + html_classes_js_1.HtmlClasses['INFOSIGNATURE']);
  53. var button = footer.appendChild(document.createElement('input'));
  54. button.type = 'button';
  55. button.value = 'Copy to Clipboard';
  56. button.addEventListener('click', function (_event) { return _this.copyToClipboard(); });
  57. };
  58. return SelectableInfo;
  59. }(info_js_1.Info));
  60. exports.SelectableInfo = SelectableInfo;
  61. //# sourceMappingURL=SelectableInfo.js.map