event-ready.js.html revision eb9b6f817df5c660be9f00fc5d27fe33479fdc98
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>API: event event-ready.js (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/api.css">
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
<h3>event&nbsp; <span class="subtitle">3.00PR1</span></h3>
<p>
<a href="/index.html">Yahoo! UI Library</a>
&gt; <a href="/module_event.html">event</a>
&gt; 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">&quot;event-ready&quot;</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">// E.DOMReadyEvent.fire();</span>
<span class="c"></span>
<span class="c">// Remove the DOMContentLoaded (FF/Opera)</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">&quot;DOMContentLoaded&quot;</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&#39;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">&#39;p&#39;</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">&#39;left&#39;</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&#39;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">&amp;&amp;</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">&lt;</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">&quot;loaded&quot;</span> <span class="o">==</span> <span class="nx">rs</span> <span class="o">||</span> <span class="s2">&quot;complete&quot;</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">&quot;DOMContentLoaded&quot;</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">&#39;event:ready&#39;</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">&#39;event:ready&#39;</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">&quot;_ready&quot;</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">},</span> <span class="s2">&quot;3.0.0&quot;</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">
<li class=""><a href="module_anim.html">anim</a></li>
<li class=""><a href="module_anim-color.html">anim-color</a></li>
<li class=""><a href="module_anim-curve.html">anim-curve</a></li>
<li class=""><a href="module_anim-easing.html">anim-easing</a></li>
<li class=""><a href="module_anim-scroll.html">anim-scroll</a></li>
<li class=""><a href="module_anim-xy.html">anim-xy</a></li>
<li class=""><a href="module_attribute.html">attribute</a></li>
<li class=""><a href="module_base.html">base</a></li>
<li class=""><a href="module_dd-plugin.html">dd-plugin</a></li>
<li class="selected"><a href="module_event.html">event</a></li>
<li class=""><a href="module_get.html">get</a></li>
<li class=""><a href="module_io.html">io</a></li>
<li class=""><a href="module_loader.html">loader</a></li>
<li class=""><a href="module_node.html">node</a></li>
<li class=""><a href="module_node-class.html">node-class</a></li>
<li class=""><a href="module_node-region.html">node-region</a></li>
<li class=""><a href="module_node-screen.html">node-screen</a></li>
<li class=""><a href="module_Queue.html">Queue</a></li>
<li class=""><a href="module_yui.html">yui</a></li>
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
<li class=""><a href="Do.html">Do</a></li>
<li class=""><a href="Do.AlterArgs.html">Do.AlterArgs</a></li>
<li class=""><a href="Do.AlterReturn.html">Do.AlterReturn</a></li>
<li class=""><a href="Do.Error.html">Do.Error</a></li>
<li class=""><a href="Do.Method.html">Do.Method</a></li>
<li class=""><a href="Event.html">Event</a></li>
<li class=""><a href="Event.Custom.html">Event.Custom</a></li>
<li class=""><a href="Event.Facade.html">Event.Facade</a></li>
<li class=""><a href="Event.Handle.html">Event.Handle</a></li>
<li class=""><a href="Event.Subscriber.html">Event.Subscriber</a></li>
<li class=""><a href="Event.Target.html">Event.Target</a></li>
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="event-custom.js.html">event-custom.js</a></li>
<li class=""><a href="event-do.js.html">event-do.js</a></li>
<li class=""><a href="event-dom.js.html">event-dom.js</a></li>
<li class=""><a href="event-facade.js.html">event-facade.js</a></li>
<li class="selected"><a href="event-ready.js.html">event-ready.js</a></li>
<li class=""><a href="event-target.js.html">event-target.js</a></li>
<li class=""><a href="event.js.html">event.js</a></li>
<li class=""><a href="oop.js.html">oop.js</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>