|
0
|
1 |
|
|
|
2 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|
|
3 |
<html> |
|
|
4 |
<head> |
|
|
5 |
<title>YUI Library Examples: Event: Using 'available', 'contentready', and 'domready'</title> |
|
|
6 |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
|
|
7 |
<link rel="stylesheet" type="text/css" href="../../assets/yui.css" > |
|
|
8 |
|
|
|
9 |
<style> |
|
|
10 |
/*Supplemental CSS for the YUI distribution*/ |
|
|
11 |
#custom-doc { width: 95%; min-width: 950px; } |
|
|
12 |
#pagetitle {background-image: url(../../assets/bg_hd.gif);} |
|
|
13 |
/* #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}*/ |
|
|
14 |
</style> |
|
|
15 |
|
|
|
16 |
<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css"> |
|
|
17 |
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" /> |
|
|
18 |
<script type="text/javascript" src="../../build/yui/yui-debug.js"></script> |
|
|
19 |
<style> |
|
|
20 |
#contentContainer {padding:1em; background:#999966;} |
|
|
21 |
#contentContainer ul {height:0px; overflow:hidden;} |
|
|
22 |
</style> |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
</head> |
|
|
26 |
<body id="yahoo-com" class=" yui-skin-sam"> |
|
|
27 |
<div id="custom-doc" class="yui-t2"> |
|
|
28 |
<div id="hd"> |
|
|
29 |
<div id="ygunav"> |
|
|
30 |
<p> |
|
|
31 |
<em> |
|
|
32 |
<a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i> |
|
|
33 |
</em> |
|
|
34 |
</p> |
|
|
35 |
<form action="http://search.yahoo.com/search" id="sitesearchform"> |
|
|
36 |
<input name="vs" type="hidden" value="developer.yahoo.com"> |
|
|
37 |
<input name="vs" type="hidden" value="yuiblog.com"> |
|
|
38 |
<div id="sitesearch"> |
|
|
39 |
<label for="searchinput">Site Search (YDN & YUIBlog): </label> |
|
|
40 |
<input type="text" id="searchinput" name="p"> |
|
|
41 |
<input type="submit" value="Search" id="searchsubmit" class="ygbt"> |
|
|
42 |
</div> |
|
|
43 |
</form> |
|
|
44 |
</div> |
|
|
45 |
<div id="ygma"><a href="../../"><img src="../../assets/logo.gif" border="0" width="200" height="93"></a></div> |
|
|
46 |
<div id="pagetitle"><h1>YUI Library Examples: Event: Using 'available', 'contentready', and 'domready'</h1></div> |
|
|
47 |
</div> |
|
|
48 |
<div id="bd"> |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
<div id="yui-main"> |
|
|
52 |
<div class="yui-b"> |
|
|
53 |
<div class="yui-ge"> |
|
|
54 |
<div class="yui-u first example" id="main"> |
|
|
55 |
|
|
|
56 |
<h2>Event: Using 'available', 'contentready', and 'domready'</h2> |
|
|
57 |
|
|
|
58 |
<div id="example" class="promo"> |
|
|
59 |
<div class="example-intro"> |
|
|
60 |
<p>As web pages get richer, they tend to get slower. One way to make your |
|
|
61 |
pages as responsive as possible is to carefully storyboard the page-load and |
|
|
62 |
page-paint processes so that the interactions most central to the page's |
|
|
63 |
purpose are enabled as early as possible. The window object's |
|
|
64 |
<code>load</code> event won't happen until the full DOM and all image data have |
|
|
65 |
loaded. Putting off script execution until after the page loads can be optimal |
|
|
66 |
for some scripts, but sometimes you won't want to wait that long to begin |
|
|
67 |
interacting with the page via script.</p> |
|
|
68 |
|
|
|
69 |
<p>The Event Utility gives you three additional interesting moments that occur |
|
|
70 |
during a page's load process: </p> |
|
|
71 |
|
|
|
72 |
<ol> |
|
|
73 |
|
|
|
74 |
<li><code><strong>available:</strong></code> <code>available</code> |
|
|
75 |
targets a single element and fires when that element is available (when it |
|
|
76 |
responds to <code>document.getElementById()</code>) — but you can't |
|
|
77 |
count on the element's children having been loaded at this point.</li> |
|
|
78 |
|
|
|
79 |
<li><code><strong>contentready:</strong></code> When you care about not |
|
|
80 |
just your target element but its children as well, use |
|
|
81 |
<code>contentready</code>. This event will tell you that your target |
|
|
82 |
element and all of its children are present in the DOM.</li> |
|
|
83 |
|
|
|
84 |
<li><code><strong>domready:</strong></code> Some DOM scripting operations |
|
|
85 |
cannot be performed safely until the page's entire DOM has loaded. The |
|
|
86 |
<code>domready</code> event will let you know that the DOM is fully loaded |
|
|
87 |
and ready for you to modify via script. This custom event takes the place of |
|
|
88 |
the <code>onDOMReady</code> event from previous versions of YUI.</li> |
|
|
89 |
|
|
|
90 |
</ol> |
|
|
91 |
|
|
|
92 |
<p>In the example box below, <code>available</code>, |
|
|
93 |
<code>contentready</code> and <code>domready</code> are all in use. A |
|
|
94 |
<code><div></code> (with a green background) loads; it has 100 chidren; |
|
|
95 |
one of those children is an arbitrarily large image that will take awhile to |
|
|
96 |
load. Keep an eye on the console, if you have one available in your browser. |
|
|
97 |
You'll see that the <code><div></code> (1) becomes available, (2) its |
|
|
98 |
content becomes ready (after all of its 100 children have loaded), (3) the DOM |
|
|
99 |
becomes ready, and finally (4) the page loads.</p> |
|
|
100 |
|
|
|
101 |
<p><strong>Internet Explorer note:</strong> It isn't always safe to modify |
|
|
102 |
content during the available/contentready until after the <code>domready</code> |
|
|
103 |
moment. In this browser, <code>domready</code> will execute before the |
|
|
104 |
available/contentready listeners. |
|
|
105 |
|
|
|
106 |
<p><strong>3.x note:</strong> This example has all of the YUI requirements included |
|
|
107 |
on the page. This differs from the default YUI configuration, which will dynamically load required |
|
|
108 |
YUI modules. Dynamic loading works asynchronously, so the domready moment |
|
|
109 |
likely will have passed when it comes time to bind the listeners, and possibly |
|
|
110 |
the window load event as well. All of the event listeners will actually fire in this |
|
|
111 |
case, but the order of the events will not be the same. <code>domready</code> will |
|
|
112 |
execute before the available/contentready listeners, and the window |
|
|
113 |
load event may as well.</p> |
|
|
114 |
</div> |
|
|
115 |
|
|
|
116 |
<div class="module example-container "> |
|
|
117 |
<div id="example-canvas" class="bd"> |
|
|
118 |
|
|
|
119 |
|
|
|
120 |
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
121 |
|
|
|
122 |
|
|
|
123 |
<!-- include event dependencies --> |
|
|
124 |
<script type="text/javascript" src="../../build/oop/oop-debug.js"></script> |
|
|
125 |
<script type="text/javascript" src="../../build/event/event-debug.js"></script> |
|
|
126 |
<script type="text/javascript" src="../../build/dom/dom-debug.js"></script> |
|
|
127 |
<script type="text/javascript" src="../../build/node/node-debug.js"></script> |
|
|
128 |
<div id="contentContainer"> |
|
|
129 |
<div id="demo"></div> |
|
|
130 |
|
|
|
131 |
<!--a ul with an arbitrarily large number of children:--> |
|
|
132 |
<ul> |
|
|
133 |
<li id='li-0'>child node #0</li> |
|
|
134 |
<li id='li-1'>child node #1</li> |
|
|
135 |
<li id='li-2'>child node #2</li> |
|
|
136 |
<li id='li-3'>child node #3</li> |
|
|
137 |
<li id='li-4'>child node #4</li> |
|
|
138 |
<li id='li-5'>child node #5</li> |
|
|
139 |
<li id='li-6'>child node #6</li> |
|
|
140 |
<li id='li-7'>child node #7</li> |
|
|
141 |
<li id='li-8'>child node #8</li> |
|
|
142 |
<li id='li-9'>child node #9</li> |
|
|
143 |
<li id='li-10'>child node #10</li> |
|
|
144 |
<li id='li-11'>child node #11</li> |
|
|
145 |
<li id='li-12'>child node #12</li> |
|
|
146 |
<li id='li-13'>child node #13</li> |
|
|
147 |
<li id='li-14'>child node #14</li> |
|
|
148 |
<li id='li-15'>child node #15</li> |
|
|
149 |
<li id='li-16'>child node #16</li> |
|
|
150 |
<li id='li-17'>child node #17</li> |
|
|
151 |
<li id='li-18'>child node #18</li> |
|
|
152 |
<li id='li-19'>child node #19</li> |
|
|
153 |
<li id='li-20'>child node #20</li> |
|
|
154 |
<li id='li-21'>child node #21</li> |
|
|
155 |
<li id='li-22'>child node #22</li> |
|
|
156 |
<li id='li-23'>child node #23</li> |
|
|
157 |
<li id='li-24'>child node #24</li> |
|
|
158 |
<li id='li-25'>child node #25</li> |
|
|
159 |
<li id='li-26'>child node #26</li> |
|
|
160 |
<li id='li-27'>child node #27</li> |
|
|
161 |
<li id='li-28'>child node #28</li> |
|
|
162 |
<li id='li-29'>child node #29</li> |
|
|
163 |
<li id='li-30'>child node #30</li> |
|
|
164 |
<li id='li-31'>child node #31</li> |
|
|
165 |
<li id='li-32'>child node #32</li> |
|
|
166 |
<li id='li-33'>child node #33</li> |
|
|
167 |
<li id='li-34'>child node #34</li> |
|
|
168 |
<li id='li-35'>child node #35</li> |
|
|
169 |
<li id='li-36'>child node #36</li> |
|
|
170 |
<li id='li-37'>child node #37</li> |
|
|
171 |
<li id='li-38'>child node #38</li> |
|
|
172 |
<li id='li-39'>child node #39</li> |
|
|
173 |
<li id='li-40'>child node #40</li> |
|
|
174 |
<li id='li-41'>child node #41</li> |
|
|
175 |
<li id='li-42'>child node #42</li> |
|
|
176 |
<li id='li-43'>child node #43</li> |
|
|
177 |
<li id='li-44'>child node #44</li> |
|
|
178 |
<li id='li-45'>child node #45</li> |
|
|
179 |
<li id='li-46'>child node #46</li> |
|
|
180 |
<li id='li-47'>child node #47</li> |
|
|
181 |
<li id='li-48'>child node #48</li> |
|
|
182 |
<li id='li-49'>child node #49</li> |
|
|
183 |
<li id='li-50'>child node #50</li> |
|
|
184 |
<li id='li-51'>child node #51</li> |
|
|
185 |
<li id='li-52'>child node #52</li> |
|
|
186 |
<li id='li-53'>child node #53</li> |
|
|
187 |
<li id='li-54'>child node #54</li> |
|
|
188 |
<li id='li-55'>child node #55</li> |
|
|
189 |
<li id='li-56'>child node #56</li> |
|
|
190 |
<li id='li-57'>child node #57</li> |
|
|
191 |
<li id='li-58'>child node #58</li> |
|
|
192 |
<li id='li-59'>child node #59</li> |
|
|
193 |
<li id='li-60'>child node #60</li> |
|
|
194 |
<li id='li-61'>child node #61</li> |
|
|
195 |
<li id='li-62'>child node #62</li> |
|
|
196 |
<li id='li-63'>child node #63</li> |
|
|
197 |
<li id='li-64'>child node #64</li> |
|
|
198 |
<li id='li-65'>child node #65</li> |
|
|
199 |
<li id='li-66'>child node #66</li> |
|
|
200 |
<li id='li-67'>child node #67</li> |
|
|
201 |
<li id='li-68'>child node #68</li> |
|
|
202 |
<li id='li-69'>child node #69</li> |
|
|
203 |
<li id='li-70'>child node #70</li> |
|
|
204 |
<li id='li-71'>child node #71</li> |
|
|
205 |
<li id='li-72'>child node #72</li> |
|
|
206 |
<li id='li-73'>child node #73</li> |
|
|
207 |
<li id='li-74'>child node #74</li> |
|
|
208 |
<li id='li-75'>child node #75</li> |
|
|
209 |
<li id='li-76'>child node #76</li> |
|
|
210 |
<li id='li-77'>child node #77</li> |
|
|
211 |
<li id='li-78'>child node #78</li> |
|
|
212 |
<li id='li-79'>child node #79</li> |
|
|
213 |
<li id='li-80'>child node #80</li> |
|
|
214 |
<li id='li-81'>child node #81</li> |
|
|
215 |
<li id='li-82'>child node #82</li> |
|
|
216 |
<li id='li-83'>child node #83</li> |
|
|
217 |
<li id='li-84'>child node #84</li> |
|
|
218 |
<li id='li-85'>child node #85</li> |
|
|
219 |
<li id='li-86'>child node #86</li> |
|
|
220 |
<li id='li-87'>child node #87</li> |
|
|
221 |
<li id='li-88'>child node #88</li> |
|
|
222 |
<li id='li-89'>child node #89</li> |
|
|
223 |
<li id='li-90'>child node #90</li> |
|
|
224 |
<li id='li-91'>child node #91</li> |
|
|
225 |
<li id='li-92'>child node #92</li> |
|
|
226 |
<li id='li-93'>child node #93</li> |
|
|
227 |
<li id='li-94'>child node #94</li> |
|
|
228 |
<li id='li-95'>child node #95</li> |
|
|
229 |
<li id='li-96'>child node #96</li> |
|
|
230 |
<li id='li-97'>child node #97</li> |
|
|
231 |
<li id='li-98'>child node #98</li> |
|
|
232 |
<li id='li-99'>child node #99</li> |
|
|
233 |
</ul> |
|
|
234 |
|
|
|
235 |
<img src="http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/large/uluru.jpg" width="500" alt="Uluru" id="image" /> |
|
|
236 |
|
|
|
237 |
</div> |
|
|
238 |
|
|
|
239 |
<script language="javascript"> |
|
|
240 |
YUI({base:"../../build/", timeout: 10000, filter:"debug", logInclude: {event:true, example:true}}).use("*", |
|
|
241 |
function(Y) { |
|
|
242 |
|
|
|
243 |
var results = Y.one('#demo'); |
|
|
244 |
|
|
|
245 |
//we'll use this handler for all of our callbacks; the |
|
|
246 |
//message being logged will always be the last argument. |
|
|
247 |
function fnHandler(e) { |
|
|
248 |
var message = arguments[arguments.length - 1]; |
|
|
249 |
// Y.log(message, "info", "example"); |
|
|
250 |
results.set('innerHTML', results.get('innerHTML') + '<p>' + message + '</p>'); |
|
|
251 |
} |
|
|
252 |
|
|
|
253 |
//assign page load handler: |
|
|
254 |
Y.on("load", fnHandler, window, Y, "The window load event fired. The page and all of its image data, including the large image of Uluru, has completed loading."); |
|
|
255 |
|
|
|
256 |
//assign domready handler: |
|
|
257 |
Y.on("domready", fnHandler, Y, "The DOMContentLoaded event fired. The DOM is now safe to modify via script."); |
|
|
258 |
|
|
|
259 |
//assign 'contentready' handler: |
|
|
260 |
Y.on("contentready", fnHandler, "#contentContainer", Y, "The 'contentready' event fired for the element 'contentContainer'. That element and all of its children are present in the DOM."); |
|
|
261 |
|
|
|
262 |
//assign 'available' handler: |
|
|
263 |
Y.on("available", fnHandler, "#contentContainer", Y, "The 'available' event fired on the element 'contentContainer'. That element is present in the DOM."); |
|
|
264 |
|
|
|
265 |
fnHandler("", "As the page loads, you'll see the 'available', 'contentready', 'domready', and window load events logged here as they fire in sequence."); |
|
|
266 |
|
|
|
267 |
}); |
|
|
268 |
</script> |
|
|
269 |
|
|
|
270 |
<!--END SOURCE CODE FOR EXAMPLE =============================== --> |
|
|
271 |
|
|
|
272 |
|
|
|
273 |
</div> |
|
|
274 |
</div> |
|
|
275 |
</div> |
|
|
276 |
|
|
|
277 |
<h2 class="first">Source Code for This Example:</h2> |
|
|
278 |
|
|
|
279 |
<h3>Markup:</h3> |
|
|
280 |
|
|
|
281 |
<p>The markup used to create the DOM is very simple, consisting of a <code><div></code> that holds a <code><ul></code> with 100 child <code><li></code>s and a single ~3MB image. The <code><ul></code> will take a little time to load, and the image (loading over the internet) will take a few seconds to load even on a fast connection. That should allow us to see in the Logger console some time deltas between when the <code><div></code> whose ID is <code>contentContainer</code> becomes available, when its children (those 100 <code><li></code>s) are ready, when the DOM is ready (including all the navigation elements on the page), and lastly when the page loads (ie, when that ~3MB image is fully loaded). </p> |
|
|
282 |
|
|
|
283 |
<div id="syntax1" class="yui-syntax-highlight"><div class="numbers"><pre class="html4strict" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="sc2"><<span class="kw2">div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">"contentContainer"</span>></span></div></li><li class="li1"><div class="de1"> </div></li><li class="li1"><div class="de1"> <span class="sc-1"><!--a ul with an arbitrarily large number of children:--></span></div></li><li class="li1"><div class="de1"> <span class="sc2"><<span class="kw2">ul</span>></span></div></li><li class="li2"><div class="de2"> <span class="sc2"><<span class="kw2">li</span>></span>...<span class="sc2"><<span class="sy0">/</span><span class="kw2">li</span>></span></div></li><li class="li1"><div class="de1"> <span class="sc-1"><!--...100 more of these--></span></div></li><li class="li1"><div class="de1"> <span class="sc2"><<span class="sy0">/</span><span class="kw2">ul</span>></span></div></li><li class="li1"><div class="de1"> </div></li><li class="li1"><div class="de1"> <span class="sc2"><<span class="kw2">img</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">"http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/large/uluru.jpg"</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">"500"</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">"Uluru"</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">"image"</span> <span class="sy0">/</span>></span></div></li><li class="li2"><div class="de2"> </div></li><li class="li1"><div class="de1"><span class="sc2"><<span class="sy0">/</span><span class="kw2">div</span>></span></div></li></ol></pre></div><div class="nonumbers"><pre class="html4strict" style="font-family:monospace;"><span class="sc2"><<span class="kw2">div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">"contentContainer"</span>></span> |
|
|
284 |
|
|
|
285 |
<span class="sc-1"><!--a ul with an arbitrarily large number of children:--></span> |
|
|
286 |
<span class="sc2"><<span class="kw2">ul</span>></span> |
|
|
287 |
<span class="sc2"><<span class="kw2">li</span>></span>...<span class="sc2"><<span class="sy0">/</span><span class="kw2">li</span>></span> |
|
|
288 |
<span class="sc-1"><!--...100 more of these--></span> |
|
|
289 |
<span class="sc2"><<span class="sy0">/</span><span class="kw2">ul</span>></span> |
|
|
290 |
|
|
|
291 |
<span class="sc2"><<span class="kw2">img</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">"http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/large/uluru.jpg"</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">"500"</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">"Uluru"</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">"image"</span> <span class="sy0">/</span>></span> |
|
|
292 |
|
|
|
293 |
<span class="sc2"><<span class="sy0">/</span><span class="kw2">div</span>></span></pre></div><textarea id="syntax1-plain"><div id="contentContainer"> |
|
|
294 |
|
|
|
295 |
<!--a ul with an arbitrarily large number of children:--> |
|
|
296 |
<ul> |
|
|
297 |
<li>...</li> |
|
|
298 |
<!--...100 more of these--> |
|
|
299 |
</ul> |
|
|
300 |
|
|
|
301 |
<img src="http://developer.yahoo.com/yui/docs/assets/examples/exampleimages/large/uluru.jpg" width="500" alt="Uluru" id="image" /> |
|
|
302 |
|
|
|
303 |
</div></textarea></div> |
|
|
304 |
<h3>CSS:</h3> |
|
|
305 |
|
|
|
306 |
<p>The CSS colors the contentContainer element and hides the big list to keep the example more compact.</p> |
|
|
307 |
|
|
|
308 |
<div id="syntax2" class="yui-syntax-highlight"><div class="numbers"><pre class="css" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><style type<span class="sy0">=</span><span class="st0">"text/css"</span><span class="sy0">></span></div></li><li class="li1"><div class="de1"> <span class="re0">#contentContainer</span> <span class="br0">{</span><span class="kw1">padding</span><span class="sy0">:</span><span class="re3">1em</span><span class="sy0">;</span> <span class="kw1">background</span><span class="sy0">:</span><span class="re0">#999966</span><span class="sy0">;</span><span class="br0">}</span></div></li><li class="li1"><div class="de1"> <span class="re0">#contentContainer</span> ul <span class="br0">{</span><span class="kw1">height</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span> <span class="kw1">overflow</span><span class="sy0">:</span><span class="kw2">hidden</span><span class="sy0">;</span><span class="br0">}</span></div></li><li class="li1"><div class="de1"></style<span class="sy0">></span></div></li></ol></pre></div><div class="nonumbers"><pre class="css" style="font-family:monospace;"><style type<span class="sy0">=</span><span class="st0">"text/css"</span><span class="sy0">></span> |
|
|
309 |
<span class="re0">#contentContainer</span> <span class="br0">{</span><span class="kw1">padding</span><span class="sy0">:</span><span class="re3">1em</span><span class="sy0">;</span> <span class="kw1">background</span><span class="sy0">:</span><span class="re0">#999966</span><span class="sy0">;</span><span class="br0">}</span> |
|
|
310 |
<span class="re0">#contentContainer</span> ul <span class="br0">{</span><span class="kw1">height</span><span class="sy0">:</span><span class="re3">0px</span><span class="sy0">;</span> <span class="kw1">overflow</span><span class="sy0">:</span><span class="kw2">hidden</span><span class="sy0">;</span><span class="br0">}</span> |
|
|
311 |
</style<span class="sy0">></span></pre></div><textarea id="syntax2-plain"><style type="text/css"> |
|
|
312 |
#contentContainer {padding:1em; background:#999966;} |
|
|
313 |
#contentContainer ul {height:0px; overflow:hidden;} |
|
|
314 |
</style></textarea></div> |
|
|
315 |
<h3>JavaScript:</h3> |
|
|
316 |
<p>In the script, we create an anonymous function that contains our YUI instance (<code>Y</code>). We then subscribe to the four events in which we're interested and, in each case, log a message to the console or Logger to express the timing of the events as they fire.</p> |
|
|
317 |
|
|
|
318 |
<div id="syntax3" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">YUI<span class="br0">(</span><span class="br0">)</span>.<span class="kw2">use</span><span class="br0">(</span><span class="st0">'*'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">(</span>Y<span class="br0">)</span> <span class="br0">{</span></div></li><li class="li1"><div class="de1"> <span class="kw2">var</span> results <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">(</span><span class="st0">'#demo'</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"> </div></li><li class="li1"><div class="de1"> <span class="co1">//we'll use this handler for all of our callbacks; the</span></div></li><li class="li2"><div class="de2"> <span class="co1">//message being logged will always be the last argument.</span></div></li><li class="li1"><div class="de1"> <span class="kw2">function</span> fnHandler<span class="br0">(</span>e<span class="br0">)</span> <span class="br0">{</span></div></li><li class="li1"><div class="de1"> <span class="kw2">var</span> message <span class="sy0">=</span> arguments<span class="br0">[</span>arguments.<span class="me1">length</span> <span class="sy0">-</span> <span class="nu0">1</span><span class="br0">]</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"> <span class="co1">// Y.log(message, "info", "example");</span></div></li><li class="li1"><div class="de1"> results.<span class="me1">set</span><span class="br0">(</span><span class="st0">'innerHTML'</span><span class="sy0">,</span> results.<span class="me1">get</span><span class="br0">(</span><span class="st0">'innerHTML'</span><span class="br0">)</span> <span class="sy0">+</span> <span class="st0">'<p>'</span> <span class="sy0">+</span> message <span class="sy0">+</span> <span class="st0">'</p>'</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2"> <span class="br0">}</span></div></li><li class="li1"><div class="de1"> </div></li><li class="li1"><div class="de1"> <span class="co1">//assign page load handler:</span></div></li><li class="li1"><div class="de1"> Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"load"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> window<span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The window load event fired. The page and all of its image data, including the large image of Uluru, has completed loading."</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"> </div></li><li class="li2"><div class="de2"> <span class="co1">//assign domready handler:</span></div></li><li class="li1"><div class="de1"> Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"domready"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The DOMContentLoaded event fired. The DOM is now safe to modify via script."</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"> </div></li><li class="li1"><div class="de1"> <span class="co1">//assign 'contentready' handler:</span></div></li><li class="li1"><div class="de1"> Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"contentready"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> <span class="st0">"#contentContainer"</span><span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The 'contentready' event fired for the element 'contentContainer'. That element and all of its children are present in the DOM."</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2"> </div></li><li class="li1"><div class="de1"> <span class="co1">//assign 'available' handler:</span></div></li><li class="li1"><div class="de1"> Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"available"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> <span class="st0">"#contentContainer"</span><span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The 'available' event fired on the element 'contentContainer'. That element is present in the DOM."</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"> </div></li><li class="li1"><div class="de1"> fnHandler<span class="br0">(</span><span class="st0">""</span><span class="sy0">,</span> <span class="st0">"As the page loads, you'll see the 'available', 'contentready', 'domready', and window load events logged here as they fire in sequence."</span><span class="br0">)</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2"><span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;">YUI<span class="br0">(</span><span class="br0">)</span>.<span class="kw2">use</span><span class="br0">(</span><span class="st0">'*'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">(</span>Y<span class="br0">)</span> <span class="br0">{</span> |
|
|
319 |
<span class="kw2">var</span> results <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">(</span><span class="st0">'#demo'</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
320 |
|
|
|
321 |
<span class="co1">//we'll use this handler for all of our callbacks; the</span> |
|
|
322 |
<span class="co1">//message being logged will always be the last argument.</span> |
|
|
323 |
<span class="kw2">function</span> fnHandler<span class="br0">(</span>e<span class="br0">)</span> <span class="br0">{</span> |
|
|
324 |
<span class="kw2">var</span> message <span class="sy0">=</span> arguments<span class="br0">[</span>arguments.<span class="me1">length</span> <span class="sy0">-</span> <span class="nu0">1</span><span class="br0">]</span><span class="sy0">;</span> |
|
|
325 |
<span class="co1">// Y.log(message, "info", "example");</span> |
|
|
326 |
results.<span class="me1">set</span><span class="br0">(</span><span class="st0">'innerHTML'</span><span class="sy0">,</span> results.<span class="me1">get</span><span class="br0">(</span><span class="st0">'innerHTML'</span><span class="br0">)</span> <span class="sy0">+</span> <span class="st0">'<p>'</span> <span class="sy0">+</span> message <span class="sy0">+</span> <span class="st0">'</p>'</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
327 |
<span class="br0">}</span> |
|
|
328 |
|
|
|
329 |
<span class="co1">//assign page load handler:</span> |
|
|
330 |
Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"load"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> window<span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The window load event fired. The page and all of its image data, including the large image of Uluru, has completed loading."</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
331 |
|
|
|
332 |
<span class="co1">//assign domready handler:</span> |
|
|
333 |
Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"domready"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The DOMContentLoaded event fired. The DOM is now safe to modify via script."</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
334 |
|
|
|
335 |
<span class="co1">//assign 'contentready' handler:</span> |
|
|
336 |
Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"contentready"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> <span class="st0">"#contentContainer"</span><span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The 'contentready' event fired for the element 'contentContainer'. That element and all of its children are present in the DOM."</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
337 |
|
|
|
338 |
<span class="co1">//assign 'available' handler:</span> |
|
|
339 |
Y.<span class="me1">on</span><span class="br0">(</span><span class="st0">"available"</span><span class="sy0">,</span> fnHandler<span class="sy0">,</span> <span class="st0">"#contentContainer"</span><span class="sy0">,</span> Y<span class="sy0">,</span> <span class="st0">"The 'available' event fired on the element 'contentContainer'. That element is present in the DOM."</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
340 |
|
|
|
341 |
fnHandler<span class="br0">(</span><span class="st0">""</span><span class="sy0">,</span> <span class="st0">"As the page loads, you'll see the 'available', 'contentready', 'domready', and window load events logged here as they fire in sequence."</span><span class="br0">)</span><span class="sy0">;</span> |
|
|
342 |
<span class="br0">}</span><span class="br0">)</span><span class="sy0">;</span></pre></div><textarea id="syntax3-plain">YUI().use('*', function(Y) { |
|
|
343 |
var results = Y.one('#demo'); |
|
|
344 |
|
|
|
345 |
//we'll use this handler for all of our callbacks; the |
|
|
346 |
//message being logged will always be the last argument. |
|
|
347 |
function fnHandler(e) { |
|
|
348 |
var message = arguments[arguments.length - 1]; |
|
|
349 |
// Y.log(message, "info", "example"); |
|
|
350 |
results.set('innerHTML', results.get('innerHTML') + '<p>' + message + '</p>'); |
|
|
351 |
} |
|
|
352 |
|
|
|
353 |
//assign page load handler: |
|
|
354 |
Y.on("load", fnHandler, window, Y, "The window load event fired. The page and all of its image data, including the large image of Uluru, has completed loading."); |
|
|
355 |
|
|
|
356 |
//assign domready handler: |
|
|
357 |
Y.on("domready", fnHandler, Y, "The DOMContentLoaded event fired. The DOM is now safe to modify via script."); |
|
|
358 |
|
|
|
359 |
//assign 'contentready' handler: |
|
|
360 |
Y.on("contentready", fnHandler, "#contentContainer", Y, "The 'contentready' event fired for the element 'contentContainer'. That element and all of its children are present in the DOM."); |
|
|
361 |
|
|
|
362 |
//assign 'available' handler: |
|
|
363 |
Y.on("available", fnHandler, "#contentContainer", Y, "The 'available' event fired on the element 'contentContainer'. That element is present in the DOM."); |
|
|
364 |
|
|
|
365 |
fnHandler("", "As the page loads, you'll see the 'available', 'contentready', 'domready', and window load events logged here as they fire in sequence."); |
|
|
366 |
});</textarea></div> </div> |
|
|
367 |
<div class="yui-u sidebar"> |
|
|
368 |
|
|
|
369 |
|
|
|
370 |
<div id="examples" class="mod box4"> |
|
|
371 |
<div class="hd"> |
|
|
372 |
<h4> |
|
|
373 |
Event Examples:</h4> |
|
|
374 |
</div> |
|
|
375 |
<div class="bd"> |
|
|
376 |
<ul> |
|
|
377 |
<li><a href='../event/event-simple.html'>Simple DOM Events</a></li><li class='selected'><a href='../event/event-timing.html'>Using 'available', 'contentready', and 'domready'</a></li><li><a href='../event/event-ce.html'>Using Custom Events</a></li><li><a href='../event/event-focus-blur.html'>Skinning via Progressive Enhancement using the Event Utility and the Loader</a></li><li><a href='../yui/yui-augment.html'>Compose Classes of Objects with <code>augment</code> (included with examples for The YUI Global Object)</a></li><li><a href='../node-focusmanager/node-focusmanager-3.html'>Accessible Menu Button (included with examples for Focus Manager Node Plugin)</a></li><li><a href='../node-focusmanager/node-focusmanager-2.html'>Accessible TabView (included with examples for Focus Manager Node Plugin)</a></li><li><a href='../attribute/attribute-event.html'>Attribute Change Events (included with examples for Attribute)</a></li><li><a href='../attribute/attribute-event-speeddate.html'>Attribute Event Based Speed Dating (included with examples for Attribute)</a></li><li><a href='../attribute/attribute-getset.html'>Attribute Getters, Setters and Validators (included with examples for Attribute)</a></li><li><a href='../widget/widget-extend.html'>Extending the base widget class (included with examples for Widget)</a></li><li><a href='../dd/photo-browser.html'>Photo Browser (included with examples for Drag & Drop)</a></li> </ul> |
|
|
378 |
</div> |
|
|
379 |
</div> |
|
|
380 |
|
|
|
381 |
<div class="mod box4"> |
|
|
382 |
<div class="hd"> |
|
|
383 |
<h4>More Event Resources:</h4> |
|
|
384 |
</div> |
|
|
385 |
<div class="bd"> |
|
|
386 |
<ul> |
|
|
387 |
<!-- <li><a href="http://developer.yahoo.com/yui/event/">User's Guide</a> (external)</li> --> |
|
|
388 |
<li><a href="../../api/module_event.html">API Documentation</a></li></ul> |
|
|
389 |
</div> |
|
|
390 |
</div> |
|
|
391 |
</div> |
|
|
392 |
</div> |
|
|
393 |
|
|
|
394 |
</div> |
|
|
395 |
</div> |
|
|
396 |
|
|
|
397 |
|
|
|
398 |
<div class="yui-b toc3" id="tocWrapper"> |
|
|
399 |
<!-- TABLE OF CONTENTS --> |
|
|
400 |
<div id="toc"> |
|
|
401 |
|
|
|
402 |
<ul> |
|
|
403 |
<li class="sect first">YUI 3 Resources</li><li class="item"><a title="YUI 3 -- Yahoo! User Interface (YUI) Library" href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="YUI 3 Dependency Configurator -- configure your custom YUI implementation" href="http://developer.yahoo.com/yui/3/configurator">YUI 3 Dependency Configurator</a></li><li class="item"><a title="The YUI 3 Forum on YUILibrary.com" href="http://yuilibrary.com/forum/viewforum.php?f=15">YUI 3 Forums (external)</a></li><li class="item"><a title="Found a bug or a missing feature? Let us know on YUILibrary.com." href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/license.html">YUI License</a></li><li class="item"><a title="Download and fork the YUI project on GitHub" href="http://github.com/yui">YUI on Github</a></li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI Global Object - Functional Examples" href="../../examples/yui/index.html">YUI Global Object</a></li><li class="selected "><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Plugin - Functional Examples" href="../../examples/plugin/index.html">Plugin <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Widget - Functional Examples" href="../../examples/widget/index.html">Widget <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="AsyncQueue - Functional Examples" href="../../examples/async-queue/index.html">AsyncQueue</a></li><li class="item"><a title="Browser History - Functional Examples" href="../../examples/history/index.html">Browser History</a></li><li class="item"><a title="Cache - Functional Examples" href="../../examples/cache/index.html">Cache</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="DataSchema - Functional Examples" href="../../examples/dataschema/index.html">DataSchema <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataSource - Functional Examples" href="../../examples/datasource/index.html">DataSource <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataType - Functional Examples" href="../../examples/datatype/index.html">DataType <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Drag & Drop - Functional Examples" href="../../examples/dd/index.html">Drag & Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="ImageLoader - Functional Examples" href="../../examples/imageloader/index.html">ImageLoader</a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="Stylesheet - Functional Examples" href="../../examples/stylesheet/index.html">Stylesheet</a></li><li class="sect">YUI 3 Widgets - Examples</li><li class="item"><a title="Overlay - Functional Examples" href="../../examples/overlay/index.html">Overlay <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Slider - Functional Examples" href="../../examples/slider/index.html">Slider <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Node Plugins - Examples</li><li class="item"><a title="FocusManager Node Plugin - Functional Examples" href="../../examples/node-focusmanager/index.html">FocusManager Node Plugin <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="MenuNav Node Plugin - Functional Examples" href="../../examples/node-menunav/index.html">MenuNav Node Plugin <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="sect">YUI 3 Developer Tools - Examples</li><li class="item"><a title="Console - Functional Examples" href="../../examples/console/index.html">Console <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Console Filters Plugin- Functional Examples" href="../../examples/console-filters/index.html">Plugin.ConsoleFilters <img src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Profiler - Functional Examples" href="../../examples/profiler/index.html">Profiler</a></li><li class="item"><a title="Test - Functional Examples" href="../../examples/test/index.html">Test</a></li><li class="sect">Other Useful YUI 3 Resources</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li></ul> |
|
|
404 |
</div> |
|
|
405 |
</div> |
|
|
406 |
</div><!--closes bd--> |
|
|
407 |
|
|
|
408 |
<div id="ft"> |
|
|
409 |
<p class="first">Copyright © 2009 Yahoo! Inc. All rights reserved.</p> |
|
|
410 |
<p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> - |
|
|
411 |
<a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> - |
|
|
412 |
<a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> - |
|
|
413 |
<a href="http://careers.yahoo.com/">Job Openings</a></p> |
|
|
414 |
</div> |
|
|
415 |
</div> |
|
|
416 |
<script language="javascript"> |
|
|
417 |
var yuiConfig = {base:"../../build/", timeout: 10000, filter:"debug", logInclude: {event:true, example:true}}; |
|
|
418 |
</script> |
|
|
419 |
<script src="../../assets/syntax.js"></script> |
|
|
420 |
<script src="../../assets/dpSyntaxHighlighter.js"></script> |
|
|
421 |
<script language="javascript"> |
|
|
422 |
dp.SyntaxHighlighter.HighlightAll('code'); |
|
|
423 |
</script> |
|
|
424 |
</body> |
|
|
425 |
</html> |