event-ready.js.html revision eb9b6f817df5c660be9f00fc5d27fe33479fdc98
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>event <span class="subtitle">3.00PR1</span></h3>
<p>
> event-ready.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> Show Deprecated</span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre><span class="nx">YUI</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="s2">"event-ready"</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">Y</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">Y</span> <span class="o">===</span> <span class="nx">YUI</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">env</span> <span class="o">=</span> <span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">,</span> <span class="nx">C</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">,</span> <span class="nx">D</span> <span class="o">=</span> <span class="nx">C</span><span class="o">.</span><span class="nx">doc</span><span class="o">,</span> <span class="nx">POLL_INTERVAL</span> <span class="o">=</span> <span class="nx">C</span><span class="o">.</span><span class="nx">pollInterval</span> <span class="o">||</span> <span class="m">20</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">env</span><span class="o">.</span><span class="nx">_ready</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">_ready</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">env</span><span class="o">.</span><span class="nx">DOMReady</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">DOMReady</span><span class="o">=</span><span class="kc">true</span><span class="o">;</span>
<span class="c">// Fire the content ready custom event</span>
<span class="c"></span>
<span class="c"></span>
<span class="k">if</span> <span class="o">(</span><span class="nx">D</span><span class="o">.</span><span class="nx">removeEventListener</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">D</span><span class="o">.</span><span class="nx">removeEventListener</span><span class="o">(</span><span class="s2">"DOMContentLoaded"</span><span class="o">,</span> <span class="nx">env</span><span class="o">.</span><span class="nx">_ready</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="c">// create custom event</span>
<span class="c"></span>
<span class="c">/////////////////////////////////////////////////////////////</span>
<span class="c"></span> <span class="c">// DOMReady</span>
<span class="c"></span> <span class="c">// based on work by: Dean Edwards/John Resig/Matthias Miller </span>
<span class="c"></span>
<span class="c">// Internet Explorer: use the readyState of a defered script.</span>
<span class="c"></span> <span class="c">// This isolates what appears to be a safe moment to manipulate</span>
<span class="c"></span> <span class="c">// the DOM prior to when the document's readyState suggests</span>
<span class="c"></span> <span class="c">// it is safe to do so.</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">UA</span><span class="o">.</span><span class="nx">ie</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">_dri</span> <span class="o">=</span> <span class="nx">setInterval</span><span class="o">(</span><span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">n</span> <span class="o">=</span> <span class="nx">D</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s1">'p'</span><span class="o">);</span>
<span class="k">try</span> <span class="o">{</span>
<span class="c">// throws an error if doc is not ready</span>
<span class="c"></span> <span class="nx">n</span><span class="o">.</span><span class="nx">doScroll</span><span class="o">(</span><span class="s1">'left'</span><span class="o">);</span>
<span class="nx">clearInterval</span><span class="o">(</span><span class="nx">env</span><span class="o">.</span><span class="nx">_dri</span><span class="o">);</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">_dri</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">_ready</span><span class="o">();</span>
<span class="nx">n</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="nx">ex</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">n</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">},</span> <span class="nx">POLL_INTERVAL</span><span class="o">);</span>
<span class="c">// The document's readyState in Safari currently will</span>
<span class="c"></span> <span class="c">// change to loaded/complete before images are loaded.</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">UA</span><span class="o">.</span><span class="nx">webkit</span> <span class="o">&&</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">UA</span><span class="o">.</span><span class="nx">webkit</span> <span class="o"><</span> <span class="m">525</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">_dri</span> <span class="o">=</span> <span class="nx">setInterval</span><span class="o">(</span><span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">rs</span><span class="o">=</span><span class="nx">D</span><span class="o">.</span><span class="nx">readyState</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="s2">"loaded"</span> <span class="o">==</span> <span class="nx">rs</span> <span class="o">||</span> <span class="s2">"complete"</span> <span class="o">==</span> <span class="nx">rs</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">clearInterval</span><span class="o">(</span><span class="nx">env</span><span class="o">.</span><span class="nx">_dri</span><span class="o">);</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">_dri</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="nx">env</span><span class="o">.</span><span class="nx">_ready</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">},</span> <span class="nx">POLL_INTERVAL</span><span class="o">);</span>
<span class="c">// FireFox and Opera: These browsers provide a event for this</span>
<span class="c"></span> <span class="c">// moment. The latest WebKit releases now support this event.</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">D</span><span class="o">.</span><span class="nx">addEventListener</span><span class="o">(</span><span class="s2">"DOMContentLoaded"</span><span class="o">,</span> <span class="nx">env</span><span class="o">.</span><span class="nx">_ready</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">/////////////////////////////////////////////////////////////</span>
<span class="c"></span>
<span class="o">}</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">publish</span><span class="o">(</span><span class="s1">'event:ready'</span><span class="o">,</span> <span class="o">{</span>
<span class="nx">fireOnce</span><span class="o">:</span> <span class="kc">true</span>
<span class="o">});</span>
<span class="k">var</span> <span class="nx">yready</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="s1">'event:ready'</span><span class="o">);</span>
<span class="o">};</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">env</span><span class="o">.</span><span class="nx">DOMReady</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">yready</span><span class="o">();</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">before</span><span class="o">(</span><span class="nx">yready</span><span class="o">,</span> <span class="nx">env</span><span class="o">,</span> <span class="s2">"_ready"</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">},</span> <span class="s2">"3.0.0"</span><span class="o">);</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>