webpage.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. 'use strict';
  2. goog.provide('Blockly.Python.webpage');
  3. goog.require('Blockly.Python');
  4. /*
  5. sed 's/^/START/; s/$/END/' target.html >> target_NEW.html
  6. */
  7. Blockly.Python['webpage_label'] = function(block) {
  8. var code = "server.send(200, \"text/html\",\"";
  9. code += "<!DOCTYPE HTML><html><head><meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1, user-scalable=no\\\"> <meta http-equiv=\\\"refresh\\\" content=\\\"1\\\"> </head><style>body { font-family:Arial;padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; /* updated */ } .row { margin-left: auto; margin-right: auto; margin-bottom: 20px; text-align: center; } .label { font-size: 20px; line-height: 28px; } .value { font-weight: bolder !important; margin-left: 2px; padding: 5px 8px; border-radius: 5px; background-color: rgba(0,0,0,.025); border: 1px solid rgba(0,0,0,.15); } .header { padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto; } .content { padding: 20px 20px 20px 20px; } h1,h2,h3,h4,h5,h6 {font-weight: 500;line-height: 1.1;z-index: 1001;}p {margin-bottom: 10px;text-align: center;z-index: 1001;} </style> <body> <div> <div class='row'> <h1> CocoRobo IoT Project </h1> </div> <div class='row header'> <h2> Web Dashboard </h2></div><div class='content'>"
  10. for (var i = 0; i < block.itemCount_; i++) {
  11. var item_label = block.getFieldValue("LABLE" + i);
  12. var item_value = Blockly.Python.valueToCode(block, "ADD" + i, Blockly.Python.ORDER_ATOMIC);
  13. code += " <div class='row label'>" + item_label + ": <span class='value'>\"+String(" + item_value + ")+\"</span> </div>";
  14. }
  15. code += " </div></body></html>"
  16. code += "\")\n";
  17. return code;
  18. }
  19. Blockly.Python['webpage_button'] = function(block) {
  20. var code = "server.send(200, \"text/html\",\"";
  21. code += "<!DOCTYPE HTML><html><head><meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1, user-scalable=no\\\"></head><style>body { font-family:Arial;padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; /* updated */ } .row { margin-left: auto; margin-right: auto; font-weight: bolder !important; margin-bottom: 20px; text-align: center; z-index: 1001; } .header { padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto; } .content { padding: 20px 20px 20px 20px; } h1,h2,h3,h4,h5,h6 {font-weight: 500;line-height: 1.1;z-index: 1001;}p {margin-bottom: 10px;text-align: center;z-index: 1001;} .btn { font-weight: bolder; /* added */ border-radius: 5px; display: inline-block; height: 36px; line-height: 36px; padding: 0.5rem 2rem; text-decoration: none; color: #444; /* updated */ border: 1px solid rgba(0,0,0,.2); /* updated */ background-color: rgba(255, 255, 255, 0); /* updated */ text-align: center; text-transform: uppercase; vertical-align: middle; -webkit-tap-highlight-color: transparent; } .btn.disabled, .btn[disabled] { pointer-events: none; background-color: rgba(44, 79, 205, 1) !important; -webkit-box-shadow: none; box-shadow: none; color: #9F9F9F !important; cursor: default; } .btn:hover { background-color: rgba(44, 79, 205, 1); border-radius: 5px; border: 1px solid #2c4fcd; color: #fff; } .btn:before { border-radius: 0; }</style> <body> <div> <div class='row'> <h1> CocoRobo IoT Project </h1> </div> <div class='row header'> <h2> Web Dashboard </h2></div> <div class='content'>"
  22. for (let i = 0; i < block.itemCount_; i++) {
  23. var url = block.getFieldValue("URL" + i);
  24. // url = url.replace(/\"/g, "");
  25. url = "http://192.168.4.1" + url;
  26. var button = block.getFieldValue("BUTTON" + i);
  27. code += " <div class='row'><a class='btn' onclick=\\\"clickBtn('" + url + "', '" + button + "')\\\">" + button + "</a></div>"
  28. }
  29. code += "</div> </body> <script> function clickBtn(url_ , btn) { var content = {'data':[ btn]};var contentTo_ = JSON.stringify(content);var xhr = new XMLHttpRequest();xhr.open('POST', url_);xhr.setRequestHeader('content-type','application/json'); xhr.send(contentTo_);}</script></html>"
  30. code += "\")\n";
  31. return code;
  32. }
  33. Blockly.Python['webpage_colorpicker'] = function(block) {
  34. var text_webpage_colorpicker_path = block.getFieldValue('webpage_colorpicker_path');
  35. var code = "server.send(200, \"text/html\", htmlContent())\n";
  36. Blockly.Python.addFunction("webpage_colorpicker-string", "" +
  37. "String htmlContent() {\n" +
  38. " String data = \"<!DOCTYPE HTML><html><head> <meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1, user-scalable=no\\\"></head><style>.color-picker,.color-picker *,.color-picker ::after,.color-picker ::before,.color-picker::after,.color-picker::before{box-sizing: border-box}.color-picker{position: absolute; top: 0; left: 0; z-index: 9999; box-shadow: 1px 5px 10px rgba(0, 0, 0, .5)}.color-picker-container{direction: rtl; display: flex; height: 10em; border: 1px solid #000; color: #000}.color-picker-container *{border-color: inherit; color: inherit}.color-picker i{font: inherit; font-size: 12px}.color-picker-h,.color-picker-sv{direction: ltr; background-size: 100% 100%; position: relative}.color-picker-h{width: 1.5em; border-left: 1px solid; background: transparent url(color-picker-h.png) no-repeat 50% 50%; background-image: linear-gradient(to top, red 0, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%); cursor: ns-resize; overflow: hidden}.color-picker-h i{display: block; height: .5em; position: absolute; top: -.25em; right: 0; left: 0; z-index: 3}.color-picker-h i::before{display: block; content: \\\"\\\"; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border: .25em solid; border-top-color: transparent; border-bottom-color: transparent}.color-picker-sv{width: 10em; background: transparent url(color-picker-sv.png) no-repeat 50% 50%; background-image: linear-gradient(to top, #000, rgba(0, 0, 0, 0)), linear-gradient(to right, #fff, rgba(255, 255, 255, 0)); cursor: crosshair}.color-picker-sv i{display: block; width: .8em; height: .8em; position: absolute; top: -.4em; right: -.4em; z-index: 3}.color-picker-sv i::after,.color-picker-sv i::before{display: block; content: \\\"\\\"; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border: 1px solid; border-color: inherit; border-radius: 100%}.color-picker-sv i::before{top: -1px; right: -1px; bottom: -1px; left: -1px; border-color: #fff}.color-picker-h,.color-picker-sv{-webkit-touch-callout: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent}#color-picker-show{text-align:center; display: inline-block; margin: auto 27% 10px 26.5%; background-color: rgb(255,0,0); height:180px; width:47%; border: 1px solid rgba(0,0,0,.1); -webkit-box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.36); -moz-box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.36); box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.36);}#color-picker-header{font-size:18px; margin-bottom:-2px; font-weight: bolder;}input[type=\\\"text\\\"]{font-size: 18px; width: 185px; padding: 10px auto; margin-left: 10px; border: 1px solid rgba(0,0,0,.2); text-align:center;}</style><style>body{font-family: Arial; padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; /* updated */}.row{margin-left: auto; margin-right: auto; font-weight: bolder !important; margin-bottom: 20px; text-align: center; z-index: 1001;}.header{padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto;}.content{padding: 20px 20px 20px 20px;}h1,h2,h3,h4,h5,h6{font-weight: 500; line-height: 1.1; z-index: 1001;}p{margin-bottom: 10px; text-align: center; z-index: 1001;}.btn{font-weight: bolder; /* added */ border-radius: 5px; display: inline-block; height: 36px; line-height: 36px; padding: 0.5rem 2rem; text-decoration: none; color: #444; /* updated */ border: 1px solid rgba(0, 0, 0, .2); /* updated */ background-color: rgba(255, 255, 255, 0); /* updated */ text-align: center; text-transform: uppercase; vertical-align: middle; -webkit-tap-highlight-color: transparent;}.btn.disabled,.btn[disabled]{pointer-events: none; background-color: rgba(44, 79, 205, 1) !important; -webkit-box-shadow: none; box-shadow: none; color: #9F9F9F !important; cursor: default;}.btn:hover{background-color: rgba(44, 79, 205, 1); border-radius: 5px; border: 1px solid #2c4fcd; color: #fff;}.btn:before{border-radius: 0;}</style><body> <div> <div class='row navbar'> <h1> CocoRobo IoT Project </h1> </div><div class='row header'> <h2> Web Dashboard </h2> </div><div class='content'> <div id=\\\"color-picker-show\\\"></div><p id=\\\"color-picker-header\\\">Pick a color below: (in RGB)</p><p> <input type=\\\"text\\\" readonly=\\\"true\\\"/> </p></div></body>\"\n" +
  39. " data += \"<script>\"; data += \"\\r\\n\"\n" +
  40. " data += \"! function(t, n, e) {\"; data += \"\\r\\n\"\n" +
  41. " data += \" function r(t) { return void 0 !== t }\"; data += \"\\r\\n\"\n" +
  42. " data += \"\"; data += \"\\r\\n\"\n" +
  43. " data += \" function i(t) { return \\\"string\\\" == typeof t }\"; data += \"\\r\\n\"\n" +
  44. " data += \"\"; data += \"\\r\\n\"\n" +
  45. " data += \" function o(t) { return \\\"object\\\" == typeof t }\"; data += \"\\r\\n\"\n" +
  46. " data += \"\"; data += \"\\r\\n\"\n" +
  47. " data += \" function u(t) { return Object.keys(t).length }\"; data += \"\\r\\n\"\n" +
  48. " data += \"\"; data += \"\\r\\n\"\n" +
  49. " data += \" function c(t, n, e) { return n > t ? n : t > e ? e : t }\"; data += \"\\r\\n\"\n" +
  50. " data += \"\"; data += \"\\r\\n\"\n" +
  51. " data += \" function s(t, n) { return parseInt(t, n || 10) }\"; data += \"\\r\\n\"\n" +
  52. " data += \"\"; data += \"\\r\\n\"\n" +
  53. " data += \" function a(t) { return Math.round(t) }\"; data += \"\\r\\n\"\n" +
  54. " data += \"\"; data += \"\\r\\n\"\n" +
  55. " data += \" function f(t) {\"; data += \"\\r\\n\"\n" +
  56. " data += \" var n, e, r, i, o, u, c, s, f = +t[0],\"; data += \"\\r\\n\"\n" +
  57. " data += \" l = +t[1],\"; data += \"\\r\\n\"\n" +
  58. " data += \" h = +t[2];\"; data += \"\\r\\n\"\n" +
  59. " data += \" switch (i = Math.floor(6 * f), o = 6 * f - i, u = h * (1 - l), c = h * (1 - o * l), s = h * (1 - (1 - o) * l), i = i || 0, c = c || 0, s = s || 0, i % 6) {\"; data += \"\\r\\n\"\n" +
  60. " data += \" case 0:\"; data += \"\\r\\n\"\n" +
  61. " data += \" n = h, e = s, r = u;\"; data += \"\\r\\n\"\n" +
  62. " data += \" break;\"; data += \"\\r\\n\"\n" +
  63. " data += \" case 1:\"; data += \"\\r\\n\"\n" +
  64. " data += \" n = c, e = h, r = u;\"; data += \"\\r\\n\"\n" +
  65. " data += \" break;\"; data += \"\\r\\n\"\n" +
  66. " data += \" case 2:\"; data += \"\\r\\n\"\n" +
  67. " data += \" n = u, e = h, r = s;\"; data += \"\\r\\n\"\n" +
  68. " data += \" break;\"; data += \"\\r\\n\"\n" +
  69. " data += \" case 3:\"; data += \"\\r\\n\"\n" +
  70. " data += \" n = u, e = c, r = h;\"; data += \"\\r\\n\"\n" +
  71. " data += \" break;\"; data += \"\\r\\n\"\n" +
  72. " data += \" case 4:\"; data += \"\\r\\n\"\n" +
  73. " data += \" n = s, e = u, r = h;\"; data += \"\\r\\n\"\n" +
  74. " data += \" break;\"; data += \"\\r\\n\"\n" +
  75. " data += \" case 5:\"; data += \"\\r\\n\"\n" +
  76. " data += \" n = h, e = u, r = c\"; data += \"\\r\\n\"\n" +
  77. " data += \" }\"; data += \"\\r\\n\"\n" +
  78. " data += \" return [a(255 * n), a(255 * e), a(255 * r)]\"; data += \"\\r\\n\"\n" +
  79. " data += \" }\"; data += \"\\r\\n\"\n" +
  80. " data += \"\"; data += \"\\r\\n\"\n" +
  81. " data += \" function l(t) { return p(f(t)) }\"; data += \"\\r\\n\"\n" +
  82. " data += \"\"; data += \"\\r\\n\"\n" +
  83. " data += \" function h(t) {\"; data += \"\\r\\n\"\n" +
  84. " data += \" var n, e = +t[0],\"; data += \"\\r\\n\"\n" +
  85. " data += \" r = +t[1],\"; data += \"\\r\\n\"\n" +
  86. " data += \" i = +t[2],\"; data += \"\\r\\n\"\n" +
  87. " data += \" o = Math.max(e, r, i),\"; data += \"\\r\\n\"\n" +
  88. " data += \" u = Math.min(e, r, i),\"; data += \"\\r\\n\"\n" +
  89. " data += \" c = o - u,\"; data += \"\\r\\n\"\n" +
  90. " data += \" s = 0 === o ? 0 : c / o,\"; data += \"\\r\\n\"\n" +
  91. " data += \" a = o / 255;\"; data += \"\\r\\n\"\n" +
  92. " data += \" switch (o) {\"; data += \"\\r\\n\"\n" +
  93. " data += \" case u:\"; data += \"\\r\\n\"\n" +
  94. " data += \" n = 0;\"; data += \"\\r\\n\"\n" +
  95. " data += \" break;\"; data += \"\\r\\n\"\n" +
  96. " data += \" case e:\"; data += \"\\r\\n\"\n" +
  97. " data += \" n = r - i + c * (i > r ? 6 : 0), n /= 6 * c;\"; data += \"\\r\\n\"\n" +
  98. " data += \" break;\"; data += \"\\r\\n\"\n" +
  99. " data += \" case r:\"; data += \"\\r\\n\"\n" +
  100. " data += \" n = i - e + 2 * c, n /= 6 * c;\"; data += \"\\r\\n\"\n" +
  101. " data += \" break;\"; data += \"\\r\\n\"\n" +
  102. " data += \" case i:\"; data += \"\\r\\n\"\n" +
  103. " data += \" n = e - r + 4 * c, n /= 6 * c\"; data += \"\\r\\n\"\n" +
  104. " data += \" }\"; data += \"\\r\\n\"\n" +
  105. " data += \" return [n, s, a]\"; data += \"\\r\\n\"\n" +
  106. " data += \" }\"; data += \"\\r\\n\"\n" +
  107. " data += \"\"; data += \"\\r\\n\"\n" +
  108. " data += \" function p(t) { var n = +t[2] | +t[1] << 8 | +t[0] << 16; return n = \\\"000000\\\" + n.toString(16), n.slice(-6) }\"; data += \"\\r\\n\"\n" +
  109. " data += \"\"; data += \"\\r\\n\"\n" +
  110. " data += \" function v(t) { return h(d(t)) }\"; data += \"\\r\\n\"\n" +
  111. " data += \"\"; data += \"\\r\\n\"\n" +
  112. " data += \" function d(t) { return 3 === t.length && (t = t.replace(/./g, \\\"$&$&\\\")), [s(t[0] + t[1], 16), s(t[2] + t[3], 16), s(t[4] + t[5], 16)] }\"; data += \"\\r\\n\"\n" +
  113. " data += \"\"; data += \"\\r\\n\"\n" +
  114. " data += \" function g(t) { return [+t[0] / 360, +t[1] / 100, +t[2] / 100] }\"; data += \"\\r\\n\"\n" +
  115. " data += \"\"; data += \"\\r\\n\"\n" +
  116. " data += \" function y(t) { return [a(360 * +t[0]), a(100 * +t[1]), a(100 * +t[2])] }\"; data += \"\\r\\n\"\n" +
  117. " data += \"\"; data += \"\\r\\n\"\n" +
  118. " data += \" function x(t) { return [+t[0] / 255, +t[1] / 255, +t[2] / 255] }\"; data += \"\\r\\n\"\n" +
  119. " data += \"\"; data += \"\\r\\n\"\n" +
  120. " data += \" function H(t) {\"; data += \"\\r\\n\"\n" +
  121. " data += \" if (o(t)) return t;\"; data += \"\\r\\n\"\n" +
  122. " data += \" var n = /\\\\s*rgb\\\\s*\\\\\(\\\\s*(\\\\d+)\\\\s*,\\\\s*(\\\\d+)\\\\s*,\\\\s*(\\\\d+)\\\\s*\\\\\)\\\\s*$/i.exec(t),\"; data += \"\\r\\n\"\n" +
  123. " data += \" e = /\\\\s*hsv\\\\s*\\\\\(\\\\s*(\\\\d+)\\\\s*,\\\\s*(\\\\d+)%\\\\s*,\\\\s*(\\\\d+)%\\\\s*\\\\\)\\\\s*$/i.exec(t),\"; data += \"\\r\\n\"\n" +
  124. " data += \" r = \\\"#\\\" === t[0] && t.match(/^#([\\\\da-f]{3}|[\\\\da-f]{6})$/i);\"; data += \"\\r\\n\"\n" +
  125. " data += \" return r ? v(t.slice(1)) : e ? g([+e[1], +e[2], +e[3]]) : n ? h([+n[1], +n[2], +n[3]]) : [0, 1, 1]\"; data += \"\\r\\n\"\n" +
  126. " data += \" }\"; data += \"\\r\\n\"\n" +
  127. " data += \" var b = \\\"__instance__\\\",\"; data += \"\\r\\n\"\n" +
  128. " data += \" m = \\\"firstChild\\\",\"; data += \"\\r\\n\"\n" +
  129. " data += \" k = setTimeout;\"; data += \"\\r\\n\"\n" +
  130. " data += \" ! function(t) { t.version = \\\"1.4.2\\\", t[b] = {}, t.each = function(n, e) { return k(function() { var e, r = t[b]; for (e in r) n.call(r[e], e, r) }, 0 === e ? 0 : e || 1), t }, t.parse = H, t._HSV2RGB = f, t._HSV2HEX = l, t._RGB2HSV = h, t._HEX2HSV = v, t._HEX2RGB = function(t) { return x(d(t)) }, t.HSV2RGB = function(t) { return f(g(t)) }, t.HSV2HEX = function(t) { return l(g(t)) }, t.RGB2HSV = function(t) { return y(h(t)) }, t.RGB2HEX = p, t.HEX2HSV = function(t) { return y(v(t)) }, t.HEX2RGB = d }(t[e] = function(s, a, h) {\"; data += \"\\r\\n\"\n" +
  131. " data += \" function p(t, n, e) { t = t.split(/\\\\s+/); for (var r = 0, i = t.length; i > r; ++r) n.addEventListener(t[r], e, !1) }\"; data += \"\\r\\n\"\n" +
  132. " data += \"\"; data += \"\\r\\n\"\n" +
  133. " data += \" function v(t, n, e) { t = t.split(/\\\\s+/); for (var r = 0, i = t.length; i > r; ++r) n.removeEventListener(t[r], e) }\"; data += \"\\r\\n\"\n" +
  134. " data += \"\"; data += \"\\r\\n\"\n" +
  135. " data += \" function d(t, n) {\"; data += \"\\r\\n\"\n" +
  136. " data += \" var e = \\\"touches\\\",\"; data += \"\\r\\n\"\n" +
  137. " data += \" r = \\\"clientX\\\",\"; data += \"\\r\\n\"\n" +
  138. " data += \" i = \\\"clientY\\\",\"; data += \"\\r\\n\"\n" +
  139. " data += \" o = n[e] ? n[e][0][r] : n[r],\"; data += \"\\r\\n\"\n" +
  140. " data += \" u = n[e] ? n[e][0][i] : n[i],\"; data += \"\\r\\n\"\n" +
  141. " data += \" c = g(t);\"; data += \"\\r\\n\"\n" +
  142. " data += \" return { x: o - c.l, y: u - c.t }\"; data += \"\\r\\n\"\n" +
  143. " data += \" }\"; data += \"\\r\\n\"\n" +
  144. " data += \"\"; data += \"\\r\\n\"\n" +
  145. " data += \" function g(n) { var e, r, i; return n === t ? (e = t.pageXOffset || M.scrollLeft, r = t.pageYOffset || M.scrollTop) : (i = n.getBoundingClientRect(), e = i.left, r = i.top), { l: e, t: r } }\"; data += \"\\r\\n\"\n" +
  146. " data += \"\"; data += \"\\r\\n\"\n" +
  147. " data += \" function y(t, n) {\"; data += \"\\r\\n\"\n" +
  148. " data += \" for (;\"; data += \"\\r\\n\"\n" +
  149. " data += \" (t = t.parentElement) && t !== n;);\"; data += \"\\r\\n\"\n" +
  150. " data += \" return t\"; data += \"\\r\\n\"\n" +
  151. " data += \" }\"; data += \"\\r\\n\"\n" +
  152. " data += \"\"; data += \"\\r\\n\"\n" +
  153. " data += \" function x(t) { t && t.preventDefault() }\"; data += \"\\r\\n\"\n" +
  154. " data += \"\"; data += \"\\r\\n\"\n" +
  155. " data += \" function H(n) { return n === t ? { w: t.innerWidth, h: t.innerHeight } : { w: n.offsetWidth, h: n.offsetHeight } }\"; data += \"\\r\\n\"\n" +
  156. " data += \"\"; data += \"\\r\\n\"\n" +
  157. " data += \" function w(t) { return j || (r(t) ? t : !1) }\"; data += \"\\r\\n\"\n" +
  158. " data += \"\"; data += \"\\r\\n\"\n" +
  159. " data += \" function E(t) { j = t }\"; data += \"\\r\\n\"\n" +
  160. " data += \"\"; data += \"\\r\\n\"\n" +
  161. " data += \" function S(t, n, e) { return r(t) ? r(n) ? (r(O[t]) || (O[t] = {}), r(e) || (e = u(O[t])), O[t][e] = n, $) : O[t] : O }\"; data += \"\\r\\n\"\n" +
  162. " data += \"\"; data += \"\\r\\n\"\n" +
  163. " data += \" function X(t, n) { return r(t) ? r(n) ? (delete O[t][n], $) : (O[t] = {}, $) : (O = {}, $) }\"; data += \"\\r\\n\"\n" +
  164. " data += \"\"; data += \"\\r\\n\"\n" +
  165. " data += \" function _(t, n, e) {\"; data += \"\\r\\n\"\n" +
  166. " data += \" if (!r(O[t])) return $;\"; data += \"\\r\\n\"\n" +
  167. " data += \" if (r(e)) r(O[t][e]) && O[t][e].apply($, n);\"; data += \"\\r\\n\"\n" +
  168. " data += \" else\"; data += \"\\r\\n\"\n" +
  169. " data += \" for (var i in O[t]) O[t][i].apply($, n);\"; data += \"\\r\\n\"\n" +
  170. " data += \" return $\"; data += \"\\r\\n\"\n" +
  171. " data += \" }\"; data += \"\\r\\n\"\n" +
  172. " data += \"\"; data += \"\\r\\n\"\n" +
  173. " data += \" function B(t, n) { t && \\\"h\\\" !== t || _(\\\"change:h\\\", n), t && \\\"sv\\\" !== t || _(\\\"change:sv\\\", n), _(\\\"change\\\", n) }\"; data += \"\\r\\n\"\n" +
  174. " data += \"\"; data += \"\\r\\n\"\n" +
  175. " data += \" function R() { return T.parentNode }\"; data += \"\\r\\n\"\n" +
  176. " data += \"\"; data += \"\\r\\n\"\n" +
  177. " data += \" function V(e, r) {\"; data += \"\\r\\n\"\n" +
  178. " data += \" function i(t) {\"; data += \"\\r\\n\"\n" +
  179. " data += \" var n = t.target,\"; data += \"\\r\\n\"\n" +
  180. " data += \" e = n === s || y(n, s) === s;\"; data += \"\\r\\n\"\n" +
  181. " data += \" e ? !R() && (V(), _(\\\"enter\\\")) : $.exit()\"; data += \"\\r\\n\"\n" +
  182. " data += \" }\"; data += \"\\r\\n\"\n" +
  183. " data += \"\"; data += \"\\r\\n\"\n" +
  184. " data += \" function o(t) {\"; data += \"\\r\\n\"\n" +
  185. " data += \" var n = (f(I), f([I[0], 1, 1]));\"; data += \"\\r\\n\"\n" +
  186. " data += \" q.style.backgroundColor = \\\"rgb(\\\" + n.join(\\\",\\\") + \\\")\\\", E(I), x(t)\"; data += \"\\r\\n\"\n" +
  187. " data += \" }\"; data += \"\\r\\n\"\n" +
  188. " data += \"\"; data += \"\\r\\n\"\n" +
  189. " data += \" function u(t) {\"; data += \"\\r\\n\"\n" +
  190. " data += \" var n = c(d(P, t).y, 0, L);\"; data += \"\\r\\n\"\n" +
  191. " data += \" I[0] = (L - n) / L, F.style.top = n - D / 2 + \\\"px\\\", o(t)\"; data += \"\\r\\n\"\n" +
  192. " data += \" }\"; data += \"\\r\\n\"\n" +
  193. " data += \"\"; data += \"\\r\\n\"\n" +
  194. " data += \" function g(t) {\"; data += \"\\r\\n\"\n" +
  195. " data += \" var n = d(q, t),\"; data += \"\\r\\n\"\n" +
  196. " data += \" e = c(n.x, 0, j),\"; data += \"\\r\\n\"\n" +
  197. " data += \" r = c(n.y, 0, O);\"; data += \"\\r\\n\"\n" +
  198. " data += \" I[1] = 1 - (j - e) / j, I[2] = (O - r) / O, J.style.right = j - e - tn / 2 + \\\"px\\\", J.style.top = r - nn / 2 + \\\"px\\\", o(t)\"; data += \"\\r\\n\"\n" +
  199. " data += \" }\"; data += \"\\r\\n\"\n" +
  200. " data += \"\"; data += \"\\r\\n\"\n" +
  201. " data += \" function b(t) { U && (u(t), on = [l(I)], K || (_(\\\"drag:h\\\", on), _(\\\"drag\\\", on), B(\\\"h\\\", on))), Z && (g(t), on = [l(I)], Q || (_(\\\"drag:sv\\\", on), _(\\\"drag\\\", on), B(\\\"sv\\\", on))), K = 0, Q = 0 }\"; data += \"\\r\\n\"\n" +
  202. " data += \"\"; data += \"\\r\\n\"\n" +
  203. " data += \" function m(t) {\"; data += \"\\r\\n\"\n" +
  204. " data += \" var n = t.target,\"; data += \"\\r\\n\"\n" +
  205. " data += \" e = U ? \\\"h\\\" : \\\"sv\\\",\"; data += \"\\r\\n\"\n" +
  206. " data += \" r = [l(I), $],\"; data += \"\\r\\n\"\n" +
  207. " data += \" i = n === s || y(n, s) === s,\"; data += \"\\r\\n\"\n" +
  208. " data += \" o = n === T || y(n, T) === T;\"; data += \"\\r\\n\"\n" +
  209. " data += \" i || o ? o && (_(\\\"stop:\\\" + e, r), _(\\\"stop\\\", r), B(e, r)) : R() && a !== !1 && ($.exit(), B(0, r)), U = 0, Z = 0\"; data += \"\\r\\n\"\n" +
  210. " data += \" }\"; data += \"\\r\\n\"\n" +
  211. " data += \"\"; data += \"\\r\\n\"\n" +
  212. " data += \" function k(t) { K = 1, U = 1, b(t), x(t), _(\\\"start:h\\\", on), _(\\\"start\\\", on), B(\\\"h\\\", on) }\"; data += \"\\r\\n\"\n" +
  213. " data += \"\"; data += \"\\r\\n\"\n" +
  214. " data += \" function S(t) { Q = 1, Z = 1, b(t), x(t), _(\\\"start:sv\\\", on), _(\\\"start\\\", on), B(\\\"sv\\\", on) } e || ((h || r || C).appendChild(T), $.visible = !0), en = H(T).w, rn = H(T).h;\"; data += \"\\r\\n\"\n" +
  215. " data += \" var X = H(q),\"; data += \"\\r\\n\"\n" +
  216. " data += \" M = H(J),\"; data += \"\\r\\n\"\n" +
  217. " data += \" L = H(P).h,\"; data += \"\\r\\n\"\n" +
  218. " data += \" j = X.w,\"; data += \"\\r\\n\"\n" +
  219. " data += \" O = X.h,\"; data += \"\\r\\n\"\n" +
  220. " data += \" D = H(F).h,\"; data += \"\\r\\n\"\n" +
  221. " data += \" tn = M.w,\"; data += \"\\r\\n\"\n" +
  222. " data += \" nn = M.h;\"; data += \"\\r\\n\"\n" +
  223. " data += \" e ? (T.style.left = T.style.top = \\\"-9999px\\\", a !== !1 && p(a, s, i), $.create = function() { return V(1), _(\\\"create\\\"), $ }, $.destroy = function() { return a !== !1 && v(a, s, i), $.exit(), E(!1), _(\\\"destroy\\\"), $ }) : G(), A = function() { I = w(I), o(), F.style.top = L - D / 2 - L * +I[0] + \\\"px\\\", J.style.right = j - tn / 2 - j * +I[1] + \\\"px\\\", J.style.top = O - nn / 2 - O * +I[2] + \\\"px\\\" }, $.exit = function() { var e = R(); return e && (e.removeChild(T), $.visible = !1), v(N, P, k), v(N, q, S), v(W, n, b), v(Y, n, m), v(z, t, G), _(\\\"exit\\\"), $ }, A(), e || (p(N, P, k), p(N, q, S), p(W, n, b), p(Y, n, m), p(z, t, G))\"; data += \"\\r\\n\"\n" +
  224. " data += \" }\"; data += \"\\r\\n\"\n" +
  225. " data += \"\"; data += \"\\r\\n\"\n" +
  226. " data += \" function G() { return $.fit() }\"; data += \"\\r\\n\"\n" +
  227. " data += \" var C = n.body,\"; data += \"\\r\\n\"\n" +
  228. " data += \" M = n.documentElement,\"; data += \"\\r\\n\"\n" +
  229. " data += \" $ = this,\"; data += \"\\r\\n\"\n" +
  230. " data += \" L = t[e],\"; data += \"\\r\\n\"\n" +
  231. " data += \" j = !1,\"; data += \"\\r\\n\"\n" +
  232. " data += \" O = {},\"; data += \"\\r\\n\"\n" +
  233. " data += \" T = n.createElement(\\\"div\\\"),\"; data += \"\\r\\n\"\n" +
  234. " data += \" N = \\\"touchstart mousedown\\\",\"; data += \"\\r\\n\"\n" +
  235. " data += \" W = \\\"touchmove mousemove\\\",\"; data += \"\\r\\n\"\n" +
  236. " data += \" Y = \\\"touchend mouseup\\\",\"; data += \"\\r\\n\"\n" +
  237. " data += \" z = \\\"orientationchange resize\\\";\"; data += \"\\r\\n\"\n" +
  238. " data += \" if (!($ instanceof L)) return new L(s, a);\"; data += \"\\r\\n\"\n" +
  239. " data += \" L[b][s.id || s.name || u(L[b])] = $, r(a) && a !== !0 || (a = N), E(L.parse(s.getAttribute(\\\"data-color\\\") || s.value || [0, 1, 1])), T.className = \\\"color-picker\\\", T.innerHTML = '<div class=\\\"color-picker-container\\\"><span class=\\\"color-picker-h\\\"><i></i></span><span class=\\\"color-picker-sv\\\"><i></i></span></div>';\"; data += \"\\r\\n\"\n" +
  240. " data += \" var A, D = T[m].children,\"; data += \"\\r\\n\"\n" +
  241. " data += \" I = w([0, 1, 1]),\"; data += \"\\r\\n\"\n" +
  242. " data += \" P = D[0],\"; data += \"\\r\\n\"\n" +
  243. " data += \" q = D[1],\"; data += \"\\r\\n\"\n" +
  244. " data += \" F = P[m],\"; data += \"\\r\\n\"\n" +
  245. " data += \" J = q[m],\"; data += \"\\r\\n\"\n" +
  246. " data += \" K = 0,\"; data += \"\\r\\n\"\n" +
  247. " data += \" Q = 0,\"; data += \"\\r\\n\"\n" +
  248. " data += \" U = 0,\"; data += \"\\r\\n\"\n" +
  249. " data += \" Z = 0,\"; data += \"\\r\\n\"\n" +
  250. " data += \" tn = 0,\"; data += \"\\r\\n\"\n" +
  251. " data += \" nn = 0,\"; data += \"\\r\\n\"\n" +
  252. " data += \" en = 0,\"; data += \"\\r\\n\"\n" +
  253. " data += \" rn = 0,\"; data += \"\\r\\n\"\n" +
  254. " data += \" on = [l(I)];\"; data += \"\\r\\n\"\n" +
  255. " data += \" return V(1), k(function() {\"; data += \"\\r\\n\"\n" +
  256. " data += \" var t = [l(I)];\"; data += \"\\r\\n\"\n" +
  257. " data += \" _(\\\"create\\\", t), B(0, t)\"; data += \"\\r\\n\"\n" +
  258. " data += \" }, 0), $.fit = function(n) {\"; data += \"\\r\\n\"\n" +
  259. " data += \" var e = H(t),\"; data += \"\\r\\n\"\n" +
  260. " data += \" i = H(M),\"; data += \"\\r\\n\"\n" +
  261. " data += \" u = e.w - i.w,\"; data += \"\\r\\n\"\n" +
  262. " data += \" a = e.h - M.clientHeight,\"; data += \"\\r\\n\"\n" +
  263. " data += \" f = g(t),\"; data += \"\\r\\n\"\n" +
  264. " data += \" l = g(s);\"; data += \"\\r\\n\"\n" +
  265. " data += \" if (tn = l.l + f.l, nn = l.t + f.t + H(s).h, o(n)) r(n[0]) && (tn = n[0]), r(n[1]) && (nn = n[1]);\"; data += \"\\r\\n\"\n" +
  266. " data += \" else {\"; data += \"\\r\\n\"\n" +
  267. " data += \" var h = f.l,\"; data += \"\\r\\n\"\n" +
  268. " data += \" p = f.t,\"; data += \"\\r\\n\"\n" +
  269. " data += \" v = f.l + e.w - en - u,\"; data += \"\\r\\n\"\n" +
  270. " data += \" d = f.t + e.h - rn - a;\"; data += \"\\r\\n\"\n" +
  271. " data += \" tn = c(tn, h, v) >> 0, nn = c(nn, p, d) >> 0\"; data += \"\\r\\n\"\n" +
  272. " data += \" }\"; data += \"\\r\\n\"\n" +
  273. " data += \" return T.style.left = tn + \\\"px\\\", T.style.top = nn + \\\"px\\\", _(\\\"fit\\\"), $\"; data += \"\\r\\n\"\n" +
  274. " data += \" }, $.set = function(t) { return r(t) ? (i(t) && (t = L.parse(t)), E(t), A(), $) : w() }, $.get = function(t) { return w(t) }, $.source = s, $.self = T, $.visible = !1, $.on = S, $.off = X, $.fire = _, $.hooks = O, $.enter = function(t) { return V(0, t), _(\\\"enter\\\"), $ }, $\"; data += \"\\r\\n\"\n" +
  275. " data += \" })\"; data += \"\\r\\n\"\n" +
  276. " data += \"}(window, document, \\\"CP\\\");\"; data += \"\\r\\n\"\n" +
  277. " data += \"</script>\"; data += \"\\r\\n\"\n" +
  278. "\n" +
  279. " data += \"<script>var picker=new CP(document.querySelector('input[type=\\\"text\\\"]'), \\\"click\\\");var globalRed, globalGreen, globalBlue;picker.on(\\\"change\\\", function(color){/* console.log(CP.HEX2RGB(color)); */ this.source.value=CP.HEX2RGB(color); document.getElementById('color-picker-show').style.backgroundColor='rgb(' + CP.HEX2RGB(color) + ')'; var colorString='rgb(' + CP.HEX2RGB(color) + ')', colorsOnly=colorString.substring(colorString.indexOf('(') + 1, colorString.lastIndexOf(')')).split(/,s*/), colorStringRed=colorsOnly[0], colorStringGreen=colorsOnly[1], colorStringBlue=colorsOnly[2]; /*console.log(colorStringRed); console.log(colorStringGreen); console.log(colorStringBlue);*/ globalRed=colorStringRed; globalGreen=colorStringGreen; globalBlue=colorStringBlue;});setInterval(function(){var content={'data': [globalRed + '|' + globalGreen + '|' + globalBlue]}; var contentTo_=JSON.stringify(content); var xhr=new XMLHttpRequest(); xhr.open('POST', 'http://192.168.4.1" + text_webpage_colorpicker_path + "'); xhr.setRequestHeader('content-type', 'application/json'); xhr.send(contentTo_); console.log(contentTo_);}, 500);</script></html>\"\n" +
  280. " return data\n" +
  281. "}\n" +
  282. "");
  283. return code;
  284. }
  285. Blockly.Python['webpage_buttoncontroller'] = function(block) {
  286. var text_webpage_buttoncontroller_top = block.getFieldValue('webpage_buttoncontroller_top');
  287. var text_webpage_buttoncontroller_top_path = block.getFieldValue('webpage_buttoncontroller_top_path');
  288. var text_webpage_buttoncontroller_left = block.getFieldValue('webpage_buttoncontroller_left');
  289. var text_webpage_buttoncontroller_left_path = block.getFieldValue('webpage_buttoncontroller_left_path');
  290. var text_webpage_buttoncontroller_center = block.getFieldValue('webpage_buttoncontroller_center');
  291. var text_webpage_buttoncontroller_center_path = block.getFieldValue('webpage_buttoncontroller_center_path');
  292. var text_webpage_buttoncontroller_right = block.getFieldValue('webpage_buttoncontroller_right');
  293. var text_webpage_buttoncontroller_right_path = block.getFieldValue('webpage_buttoncontroller_right_path');
  294. var text_webpage_buttoncontroller_bottom = block.getFieldValue('webpage_buttoncontroller_bottom');
  295. var text_webpage_buttoncontroller_bottom_path = block.getFieldValue('webpage_buttoncontroller_bottom_path');
  296. var code = "server.send(200, \"text/html\",\" " +
  297. "<!DOCTYPE HTML><html><head> <meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'></head><style>* { box-sizing: border-box;}body { font-family: Arial; padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; overflow: hidden; margin: 0;}.row { margin-left: auto; margin-right: auto; font-weight: bolder !important; margin-bottom: 20px; text-align: center; z-index: 1001;}.header { padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto;}.content { width: 100%; padding-top: 10px; margin: auto 0px auto 9.5%;}.block { background-color: rgba(0, 0, 0, 0);}/* Create three equal columns that floats next to each other */.column { float: left; width: 27%; padding: 0px; /* Should be removed. Only for demonstration */}/* Clear floats after the columns */.row:after { content: ''; display: table; clear: both;}#btn { display: inline-block; display: inline-block; font-size: 20px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: rgba(44, 79, 205, .88); border-radius: 10px; border: none; box-shadow: 0 9px rgba(24, 61, 195, .99); width: 90%; height: 80px; margin: 5px 5% 0px 5%;} .blank { color: rgba(0,0,0,0); } /* .btn:hover {background-color: #3e8e41}*/#btn:active { background-color: rgba(24, 61, 195, .99); border: none; box-shadow: 0 5px rgba(24, 61, 195, .99); transform: translateY(4px); cursor: pointer;}button:focus { outline: 0;}h1,h2,h3,h4,h5,h6 { font-weight: 500; line-height: 1.1; z-index: 1001;}p { margin-bottom: 10px; text-align: center; z-index: 1001;}</style><body> <div> <div class='row navbar'> <h1> CocoRobo IoT Project </h1> </div> <div class='row header'> <h2> Web Dashboard </h2> </div> <div class='content'> <div class='row'> <div class='column block blank'> . </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+text_webpage_buttoncontroller_top_path+"', '"+text_webpage_buttoncontroller_top+"')\\\">"+text_webpage_buttoncontroller_top+"</button> </div> <div class='column block blank'> . </div> </div> <div class='row'> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+text_webpage_buttoncontroller_left_path+"', '"+text_webpage_buttoncontroller_left+"')\\\">"+text_webpage_buttoncontroller_left+"</button> </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+text_webpage_buttoncontroller_center_path+"', '"+text_webpage_buttoncontroller_center+"')\\\">"+text_webpage_buttoncontroller_center+"</button> </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+text_webpage_buttoncontroller_right_path+"', '"+text_webpage_buttoncontroller_right+"')\\\">"+text_webpage_buttoncontroller_right+"</button> </div> </div> <div class='row'> <div class='column block blank'> . </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+text_webpage_buttoncontroller_bottom_path+"', '"+text_webpage_buttoncontroller_bottom+"')\\\">"+text_webpage_buttoncontroller_bottom+"</button> </div> <div class='column block blank'> . </div> </div> </div></body><script>function clickBtn(url_, btn) { var content = { 'data': [btn] }; var contentTo_ = JSON.stringify(content); var xhr = new XMLHttpRequest(); xhr.open('POST', url_); xhr.setRequestHeader('content-type', 'application/json'); xhr.send(contentTo_); console.log(btn);}</script></html>" +
  298. "\")\n";
  299. return code;
  300. }