Debian Codegraph @

closure-library/closure/goog/demos/bubble.html

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