feedback.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. var feedbackNode = null
  2. if (!global.p5VendorJs) throw "Missing vendor.js!";
  3. if (!html2canvas) throw "Missing html2canvas!";
  4. var h = global.p5VendorJs.React.createElement;
  5. var ReactDOM = global.p5VendorJs.ReactDOM;
  6. var createReactClass = global.p5VendorJs.createReactClass;
  7. // echo UI:: h('div', [
  8. // 'style' => "position:fixed; width:20px; height:20px; right:5px; bottom:5px; cursor:pointer; z-index:1041",
  9. // ], [
  10. // UI:: h('i', [
  11. // 'class' => "glyphicon glyphicon-camera",
  12. // 'style' => "color:#666",
  13. // 'onClick' => "p5UI__feedback(event)"
  14. // ])
  15. // ]);
  16. (function () {
  17. var node = document.createElement('div')
  18. node.style.position = 'fixed';
  19. node.style.width = '20px';
  20. node.style.height = '20px';
  21. node.style.right = '5px';
  22. node.style.bottom = '5px';
  23. node.style.cursor = 'pointer';
  24. node.style.zIndex = '1041';
  25. var feedbackBtn = document.createElement('i')
  26. feedbackBtn.style.color = "#666";
  27. feedbackBtn.setAttribute('onClick', "p5UI__feedback(event)");
  28. feedbackBtn.setAttribute('class', "glyphicon glyphicon-camera");
  29. node.appendChild(feedbackBtn);
  30. document.body.appendChild(node);
  31. })();
  32. function p5UI__feedback(event) {
  33. event.stopPropagation()
  34. event.preventDefault()
  35. console.log('DBG:p5UI__feedback', { target: event.target });
  36. if (feedbackNode) hideFeedback();
  37. else {
  38. makeScreenshot().then(function (pngDataUrl) {
  39. showFeedback(pngDataUrl);
  40. }).catch(function (err) {
  41. console.log('Error: ', err);
  42. })
  43. }
  44. }
  45. function showFeedback(pngDataUrl) {
  46. feedbackNode = document.createElement('div')
  47. feedbackNode.style.position = 'absolute';
  48. feedbackNode.style.top = '0px';
  49. feedbackNode.style.left = '0px';
  50. feedbackNode.style.width = '' + document.documentElement.clientWidth + 'px';
  51. var bodyHeight = Math.max(
  52. document.body.scrollHeight, document.body.offsetHeight,
  53. document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight
  54. );
  55. feedbackNode.style.height = '' + bodyHeight + 'px';
  56. feedbackNode.style.zIndex = '2';
  57. feedbackNode.style.backgroundColor = '#eee';
  58. document.body.appendChild(feedbackNode)
  59. ReactDOM.render(
  60. h(p5UI__feedbackBox, {
  61. pngDataUrl: pngDataUrl,
  62. // nameSection: nameSection,
  63. // store: globalGraphStore,
  64. // actions: globalGraphActions,
  65. }),
  66. feedbackNode
  67. );
  68. }
  69. function hideFeedback() {
  70. if (!feedbackNode) return false;
  71. document.body.removeChild(feedbackNode)
  72. feedbackNode = null;
  73. }
  74. function makeScreenshot() {
  75. return new Promise((resolve, reject) => {
  76. var node = document.querySelector('body');
  77. html2canvas(node, {
  78. onrendered: (canvas) => {
  79. let pngUrl = canvas.toDataURL();
  80. resolve(pngUrl);
  81. }
  82. });
  83. });
  84. }
  85. var p5UI__feedbackBox = createReactClass({
  86. sendFeedback: function () {
  87. console.log('TODO: send feedback...');
  88. },
  89. close: function () {
  90. hideFeedback();
  91. },
  92. render: function () {
  93. return h('div', {
  94. style: {
  95. width: '100%',
  96. height: '100%',
  97. }
  98. }, [
  99. h('form', { onSubmit: this.sendFeedback }, [
  100. h('table', {
  101. style: { width: "100%",
  102. backgroundColor: "#eee",
  103. borderBottom: "2px solid #ccc",
  104. }
  105. }, [
  106. h('tr', {}, [
  107. // h('td', { style: { padding: "2px 12px" } }, [
  108. // h('h1', {}, "Test..."),
  109. // ]),
  110. h('td', { style: { padding: "2px 12px", width: "10%" } }, [
  111. h('select', {}, [
  112. h('option', { value: "BUG" }, "Zgłoś błąd"),
  113. h('option', { value: "IDEA" }, "Zaproponuj zmianę/nową funkcjonalność"),
  114. h('option', { value: "DOC" }, "Dokumantacja"),
  115. ]),
  116. ]),
  117. h('td', { style: { padding: "2px 12px", width: "10%" } }, [
  118. h('textarea', { placeholder: "opis..." }),
  119. ]),
  120. h('td', { style: { padding: "2px 12px", width: "10%" } }, [
  121. h('button', { type: "submit" }, "Zapisz"),
  122. ]),
  123. h('td', { style: { padding: "2px 12px", textAlign: "right" } }, [
  124. h('i', { onClick: this.close, className: "glyphicon glyphicon-remove", style: { cursor: "pointer" } }),
  125. ]),
  126. ])
  127. ]),
  128. h('div', {
  129. style: {
  130. padding: "6px",
  131. textAlign: "center",
  132. backgroundColor: "#fff",
  133. }
  134. }, [
  135. h('img', {
  136. src: this.props.pngDataUrl,
  137. style: {
  138. width: '90%',
  139. border: "2px solid #ccc",
  140. }
  141. })
  142. ])
  143. ]),
  144. ]);
  145. }
  146. })
  147. global.p5UI__feedback = p5UI__feedback;