overlay.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Blockly Demo: Resizable Blockly (Part 2)</title>
  6. <script src="../../blockly_compressed.js"></script>
  7. <script src="../../blocks_compressed.js"></script>
  8. <script src="../../msg/js/en.js"></script>
  9. <style>
  10. html, body {
  11. height: 100%;
  12. margin: 0;
  13. }
  14. body {
  15. background-color: #fff;
  16. font-family: sans-serif;
  17. overflow: hidden;
  18. }
  19. h1 {
  20. font-weight: normal;
  21. font-size: 140%;
  22. }
  23. table {
  24. height: 100%;
  25. width: 100%;
  26. }
  27. #blocklyArea {
  28. height: 99%;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <table>
  34. <tr>
  35. <td>
  36. <h1><a href="https://developers.google.com/blockly/">Blockly</a> &gt;
  37. <a href="../index.html">Demos</a> &gt; Resizable Blockly (Part 2)</h1>
  38. <p>
  39. Once an <a href="index.html">area is defined</a>, Blockly can be
  40. injected and positioned over the area.
  41. A resize handler keeps it in position as the page changes.
  42. </p>
  43. <p>&rarr; More info on <a href="https://developers.google.com/blockly/guides/configure/web/resizable">injecting resizable Blockly</a>&hellip;</p>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td id="blocklyArea">
  48. </td>
  49. </tr>
  50. </table>
  51. <div id="blocklyDiv" style="position: absolute"></div>
  52. <xml id="toolbox" style="display: none">
  53. <block type="controls_if"></block>
  54. <block type="logic_compare"></block>
  55. <block type="controls_repeat_ext"></block>
  56. <block type="math_number"></block>
  57. <block type="math_arithmetic"></block>
  58. <block type="text"></block>
  59. <block type="text_print"></block>
  60. </xml>
  61. <script>
  62. var blocklyArea = document.getElementById('blocklyArea');
  63. var blocklyDiv = document.getElementById('blocklyDiv');
  64. var workspace = Blockly.inject(blocklyDiv,
  65. {media: '../../media/',
  66. toolbox: document.getElementById('toolbox')});
  67. var onresize = function(e) {
  68. // Compute the absolute coordinates and dimensions of blocklyArea.
  69. var element = blocklyArea;
  70. var x = 0;
  71. var y = 0;
  72. do {
  73. x += element.offsetLeft;
  74. y += element.offsetTop;
  75. element = element.offsetParent;
  76. } while (element);
  77. // Position blocklyDiv over blocklyArea.
  78. blocklyDiv.style.left = x + 'px';
  79. blocklyDiv.style.top = y + 'px';
  80. blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
  81. blocklyDiv.style.height = blocklyArea.offsetHeight + 'px';
  82. };
  83. window.addEventListener('resize', onresize, false);
  84. onresize();
  85. Blockly.svgResize(workspace);
  86. </script>
  87. </body>
  88. </html>