bubble.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2007 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <!--
  9. File for testing bubble control.
  10. -->
  11. <head>
  12. <title>goog.ui.Bubble</title>
  13. <script src="../base.js"></script>
  14. <script>
  15. if (typeof goog == 'undefined') {
  16. alert('Closure failed to load');
  17. } else {
  18. goog.require('goog.ui.Bubble');
  19. }
  20. </script>
  21. <link rel="stylesheet" href="css/demo.css">
  22. <link rel="stylesheet" href="../css/bubble.css">
  23. </head>
  24. <body bgcolor="green">
  25. <h1>goog.ui.Bubble</h1>
  26. <table width="100%" align="center">
  27. <tbody>
  28. <tr>
  29. <td>
  30. <div align="left">
  31. <form>
  32. <input type="text" id="textField1"/>
  33. <input type="button" id="button1" value="Click for a bubble!!!"
  34. onclick="clickButton(button1, textField1);"/>
  35. </form>
  36. </div>
  37. </td>
  38. <td>
  39. <div align="center">
  40. <form>
  41. <input type="text" id="textField2"/>
  42. <input type="button" id="button2" value="Click for a bubble!!!"
  43. onclick="clickButton(button2, textField2);"/>
  44. </form>
  45. </div>
  46. </td>
  47. <td>
  48. <div align="right">
  49. <form>
  50. <input type="text" id="textField3"/>
  51. <input type="button" id="button3" value="Click for a bubble!!!"
  52. onclick="clickButton(button3, textField3);"/>
  53. </form>
  54. </div>
  55. </td>
  56. </tr>
  57. <tr height>
  58. <td>
  59. <div align="left">
  60. <form>
  61. <input type="text" id="textField4"/>
  62. <input type="button" id="button4" value="Click for a bubble!!!"
  63. onclick="clickButton(button4, textField4);"/>
  64. </form>
  65. </div>
  66. </td>
  67. <td>
  68. <br>
  69. <div align="left">
  70. <form>
  71. <table>
  72. <tbody>
  73. <tr><td>X:</td>
  74. <td><input type="text" id="xcoord" value="100"/></td>
  75. </tr>
  76. <tr><td>Y:</td>
  77. <td><input type="text" id="ycoord" value="100"/></td>
  78. </tr>
  79. <tr><td>Corner orientation(0-3):</td>
  80. <td><input type="text" id="corner" value="1"/></td>
  81. </tr>
  82. <tr><td>Auto-hide (true or false):</td>
  83. <td><input type="text" id="autoHide" value="false"/></td>
  84. </tr>
  85. <tr><td>Timeout (ms):</td>
  86. <td><input type="text" id="timeout" value="0"/></td>
  87. <tr><td>Decorated</td>
  88. <td><input type="checkbox" id="decorated"/></td>
  89. <tr><td><input type="button" id="button5.0.0"
  90. value="Click for a custom bubble!!!"
  91. onclick=
  92. "doCustom(xcoord, ycoord, corner, autoHide, timeout, decorated);"/>
  93. </td><td><input type="button" id="button5.0.1"
  94. value="Toggle custom button!"
  95. onclick="toggleVisibility();"/>
  96. </td>
  97. </tr>
  98. <tr><td><input type="button" id="button5.1"
  99. value="Click for a random bubble!!!"
  100. onclick="doRandom();"/>
  101. </td></tr>
  102. </tbody>
  103. </table>
  104. </form>
  105. </div>
  106. <br>
  107. </td>
  108. <td>
  109. <div align="right">
  110. <form>
  111. <input type="text" id="textField6"/>
  112. <input type="button" id="button6" value="Click for a bubble!!!"
  113. onclick="clickButton(button6, textField6);"/>
  114. </form>
  115. </div>
  116. </td>
  117. </tr>
  118. <tr>
  119. <td height="30%">
  120. <div align="left">
  121. <form>
  122. <input type="text" id="textField7"/>
  123. <input type="button" id="button7" value="Click for a bubble!!!"
  124. onclick="clickButton(button7, textField7);"/>
  125. </form>
  126. </div>
  127. </td>
  128. <td>
  129. <div align="center">
  130. <form>
  131. <input type="text" id="textField8"/>
  132. <input type="button" id="button8" value="Click for a bubble!!!"
  133. onclick="clickButton(button8, textField8);"/>
  134. </form>
  135. </div>
  136. </td>
  137. <td>
  138. <div align="right">
  139. <form>
  140. <input type="text" id="textField9"/>
  141. <input type="button" id="button9" value="Click for a bubble!!!"
  142. onclick="clickButton(button9, textField9);"/>
  143. </form>
  144. </div>
  145. </td>
  146. </tr>
  147. </tbody>
  148. </table>
  149. <script>
  150. var defaultTimeout = 10000;
  151. var bubble = null;
  152. function clickButton(anchor, textField) {
  153. if (bubble) {
  154. bubble.dispose();
  155. bubble = null;
  156. }
  157. var textString = textField.value;
  158. if (!textString) {
  159. textString = 'Input here!';
  160. anchor = textField;
  161. }
  162. bubble = new goog.ui.Bubble(textString);
  163. bubble.setAutoHide(false);
  164. bubble.setPosition(new goog.positioning.AnchoredPosition(anchor, null));
  165. bubble.setTimeout(defaultTimeout);
  166. bubble.render();
  167. bubble.attach(anchor);
  168. bubble.setVisible(true);
  169. }
  170. var decorated = false;
  171. var bubbleC = null;
  172. function doCustom(xcoord, ycoord, corner, autoHide, timeout, decorated) {
  173. if (bubbleC) {
  174. bubbleC.dispose();
  175. bubbleC = null;
  176. }
  177. if (parseInt(xcoord.value) == NaN ||
  178. parseInt(ycoord.value) == NaN ||
  179. parseInt(corner.value) == NaN ||
  180. parseInt(timeout.value) == NaN ||
  181. (autoHide.value != "true" && autoHide.value != "false") ||
  182. (corner.value < 0 || corner.value > 3)) {
  183. alert('Incorrect input!');
  184. return;
  185. }
  186. var internalElement = null;
  187. if (decorated.checked) {
  188. internalElement = goog.dom.createElement('div');
  189. internalElement.innerHTML = '<table><tbody>' +
  190. '<tr><td>One!</td><td>Two!</td></tr>' +
  191. '<tr><td>Three!</td><td>Four!</td></tr>' +
  192. '</tbody></table>';
  193. } else {
  194. internalElement = 'Random Bubble. La-la-la-la! La-la-la-la-la!!!';
  195. }
  196. bubbleC = new goog.ui.Bubble(internalElement);
  197. bubbleC.setAutoHide(autoHide.value == "false" ? false : true);
  198. bubbleC.setPinnedCorner(parseInt(corner.value));
  199. bubbleC.setPosition(new goog.positioning.AbsolutePosition(
  200. parseInt(xcoord.value), parseInt(ycoord.value)));
  201. bubbleC.setTimeout(parseInt(timeout.value));
  202. bubbleC.render();
  203. bubbleC.setVisible(true);
  204. }
  205. function toggleVisibility () {
  206. if (bubbleC) {
  207. bubbleC.setVisible(!bubbleC.isVisible());
  208. }
  209. }
  210. var timer = null;
  211. function doRandom() {
  212. if (timer) {
  213. window.clearInterval(timer);
  214. timer = null;
  215. return;
  216. }
  217. doRandomClick();
  218. timer = window.setInterval(doRandomClick, 2000);
  219. }
  220. function doRandomClick() {
  221. for ( ; ; ) {
  222. var number=Math.floor(Math.random()*9) + 1;
  223. if (number != 5) {
  224. break;
  225. }
  226. }
  227. var button = document.getElementById("button" + number);
  228. if (button) {
  229. var defaultTimeoutSav = defaultTimeout;
  230. defaultTimeout = 2000;
  231. button.click ();
  232. defaultTimeout = defaultTimeoutSav;
  233. }
  234. }
  235. </script>
  236. </body>
  237. </html>