|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Creating a Universal Console</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Creating a Universal Console</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style> |
|
|
29 |
#yconsole { |
|
|
30 |
text-align: right; |
|
|
31 |
} |
|
|
32 |
|
|
|
33 |
#demo .first button { |
|
|
34 |
margin-bottom: 2em; |
|
|
35 |
} |
|
|
36 |
|
|
|
37 |
#demo .yui3-console .yui3-console-title { |
|
|
38 |
border: 0 none; |
|
|
39 |
color: #000; |
|
|
40 |
font-size: 13px; |
|
|
41 |
font-weight: bold; |
|
|
42 |
margin: 0; |
|
|
43 |
text-transform: none; |
|
|
44 |
} |
|
|
45 |
#demo .yui3-console .yui3-console-entry-meta { |
|
|
46 |
margin: 0; |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
.clr { |
|
|
50 |
clear: both; |
|
|
51 |
} |
|
|
52 |
</style> |
|
|
53 |
|
|
|
54 |
|
|
|
55 |
<div class="intro"> |
|
|
56 |
<p>In this example, three YUI instances are created, each binding a button to call <code>Y.log(...)</code>. Then an additional, separate YUI instance is created that requests only the <code>console</code> module and creates a Console that listens for log events from all three.</p> |
|
|
57 |
</div> |
|
|
58 |
|
|
|
59 |
<div class="example yui3-skin-sam"> |
|
|
60 |
<div id="demo" class="yui3-skin-sam"> |
|
|
61 |
<div class="yui3-g"> |
|
|
62 |
<div class="yui3-u-1-2 first"> |
|
|
63 |
<h4>YUI #1</h4> |
|
|
64 |
<button type="button" id="yui1">Log from YUI instance #1</button> |
|
|
65 |
|
|
|
66 |
<h4>YUI #2</h4> |
|
|
67 |
<button type="button" id="yui2">Log from YUI instance #2</button> |
|
|
68 |
|
|
|
69 |
<h4>YUI #3</h4> |
|
|
70 |
<button type="button" id="yui3">Log from YUI instance #3</button> |
|
|
71 |
</div> |
|
|
72 |
<div class="yui3-u-1-2" id="yconsole"> |
|
|
73 |
</div> |
|
|
74 |
</div> |
|
|
75 |
<div class="clr"></div> |
|
|
76 |
</div> |
|
|
77 |
|
|
|
78 |
<script> |
|
|
79 |
|
|
|
80 |
// Create the first YUI instance |
|
|
81 |
YUI().use("node", function (Y) { |
|
|
82 |
|
|
|
83 |
Y.one( "#yui1" ).on( "click", function () { |
|
|
84 |
Y.log( "Message from YUI instance #1" ); |
|
|
85 |
}); |
|
|
86 |
|
|
|
87 |
}); |
|
|
88 |
|
|
|
89 |
// Create the second YUI instance |
|
|
90 |
YUI().use("node", function (Y) { |
|
|
91 |
|
|
|
92 |
Y.one( "#yui2" ).on( "click", function () { |
|
|
93 |
Y.log( "I'm the second YUI instance" ); |
|
|
94 |
}); |
|
|
95 |
|
|
|
96 |
}); |
|
|
97 |
|
|
|
98 |
// Create a third YUI instance |
|
|
99 |
YUI().use("node", function (Y) { |
|
|
100 |
|
|
|
101 |
Y.one( "#yui3" ).on( "click", function () { |
|
|
102 |
Y.log( "And this is #3 YUI" ); |
|
|
103 |
}); |
|
|
104 |
|
|
|
105 |
}); |
|
|
106 |
|
|
|
107 |
// Create a separate YUI instance to listen to all instances' logging |
|
|
108 |
YUI().use("console", function (Y) { |
|
|
109 |
|
|
|
110 |
// Configure the Console's logSource to Y.Global to make it universal |
|
|
111 |
new Y.Console({ |
|
|
112 |
logSource: Y.Global, |
|
|
113 |
style: 'inline', |
|
|
114 |
newestOnTop: false |
|
|
115 |
}).render( "#yconsole" ); |
|
|
116 |
|
|
|
117 |
}); |
|
|
118 |
|
|
|
119 |
</script> |
|
|
120 |
|
|
|
121 |
</div> |
|
|
122 |
|
|
|
123 |
<h3 class="first">Multiple YUI instances</h3> |
|
|
124 |
<p>Each YUI instance is its own sandbox. You can create as many YUI instances on a page as you want or need (though typically one is enough). The variables, module configurations and instances are kept inside that instance unless you expressly expose them via a global variable.</p> |
|
|
125 |
|
|
|
126 |
<pre class="code prettyprint">// Create the first YUI instance |
|
|
127 |
YUI().use("node", function (Y) { |
|
|
128 |
|
|
|
129 |
Y.one( "#yui1" ).on( "click", function () { |
|
|
130 |
Y.log( "Message from YUI instance #1" ); |
|
|
131 |
}); |
|
|
132 |
|
|
|
133 |
}); |
|
|
134 |
|
|
|
135 |
// Create the second YUI instance |
|
|
136 |
YUI().use("node", function (Y) { |
|
|
137 |
|
|
|
138 |
Y.one( "#yui2" ).on( "click", function () { |
|
|
139 |
Y.log( "I'm the second YUI instance" ); |
|
|
140 |
}); |
|
|
141 |
|
|
|
142 |
}); |
|
|
143 |
|
|
|
144 |
// Create a third YUI instance |
|
|
145 |
YUI().use("node", function (Y) { |
|
|
146 |
|
|
|
147 |
Y.one( "#yui3" ).on( "click", function () { |
|
|
148 |
Y.log( "And this is #3 YUI" ); |
|
|
149 |
}); |
|
|
150 |
|
|
|
151 |
});</pre> |
|
|
152 |
|
|
|
153 |
|
|
|
154 |
<h3>Listening to <code>Y.Global</code></h3> |
|
|
155 |
<p>To address debugging such an environment, Console can be configured to listen for log messages across all YUI instances by setting the Console instance's <code>logSource</code> configuration to <code>Y.Global</code>.</p> |
|
|
156 |
|
|
|
157 |
<p>We'll insert the universal Console into another YUI instance.</p> |
|
|
158 |
|
|
|
159 |
<pre class="code prettyprint">// Create a separate YUI instance to listen to all instances' logging |
|
|
160 |
YUI().use("console", function (Y) { |
|
|
161 |
|
|
|
162 |
// Configure the Console's logSource to Y.Global to make it universal |
|
|
163 |
new Y.Console({ |
|
|
164 |
logSource: Y.Global, |
|
|
165 |
style: 'block', |
|
|
166 |
newestOnTop: false, |
|
|
167 |
width: "250px" |
|
|
168 |
}).render( "#yconsole" ); |
|
|
169 |
|
|
|
170 |
});</pre> |
|
|
171 |
|
|
|
172 |
|
|
|
173 |
<h3>Full Code Listing</h3> |
|
|
174 |
|
|
|
175 |
<h4>Markup</h4> |
|
|
176 |
<pre class="code prettyprint"><div id="demo" class="yui3-skin-sam"> |
|
|
177 |
<div class="yui3-g"> |
|
|
178 |
<div class="yui3-u-1-2 first"> |
|
|
179 |
<h4>YUI #1</h4> |
|
|
180 |
<button type="button" id="yui1">Log from YUI instance #1</button> |
|
|
181 |
|
|
|
182 |
<h4>YUI #2</h4> |
|
|
183 |
<button type="button" id="yui2">Log from YUI instance #2</button> |
|
|
184 |
|
|
|
185 |
<h4>YUI #3</h4> |
|
|
186 |
<button type="button" id="yui3">Log from YUI instance #3</button> |
|
|
187 |
</div> |
|
|
188 |
<div class="yui3-u-1-2" id="yconsole"> |
|
|
189 |
</div> |
|
|
190 |
</div> |
|
|
191 |
<div class="clr"></div> |
|
|
192 |
</div></pre> |
|
|
193 |
|
|
|
194 |
|
|
|
195 |
<h4>JavaScript</h4> |
|
|
196 |
<pre class="code prettyprint"><script> |
|
|
197 |
|
|
|
198 |
// Create the first YUI instance |
|
|
199 |
YUI().use("node", function (Y) { |
|
|
200 |
|
|
|
201 |
Y.one( "#yui1" ).on( "click", function () { |
|
|
202 |
Y.log( "Message from YUI instance #1" ); |
|
|
203 |
}); |
|
|
204 |
|
|
|
205 |
}); |
|
|
206 |
|
|
|
207 |
// Create the second YUI instance |
|
|
208 |
YUI().use("node", function (Y) { |
|
|
209 |
|
|
|
210 |
Y.one( "#yui2" ).on( "click", function () { |
|
|
211 |
Y.log( "I'm the second YUI instance" ); |
|
|
212 |
}); |
|
|
213 |
|
|
|
214 |
}); |
|
|
215 |
|
|
|
216 |
// Create a third YUI instance |
|
|
217 |
YUI().use("node", function (Y) { |
|
|
218 |
|
|
|
219 |
Y.one( "#yui3" ).on( "click", function () { |
|
|
220 |
Y.log( "And this is #3 YUI" ); |
|
|
221 |
}); |
|
|
222 |
|
|
|
223 |
}); |
|
|
224 |
|
|
|
225 |
// Create a separate YUI instance to listen to all instances' logging |
|
|
226 |
YUI().use("console", function (Y) { |
|
|
227 |
|
|
|
228 |
// Configure the Console's logSource to Y.Global to make it universal |
|
|
229 |
new Y.Console({ |
|
|
230 |
logSource: Y.Global, |
|
|
231 |
style: 'inline', |
|
|
232 |
newestOnTop: false |
|
|
233 |
}).render( "#yconsole" ); |
|
|
234 |
|
|
|
235 |
}); |
|
|
236 |
|
|
|
237 |
</script></pre> |
|
|
238 |
|
|
|
239 |
|
|
|
240 |
<h4>CSS</h4> |
|
|
241 |
<pre class="code prettyprint"><style> |
|
|
242 |
#yconsole { |
|
|
243 |
text-align: right; |
|
|
244 |
} |
|
|
245 |
|
|
|
246 |
#demo .first button { |
|
|
247 |
margin-bottom: 2em; |
|
|
248 |
} |
|
|
249 |
|
|
|
250 |
#demo .yui3-console .yui3-console-title { |
|
|
251 |
border: 0 none; |
|
|
252 |
color: #000; |
|
|
253 |
font-size: 13px; |
|
|
254 |
font-weight: bold; |
|
|
255 |
margin: 0; |
|
|
256 |
text-transform: none; |
|
|
257 |
} |
|
|
258 |
#demo .yui3-console .yui3-console-entry-meta { |
|
|
259 |
margin: 0; |
|
|
260 |
} |
|
|
261 |
|
|
|
262 |
.clr { |
|
|
263 |
clear: both; |
|
|
264 |
} |
|
|
265 |
</style></pre> |
|
|
266 |
|
|
|
267 |
</div> |
|
|
268 |
</div> |
|
|
269 |
</div> |
|
|
270 |
|
|
|
271 |
<div class="yui3-u-1-4"> |
|
|
272 |
<div class="sidebar"> |
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
<div class="sidebox"> |
|
|
277 |
<div class="hd"> |
|
|
278 |
<h2 class="no-toc">Examples</h2> |
|
|
279 |
</div> |
|
|
280 |
|
|
|
281 |
<div class="bd"> |
|
|
282 |
<ul class="examples"> |
|
|
283 |
|
|
|
284 |
|
|
|
285 |
<li data-description="The basics of setting up a Console"> |
|
|
286 |
<a href="console-basic.html">Creating a Console for Debugging</a> |
|
|
287 |
</li> |
|
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
|
291 |
<li data-description="Using your YUI instance configuration to filter which messages are reported in the Console"> |
|
|
292 |
<a href="console-yui-config.html">YUI Configuration to Filter Log Messages</a> |
|
|
293 |
</li> |
|
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
<li data-description="Using the Console's logSource attribute to consolidate log messages from multiple YUI instances into one Console"> |
|
|
298 |
<a href="console-global.html">Creating a Universal Console</a> |
|
|
299 |
</li> |
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
</ul> |
|
|
305 |
</div> |
|
|
306 |
</div> |
|
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
<div class="sidebox"> |
|
|
311 |
<div class="hd"> |
|
|
312 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
313 |
</div> |
|
|
314 |
|
|
|
315 |
<div class="bd"> |
|
|
316 |
<ul class="examples"> |
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
<li data-description="Adding the ConsoleFilters plugin to a Console instance for more granular run time log message filtering"> |
|
|
326 |
<a href="../console-filters/console-filters-intro.html">Using the ConsoleFilters Plugin</a> |
|
|
327 |
</li> |
|
|
328 |
|
|
|
329 |
|
|
|
330 |
</ul> |
|
|
331 |
</div> |
|
|
332 |
</div> |
|
|
333 |
|
|
|
334 |
</div> |
|
|
335 |
</div> |
|
|
336 |
</div> |
|
|
337 |
</div> |
|
|
338 |
|
|
|
339 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
340 |
<script>prettyPrint();</script> |
|
|
341 |
|
|
|
342 |
<script> |
|
|
343 |
YUI.Env.Tests = { |
|
|
344 |
examples: [], |
|
|
345 |
project: '../assets', |
|
|
346 |
assets: '../assets/console', |
|
|
347 |
name: 'console-global', |
|
|
348 |
title: 'Creating a Universal Console', |
|
|
349 |
newWindow: '', |
|
|
350 |
auto: false |
|
|
351 |
}; |
|
|
352 |
YUI.Env.Tests.examples.push('console-basic'); |
|
|
353 |
YUI.Env.Tests.examples.push('console-yui-config'); |
|
|
354 |
YUI.Env.Tests.examples.push('console-global'); |
|
|
355 |
YUI.Env.Tests.examples.push('console-filters-intro'); |
|
|
356 |
|
|
|
357 |
</script> |
|
|
358 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
</body> |
|
|
363 |
</html> |