get.js.html revision 4fcbec6145d16637205990699912fb90f6a3807c
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>yui <span class="subtitle">3.00PR1</span></h3>
<p>
> get.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" /> <label for="showprivate">Show Private</label></span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></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">"get"</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">var</span> <span class="nx">ua</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">L</span><span class="o">=</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Lang</span><span class="o">;</span>
<span class="c">/**</span>
<span class="c"> * Provides a mechanism to fetch remote resources and</span>
<span class="c"> * insert them into a document.</span>
<span class="c"> * @module yui</span>
<span class="c"> * @submodule get</span>
<span class="c"> */</span>
<span class="c">/**</span>
<span class="c"> * Fetches and inserts one or more script or link nodes into the document </span>
<span class="c"> * @class Get</span>
<span class="c"> * @static</span>
<span class="c"> */</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Get</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * hash of queues to manage multiple requests</span>
<span class="c"> * @property queues</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">queues</span><span class="o">={},</span>
<span class="c">/**</span>
<span class="c"> * queue index used to generate transaction ids</span>
<span class="c"> * @property qidx</span>
<span class="c"> * @type int</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">qidx</span><span class="o">=</span><span class="m">0</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * node index used to generate unique node ids</span>
<span class="c"> * @property nidx</span>
<span class="c"> * @type int</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">nidx</span><span class="o">=</span><span class="m">0</span><span class="o">,</span>
<span class="c">// ridx=0,</span>
<span class="c"></span>
<span class="c">// sandboxFrame=null,</span>
<span class="c"></span>
<span class="c">/**</span>
<span class="c"> * interal property used to prevent multiple simultaneous purge </span>
<span class="c"> * processes</span>
<span class="c"> * @property purging</span>
<span class="c"> * @type boolean</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">purging</span><span class="o">=</span><span class="kc">false</span><span class="o">;</span>
<span class="c">/** </span>
<span class="c"> * Generates an HTML element, this is not appended to a document</span>
<span class="c"> * @method _node</span>
<span class="c"> * @param type {string} the type of element</span>
<span class="c"> * @param attr {string} the attributes</span>
<span class="c"> * @param win {Window} optional window to create the element in</span>
<span class="c"> * @return {HTMLElement} the generated node</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_node</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">attr</span><span class="o">,</span> <span class="nx">win</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">w</span> <span class="o">=</span> <span class="nx">win</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">win</span><span class="o">,</span> <span class="nx">d</span><span class="o">=</span><span class="nx">w</span><span class="o">.</span><span class="nb">document</span><span class="o">,</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="nx">type</span><span class="o">);</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">attr</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">attr</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">&&</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Object</span><span class="o">.</span><span class="nx">owns</span><span class="o">(</span><span class="nx">attr</span><span class="o">,</span> <span class="nx">i</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">n</span><span class="o">.</span><span class="nx">setAttribute</span><span class="o">(</span><span class="nx">i</span><span class="o">,</span> <span class="nx">attr</span><span class="o">[</span><span class="nx">i</span><span class="o">]);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">n</span><span class="o">;</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Generates a link node</span>
<span class="c"> * @method _linkNode</span>
<span class="c"> * @param url {string} the url for the css file</span>
<span class="c"> * @param win {Window} optional window to create the node in</span>
<span class="c"> * @return {HTMLElement} the generated node</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_linkNode</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">url</span><span class="o">,</span> <span class="nx">win</span><span class="o">,</span> <span class="nx">charset</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="nx">charset</span> <span class="o">||</span> <span class="s2">"utf-8"</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">_node</span><span class="o">(</span><span class="s2">"link"</span><span class="o">,</span> <span class="o">{</span>
<span class="s2">"id"</span><span class="o">:</span> <span class="s2">"yui__dyn_"</span> <span class="o">+</span> <span class="o">(</span><span class="nx">nidx</span><span class="o">++),</span>
<span class="s2">"type"</span><span class="o">:</span> <span class="s2">"text/css"</span><span class="o">,</span>
<span class="s2">"charset"</span><span class="o">:</span> <span class="nx">c</span><span class="o">,</span>
<span class="s2">"rel"</span><span class="o">:</span> <span class="s2">"stylesheet"</span><span class="o">,</span>
<span class="s2">"href"</span><span class="o">:</span> <span class="nx">url</span>
<span class="o">},</span> <span class="nx">win</span><span class="o">);</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Generates a script node</span>
<span class="c"> * @method _scriptNode</span>
<span class="c"> * @param url {string} the url for the script file</span>
<span class="c"> * @param win {Window} optional window to create the node in</span>
<span class="c"> * @return {HTMLElement} the generated node</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_scriptNode</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">url</span><span class="o">,</span> <span class="nx">win</span><span class="o">,</span> <span class="nx">charset</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="nx">charset</span> <span class="o">||</span> <span class="s2">"utf-8"</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">_node</span><span class="o">(</span><span class="s2">"script"</span><span class="o">,</span> <span class="o">{</span>
<span class="s2">"id"</span><span class="o">:</span> <span class="s2">"yui__dyn_"</span> <span class="o">+</span> <span class="o">(</span><span class="nx">nidx</span><span class="o">++),</span>
<span class="s2">"type"</span><span class="o">:</span> <span class="s2">"text/javascript"</span><span class="o">,</span>
<span class="s2">"charset"</span><span class="o">:</span> <span class="nx">c</span><span class="o">,</span>
<span class="s2">"src"</span><span class="o">:</span> <span class="nx">url</span>
<span class="o">},</span> <span class="nx">win</span><span class="o">);</span>
<span class="o">};</span>
<span class="c">/*</span>
<span class="c"> * The request failed, execute fail handler with whatever</span>
<span class="c"> * was accomplished. There isn't a failure case at the</span>
<span class="c"> * moment unless you count aborted transactions</span>
<span class="c"> * @method _fail</span>
<span class="c"> * @param id {string} the id of the request</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_fail</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">msg</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">"get failure: "</span> <span class="o">+</span> <span class="nx">msg</span><span class="o">,</span> <span class="s2">"warn"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">id</span><span class="o">];</span>
<span class="c">// execute failure callback</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">onFailure</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">sc</span><span class="o">=</span><span class="nx">q</span><span class="o">.</span><span class="nx">context</span> <span class="o">||</span> <span class="nx">q</span><span class="o">;</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">onFailure</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">sc</span><span class="o">,</span> <span class="nx">_returnData</span><span class="o">(</span><span class="nx">q</span><span class="o">,</span> <span class="nx">msg</span><span class="o">));</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">_get</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">nId</span><span class="o">,</span> <span class="nx">tId</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">tId</span><span class="o">],</span>
<span class="nx">n</span> <span class="o">=</span> <span class="o">(</span><span class="nx">L</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">nId</span><span class="o">))</span> <span class="o">?</span> <span class="nx">q</span><span class="o">.</span><span class="nx">win</span><span class="o">.</span><span class="nb">document</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">nId</span><span class="o">)</span> <span class="o">:</span> <span class="nx">nId</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">n</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_fail</span><span class="o">(</span><span class="nx">tId</span><span class="o">,</span> <span class="s2">"target node not found: "</span> <span class="o">+</span> <span class="nx">nId</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">n</span><span class="o">;</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Removes the nodes for the specified queue</span>
<span class="c"> * @method _purge</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_purge</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">tId</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">q</span><span class="o">=</span><span class="nx">queues</span><span class="o">[</span><span class="nx">tId</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</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">q</span><span class="o">.</span><span class="nx">nodes</span><span class="o">,</span> <span class="nx">l</span><span class="o">=</span><span class="nx">n</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span> <span class="nx">d</span><span class="o">=</span><span class="nx">q</span><span class="o">.</span><span class="nx">win</span><span class="o">.</span><span class="nb">document</span><span class="o">,</span>
<span class="nx">h</span><span class="o">=</span><span class="nx">d</span><span class="o">.</span><span class="nx">getElementsByTagName</span><span class="o">(</span><span class="s2">"head"</span><span class="o">)[</span><span class="m">0</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">insertBefore</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">s</span> <span class="o">=</span> <span class="nx">_get</span><span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">insertBefore</span><span class="o">,</span> <span class="nx">tId</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">s</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">h</span> <span class="o">=</span> <span class="nx">s</span><span class="o">.</span><span class="nx">parentNode</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span> <span class="nx">i</span><span class="o"><</span><span class="nx">l</span><span class="o">;</span> <span class="nx">i</span><span class="o">=</span><span class="nx">i</span><span class="o">+</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">h</span><span class="o">.</span><span class="nx">removeChild</span><span class="o">(</span><span class="nx">n</span><span class="o">[</span><span class="nx">i</span><span class="o">]);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">nodes</span> <span class="o">=</span> <span class="o">[];</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Returns the data payload for callback functions</span>
<span class="c"> * @method _returnData</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_returnData</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">q</span><span class="o">,</span> <span class="nx">msg</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="o">{</span>
<span class="nx">tId</span><span class="o">:</span> <span class="nx">q</span><span class="o">.</span><span class="nx">tId</span><span class="o">,</span>
<span class="nx">win</span><span class="o">:</span> <span class="nx">q</span><span class="o">.</span><span class="nx">win</span><span class="o">,</span>
<span class="nx">data</span><span class="o">:</span> <span class="nx">q</span><span class="o">.</span><span class="nx">data</span><span class="o">,</span>
<span class="nx">nodes</span><span class="o">:</span> <span class="nx">q</span><span class="o">.</span><span class="nx">nodes</span><span class="o">,</span>
<span class="nx">msg</span><span class="o">:</span> <span class="nx">msg</span><span class="o">,</span>
<span class="nx">purge</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">_purge</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">tId</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * The request is complete, so executing the requester's callback</span>
<span class="c"> * @method _finish</span>
<span class="c"> * @param id {string} the id of the request</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_finish</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">"Finishing transaction "</span> <span class="o">+</span> <span class="nx">id</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">id</span><span class="o">];</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">finished</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">aborted</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">msg</span> <span class="o">=</span> <span class="s2">"transaction "</span> <span class="o">+</span> <span class="nx">id</span> <span class="o">+</span> <span class="s2">" was aborted"</span><span class="o">;</span>
<span class="nx">_fail</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">msg</span><span class="o">);</span>
<span class="k">return</span><span class="o">;</span>
<span class="o">}</span>
<span class="c">// execute success callback</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">onSuccess</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">sc</span><span class="o">=</span><span class="nx">q</span><span class="o">.</span><span class="nx">context</span> <span class="o">||</span> <span class="nx">q</span><span class="o">;</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">onSuccess</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">sc</span><span class="o">,</span> <span class="nx">_returnData</span><span class="o">(</span><span class="nx">q</span><span class="o">));</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Timeout detected</span>
<span class="c"> * @method _timeout</span>
<span class="c"> * @param id {string} the id of the request</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_timeout</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">"Timeout "</span> <span class="o">+</span> <span class="nx">id</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">id</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">onTimeout</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">sc</span><span class="o">=</span><span class="nx">q</span><span class="o">.</span><span class="nx">context</span> <span class="o">||</span> <span class="nx">q</span><span class="o">;</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">onTimeout</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">sc</span><span class="o">,</span> <span class="nx">_returnData</span><span class="o">(</span><span class="nx">q</span><span class="o">));</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Loads the next item for a given request</span>
<span class="c"> * @method _next</span>
<span class="c"> * @param id {string} the id of the request</span>
<span class="c"> * @param loaded {string} the url that was just loaded, if any</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_next</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">loaded</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">"_next: "</span> <span class="o">+</span> <span class="nx">id</span> <span class="o">+</span> <span class="s2">", loaded: "</span> <span class="o">+</span> <span class="nx">loaded</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">id</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">timer</span><span class="o">)</span> <span class="o">{</span>
<span class="c"></span> <span class="nx">q</span><span class="o">.</span><span class="nx">timer</span><span class="o">.</span><span class="nx">cancel</span><span class="o">();</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">aborted</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">msg</span> <span class="o">=</span> <span class="s2">"transaction "</span> <span class="o">+</span> <span class="nx">id</span> <span class="o">+</span> <span class="s2">" was aborted"</span><span class="o">;</span>
<span class="nx">_fail</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">msg</span><span class="o">);</span>
<span class="k">return</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">loaded</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">url</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">varName</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">varName</span><span class="o">.</span><span class="nx">shift</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="c">// This is the first pass: make sure the url is an array</span>
<span class="c"></span> <span class="nx">q</span><span class="o">.</span><span class="nx">url</span> <span class="o">=</span> <span class="o">(</span><span class="nx">L</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">url</span><span class="o">))</span> <span class="o">?</span> <span class="o">[</span><span class="nx">q</span><span class="o">.</span><span class="nx">url</span><span class="o">]</span> <span class="o">:</span> <span class="nx">q</span><span class="o">.</span><span class="nx">url</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">varName</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">varName</span> <span class="o">=</span> <span class="o">(</span><span class="nx">L</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">varName</span><span class="o">))</span> <span class="o">?</span> <span class="o">[</span><span class="nx">q</span><span class="o">.</span><span class="nx">varName</span><span class="o">]</span> <span class="o">:</span> <span class="nx">q</span><span class="o">.</span><span class="nx">varName</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">w</span><span class="o">=</span><span class="nx">q</span><span class="o">.</span><span class="nx">win</span><span class="o">,</span> <span class="nx">d</span><span class="o">=</span><span class="nx">w</span><span class="o">.</span><span class="nb">document</span><span class="o">,</span> <span class="nx">h</span><span class="o">=</span><span class="nx">d</span><span class="o">.</span><span class="nx">getElementsByTagName</span><span class="o">(</span><span class="s2">"head"</span><span class="o">)[</span><span class="m">0</span><span class="o">],</span> <span class="nx">n</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">url</span><span class="o">.</span><span class="nx">length</span> <span class="o">===</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_finish</span><span class="o">(</span><span class="nx">id</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">url</span> <span class="o">=</span> <span class="nx">q</span><span class="o">.</span><span class="nx">url</span><span class="o">[</span><span class="m">0</span><span class="o">];</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">"attempting to load "</span> <span class="o">+</span> <span class="nx">url</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">timeout</span><span class="o">)</span> <span class="o">{</span>
<span class="c"></span> <span class="nx">q</span><span class="o">.</span><span class="nx">timer</span> <span class="o">=</span> <span class="nx">L</span><span class="o">.</span><span class="nx">later</span><span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">timeout</span><span class="o">,</span> <span class="nx">q</span><span class="o">,</span> <span class="nx">_timeout</span><span class="o">,</span> <span class="nx">id</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"script"</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">n</span> <span class="o">=</span> <span class="nx">_scriptNode</span><span class="o">(</span><span class="nx">url</span><span class="o">,</span> <span class="nx">w</span><span class="o">,</span> <span class="nx">q</span><span class="o">.</span><span class="nx">charset</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">n</span> <span class="o">=</span> <span class="nx">_linkNode</span><span class="o">(</span><span class="nx">url</span><span class="o">,</span> <span class="nx">w</span><span class="o">,</span> <span class="nx">q</span><span class="o">.</span><span class="nx">charset</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">// track this node's load progress</span>
<span class="c"></span> <span class="nx">_track</span><span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">type</span><span class="o">,</span> <span class="nx">n</span><span class="o">,</span> <span class="nx">id</span><span class="o">,</span> <span class="nx">url</span><span class="o">,</span> <span class="nx">w</span><span class="o">,</span> <span class="nx">q</span><span class="o">.</span><span class="nx">url</span><span class="o">.</span><span class="nx">length</span><span class="o">);</span>
<span class="c">// add the node to the queue so we can return it to the user supplied callback</span>
<span class="c"></span> <span class="nx">q</span><span class="o">.</span><span class="nx">nodes</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">n</span><span class="o">);</span>
<span class="c">// add it to the head or insert it before 'insertBefore'</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">insertBefore</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">s</span> <span class="o">=</span> <span class="nx">_get</span><span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">insertBefore</span><span class="o">,</span> <span class="nx">id</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">s</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">s</span><span class="o">.</span><span class="nx">parentNode</span><span class="o">.</span><span class="nx">insertBefore</span><span class="o">(</span><span class="nx">n</span><span class="o">,</span> <span class="nx">s</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">h</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">n</span><span class="o">);</span>
<span class="o">}</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">"Appending node: "</span> <span class="o">+</span> <span class="nx">url</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="c">// FireFox does not support the onload event for link nodes, so there is</span>
<span class="c"></span> <span class="c">// no way to make the css requests synchronous. This means that the css </span>
<span class="c"></span> <span class="c">// rules in multiple files could be applied out of order in this browser</span>
<span class="c"></span> <span class="c">// if a later request returns before an earlier one. Safari too.</span>
<span class="c"></span> <span class="k">if</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">ua</span><span class="o">.</span><span class="nx">gecko</span><span class="o">)</span> <span class="o">&&</span> <span class="nx">q</span><span class="o">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"css"</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_next</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">url</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Removes processed queues and corresponding nodes</span>
<span class="c"> * @method _autoPurge</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_autoPurge</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">purging</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span><span class="o">;</span>
<span class="o">}</span>
<span class="nx">purging</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">queues</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">queues</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">i</span><span class="o">))</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">autopurge</span> <span class="o">&&</span> <span class="nx">q</span><span class="o">.</span><span class="nx">finished</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_purge</span><span class="o">(</span><span class="nx">q</span><span class="o">.</span><span class="nx">tId</span><span class="o">);</span>
<span class="nx">delete</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="nx">purging</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"> * Saves the state for the request and begins loading</span>
<span class="c"> * the requested urls</span>
<span class="c"> * @method queue</span>
<span class="c"> * @param type {string} the type of node to insert</span>
<span class="c"> * @param url {string} the url to load</span>
<span class="c"> * @param opts the hash of options for this request</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_queue</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">url</span><span class="o">,</span> <span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="s2">"q"</span> <span class="o">+</span> <span class="o">(</span><span class="nx">qidx</span><span class="o">++);</span>
<span class="nx">opts</span> <span class="o">=</span> <span class="nx">opts</span> <span class="o">||</span> <span class="o">{};</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">qidx</span> <span class="o">%</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Get</span><span class="o">.</span><span class="nx">PURGE_THRESH</span> <span class="o">===</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_autoPurge</span><span class="o">();</span>
<span class="o">}</span>
<span class="nx">queues</span><span class="o">[</span><span class="nx">id</span><span class="o">]</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="nx">opts</span><span class="o">,</span> <span class="o">{</span>
<span class="nx">tId</span><span class="o">:</span> <span class="nx">id</span><span class="o">,</span>
<span class="nx">type</span><span class="o">:</span> <span class="nx">type</span><span class="o">,</span>
<span class="nx">url</span><span class="o">:</span> <span class="nx">url</span><span class="o">,</span>
<span class="nx">finished</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>
<span class="nx">nodes</span><span class="o">:</span> <span class="o">[]</span>
<span class="o">});</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">id</span><span class="o">];</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">win</span> <span class="o">=</span> <span class="nx">q</span><span class="o">.</span><span class="nx">win</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">win</span><span class="o">;</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">context</span> <span class="o">=</span> <span class="nx">q</span><span class="o">.</span><span class="nx">context</span> <span class="o">||</span> <span class="nx">q</span><span class="o">;</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">autopurge</span> <span class="o">=</span> <span class="o">(</span><span class="s2">"autopurge"</span> <span class="k">in</span> <span class="nx">q</span><span class="o">)</span> <span class="o">?</span> <span class="nx">q</span><span class="o">.</span><span class="nx">autopurge</span> <span class="o">:</span>
<span class="o">(</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"script"</span><span class="o">)</span> <span class="o">?</span> <span class="kc">true</span> <span class="o">:</span> <span class="kc">false</span><span class="o">;</span>
<span class="nx">L</span><span class="o">.</span><span class="nx">later</span><span class="o">(</span><span class="m">0</span><span class="o">,</span> <span class="nx">q</span><span class="o">,</span> <span class="nx">_next</span><span class="o">,</span> <span class="nx">id</span><span class="o">);</span>
<span class="k">return</span> <span class="o">{</span>
<span class="nx">tId</span><span class="o">:</span> <span class="nx">id</span>
<span class="o">};</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Detects when a node has been loaded. In the case of</span>
<span class="c"> * script nodes, this does not guarantee that contained</span>
<span class="c"> * script is ready to use.</span>
<span class="c"> * @method _track</span>
<span class="c"> * @param type {string} the type of node to track</span>
<span class="c"> * @param n {HTMLElement} the node to track</span>
<span class="c"> * @param id {string} the id of the request</span>
<span class="c"> * @param url {string} the url that is being loaded</span>
<span class="c"> * @param win {Window} the targeted window</span>
<span class="c"> * @param qlength the number of remaining items in the queue,</span>
<span class="c"> * including this one</span>
<span class="c"> * @param trackfn {Function} function to execute when finished</span>
<span class="c"> * the default is _next</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">_track</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">n</span><span class="o">,</span> <span class="nx">id</span><span class="o">,</span> <span class="nx">url</span><span class="o">,</span> <span class="nx">win</span><span class="o">,</span> <span class="nx">qlength</span><span class="o">,</span> <span class="nx">trackfn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">f</span> <span class="o">=</span> <span class="nx">trackfn</span> <span class="o">||</span> <span class="nx">_next</span><span class="o">;</span>
<span class="c">// IE supports the readystatechange event for script and css nodes</span>
<span class="c"></span> <span class="k">if</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">n</span><span class="o">.</span><span class="nx">onreadystatechange</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="k">this</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">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="nx">id</span> <span class="o">+</span> <span class="s2">" onload "</span> <span class="o">+</span> <span class="nx">url</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="nx">f</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">url</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</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">ua</span><span class="o">.</span><span class="nx">webkit</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"script"</span><span class="o">)</span> <span class="o">{</span>
<span class="c"></span> <span class="nx">n</span><span class="o">.</span><span class="nx">addEventListener</span><span class="o">(</span><span class="s2">"load"</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">log</span><span class="o">(</span><span class="nx">id</span> <span class="o">+</span> <span class="s2">" DOM2 onload "</span> <span class="o">+</span> <span class="nx">url</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="nx">f</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">url</span><span class="o">);</span>
<span class="o">});</span>
<span class="o">}</span>
<span class="c">// FireFox and Opera support onload (but not DOM2 in FF) handlers for</span>
<span class="c"></span> <span class="c">// script nodes. Opera, but not FF, supports the onload event for link</span>
<span class="c"></span> <span class="c">// nodes.</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">n</span><span class="o">.</span><span class="nx">onload</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">log</span><span class="o">(</span><span class="nx">id</span> <span class="o">+</span> <span class="s2">" onload "</span> <span class="o">+</span> <span class="nx">url</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="nx">f</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">url</span><span class="o">);</span>
<span class="o">};</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="k">return</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * The number of request required before an automatic purge.</span>
<span class="c"> * property PURGE_THRESH</span>
<span class="c"> * @static</span>
<span class="c"> * @type int</span>
<span class="c"> * @default 20</span>
<span class="c"> */</span>
<span class="nx">PURGE_THRESH</span><span class="o">:</span> <span class="m">20</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Called by the the helper for detecting script load in Safari</span>
<span class="c"> * @method _finalize</span>
<span class="c"> * @param id {string} the transaction id</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_finalize</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="nx">id</span> <span class="o">+</span> <span class="s2">" finalized "</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="nx">L</span><span class="o">.</span><span class="nx">later</span><span class="o">(</span><span class="m">0</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="nx">_finish</span><span class="o">,</span> <span class="nx">id</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Abort a transaction</span>
<span class="c"> * @method abort</span>
<span class="c"> * @param o {string|object} Either the tId or the object returned from</span>
<span class="c"> * script() or css()</span>
<span class="c"> */</span>
<span class="nx">abort</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">o</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="o">(</span><span class="nx">L</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">o</span><span class="o">))</span> <span class="o">?</span> <span class="nx">o</span> <span class="o">:</span> <span class="nx">o</span><span class="o">.</span><span class="nx">tId</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">q</span> <span class="o">=</span> <span class="nx">queues</span><span class="o">[</span><span class="nx">id</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">q</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">"Aborting "</span> <span class="o">+</span> <span class="nx">id</span><span class="o">,</span> <span class="s2">"info"</span><span class="o">,</span> <span class="s2">"Get"</span><span class="o">);</span>
<span class="nx">q</span><span class="o">.</span><span class="nx">aborted</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Fetches and inserts one or more script nodes into the head</span>
<span class="c"> * of the current document or the document in a specified window.</span>
<span class="c"> *</span>
<span class="c"> * @method script</span>
<span class="c"> * @static</span>
<span class="c"> * @param url {string|string[]} the url or urls to the script(s)</span>
<span class="c"> * @param opts {object} Options: </span>
<span class="c"> * <dl></span>
<span class="c"> * <dt>onSuccess</dt></span>
<span class="c"> * <dd></span>
<span class="c"> * callback to execute when the script(s) are finished loading</span>
<span class="c"> * The callback receives an object back with the following</span>
<span class="c"> * data:</span>
<span class="c"> * <dl></span>
<span class="c"> * <dt>win</dt></span>
<span class="c"> * <dd>the window the script(s) were inserted into</dd></span>
<span class="c"> * <dt>data</dt></span>
<span class="c"> * <dd>the data object passed in when the request was made</dd></span>
<span class="c"> * <dt>nodes</dt></span>
<span class="c"> * <dd>An array containing references to the nodes that were</span>
<span class="c"> * inserted</dd></span>
<span class="c"> * <dt>purge</dt></span>
<span class="c"> * <dd>A function that, when executed, will remove the nodes</span>
<span class="c"> * that were inserted</dd></span>
<span class="c"> * <dt></span>
<span class="c"> * </dl></span>
<span class="c"> * </dd></span>
<span class="c"> * <dt>onTimeout</dt></span>
<span class="c"> * <dd></span>
<span class="c"> * callback to execute when a timeout occurs.</span>
<span class="c"> * The callback receives an object back with the following</span>
<span class="c"> * data:</span>
<span class="c"> * <dl></span>
<span class="c"> * <dt>win</dt></span>
<span class="c"> * <dd>the window the script(s) were inserted into</dd></span>
<span class="c"> * <dt>data</dt></span>
<span class="c"> * <dd>the data object passed in when the request was made</dd></span>
<span class="c"> * <dt>nodes</dt></span>
<span class="c"> * <dd>An array containing references to the nodes that were</span>
<span class="c"> * inserted</dd></span>
<span class="c"> * <dt>purge</dt></span>
<span class="c"> * <dd>A function that, when executed, will remove the nodes</span>
<span class="c"> * that were inserted</dd></span>
<span class="c"> * <dt></span>
<span class="c"> * </dl></span>
<span class="c"> * </dd></span>
<span class="c"> * <dt>onFailure</dt></span>
<span class="c"> * <dd></span>
<span class="c"> * callback to execute when the script load operation fails</span>
<span class="c"> * The callback receives an object back with the following</span>
<span class="c"> * data:</span>
<span class="c"> * <dl></span>
<span class="c"> * <dt>win</dt></span>
<span class="c"> * <dd>the window the script(s) were inserted into</dd></span>
<span class="c"> * <dt>data</dt></span>
<span class="c"> * <dd>the data object passed in when the request was made</dd></span>
<span class="c"> * <dt>nodes</dt></span>
<span class="c"> * <dd>An array containing references to the nodes that were</span>
<span class="c"> * inserted successfully</dd></span>
<span class="c"> * <dt>purge</dt></span>
<span class="c"> * <dd>A function that, when executed, will remove any nodes</span>
<span class="c"> * that were inserted</dd></span>
<span class="c"> * <dt></span>
<span class="c"> * </dl></span>
<span class="c"> * </dd></span>
<span class="c"> * <dt>context</dt></span>
<span class="c"> * <dd>the execution context for the callbacks</dd></span>
<span class="c"> * <dt>win</dt></span>
<span class="c"> * <dd>a window other than the one the utility occupies</dd></span>
<span class="c"> * <dt>autopurge</dt></span>
<span class="c"> * <dd></span>
<span class="c"> * setting to true will let the utilities cleanup routine purge </span>
<span class="c"> * the script once loaded</span>
<span class="c"> * </dd></span>
<span class="c"> * <dt>data</dt></span>
<span class="c"> * <dd></span>
<span class="c"> * data that is supplied to the callback when the script(s) are</span>
<span class="c"> * loaded.</span>
<span class="c"> * </dd></span>
<span class="c"> * <dt>insertBefore</dt></span>
<span class="c"> * <dd>node or node id that will become the new node's nextSibling</dd></span>
<span class="c"> * </dl></span>
<span class="c"> * <dt>charset</dt></span>
<span class="c"> * <dd>Node charset, default utf-8</dd></span>
<span class="c"> * <dt>timeout</dt></span>
<span class="c"> * <dd>Number of milliseconds to wait before aborting and firing the timeout event</dd></span>
<span class="c"> * <pre></span>
<span class="c"> * &nbsp;&nbsp;["http://yui.yahooapis.com/2.5.2/build/yahoo/yahoo-min.js",</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;"http://yui.yahooapis.com/2.5.2/build/event/event-min.js"], &#123;</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;onSuccess: function(o) &#123;</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.log("won't cause error because Y is the context");</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log(o.data); // foo</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log(o.nodes.length === 2) // true</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// o.purge(); // optionally remove the script nodes immediately</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;onFailure: function(o) &#123;</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log("transaction failed");</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;onTimeout: function(o) &#123;</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log("transaction timed out");</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;data: "foo",</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;timeout: 10000, // 10 second timeout</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;context: Y, // make the YUI instance</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;// win: otherframe // target another window/frame</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;autopurge: true // allow the utility to choose when to remove the nodes</span>
<span class="c"> * &nbsp;&nbsp;&#125;);</span>
<span class="c"> * </pre></span>
<span class="c"> * @return {tId: string} an object containing info about the transaction</span>
<span class="c"> */</span>
<span class="nx">script</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">url</span><span class="o">,</span> <span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">_queue</span><span class="o">(</span><span class="s2">"script"</span><span class="o">,</span> <span class="nx">url</span><span class="o">,</span> <span class="nx">opts</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Fetches and inserts one or more css link nodes into the </span>
<span class="c"> * head of the current document or the document in a specified</span>
<span class="c"> * window.</span>
<span class="c"> * @method css</span>
<span class="c"> * @static</span>
<span class="c"> * @param url {string} the url or urls to the css file(s)</span>
<span class="c"> * @param opts Options: </span>
<span class="c"> * <dl></span>
<span class="c"> * <dt>onSuccess</dt></span>
<span class="c"> * <dd></span>
<span class="c"> * callback to execute when the css file(s) are finished loading</span>
<span class="c"> * The callback receives an object back with the following</span>
<span class="c"> * data:</span>
<span class="c"> * <dl>win</dl></span>
<span class="c"> * <dd>the window the link nodes(s) were inserted into</dd></span>
<span class="c"> * <dt>data</dt></span>
<span class="c"> * <dd>the data object passed in when the request was made</dd></span>
<span class="c"> * <dt>nodes</dt></span>
<span class="c"> * <dd>An array containing references to the nodes that were</span>
<span class="c"> * inserted</dd></span>
<span class="c"> * <dt>purge</dt></span>
<span class="c"> * <dd>A function that, when executed, will remove the nodes</span>
<span class="c"> * that were inserted</dd></span>
<span class="c"> * <dt></span>
<span class="c"> * </dl></span>
<span class="c"> * </dd></span>
<span class="c"> * <dt>context</dt></span>
<span class="c"> * <dd>the execution context for the callbacks</dd></span>
<span class="c"> * <dt>win</dt></span>
<span class="c"> * <dd>a window other than the one the utility occupies</dd></span>
<span class="c"> * <dt>data</dt></span>
<span class="c"> * <dd></span>
<span class="c"> * data that is supplied to the callbacks when the nodes(s) are</span>
<span class="c"> * loaded.</span>
<span class="c"> * </dd></span>
<span class="c"> * <dt>insertBefore</dt></span>
<span class="c"> * <dd>node or node id that will become the new node's nextSibling</dd></span>
<span class="c"> * <dt>charset</dt></span>
<span class="c"> * <dd>Node charset, default utf-8</dd></span>
<span class="c"> * </dl></span>
<span class="c"> * <pre></span>
<span class="c"> * Y.Get.css("http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css");</span>
<span class="c"> * </pre></span>
<span class="c"> * <pre></span>
<span class="c"> * &nbsp;&nbsp;["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;"http://yui.yahooapis.com/2.3.1/build/logger/assets/skins/sam/logger.css"], &#123;</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;insertBefore: 'custom-styles' // nodes will be inserted before the specified node</span>
<span class="c"> * &nbsp;&nbsp;&#125;);</span>
<span class="c"> * </pre></span>
<span class="c"> * @return {tId: string} an object containing info about the transaction</span>
<span class="c"> */</span>
<span class="nx">css</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">url</span><span class="o">,</span> <span class="nx">opts</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">_queue</span><span class="o">(</span><span class="s2">"css"</span><span class="o">,</span> <span class="nx">url</span><span class="o">,</span> <span class="nx">opts</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="o">}();</span>
<span class="o">},</span> <span class="s2">"@VERSION@"</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>