yui-get.js.html revision ace5e2555c33a0ceddef42649f6f38fa006707cc
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
b1c39f37bdd5f51ec6a90991eb0c586867a02da5Matt Sweeney <title>API: yui yui-get.js (YUI Library)</title>
b1c39f37bdd5f51ec6a90991eb0c586867a02da5Matt Sweeney <link rel="stylesheet" type="text/css" href="assets/api.css">
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <script type="text/javascript" src="assets/api-js"></script>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <script type="text/javascript" src="assets/ac-js"></script>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <h3>yui <span class="subtitle">3.00PR1</span></h3>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney > yui-get.js (source view)
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> Show Deprecated</span>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney #doc3 #classopts { display:none; }
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney<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>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <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>
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney <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="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="nx">qidx</span><span class="o">=</span><span class="m">0</span><span class="o">,</span>
<span class="nx">nidx</span><span class="o">=</span><span class="m">0</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="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="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="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="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="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="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="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"></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">scope</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="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="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="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">scope</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="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">"Get utility timeout "</span> <span class="o">+</span> <span class="nx">id</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">scope</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="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="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">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="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="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">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="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="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="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"></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="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="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"></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="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="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">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="nx">purging</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</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="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="nx">q</span><span class="o">.</span><span class="nx">nodes</span> <span class="o">=</span> <span class="o">[];</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">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="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">scope</span> <span class="o">=</span> <span class="nx">q</span><span class="o">.</span><span class="nx">scope</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">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"></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="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="c"></span> <span class="c">// script nodes. Opera, but not FF, supports the onload event for link</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="nx">POLL_FREQ</span><span class="o">:</span> <span class="m">10</span><span class="o">,</span>
<span class="nx">PURGE_THRESH</span><span class="o">:</span> <span class="m">20</span><span class="o">,</span>
<span class="nx">TIMEOUT</span><span class="o">:</span> <span class="m">2000</span><span class="o">,</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="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="c"> * <dd>node or node id that will become the new node's nextSibling</dd></span>
<span class="c"> * &nbsp;&nbsp;["http://yui.yahooapis.com/2.3.1/build/dragdrop/dragdrop-min.js",</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;"http://yui.yahooapis.com/2.3.1/build/animation/animation-min.js"], &#123;</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(o.data); // foo</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Y.DDProxy("dd1"); // also new o.reference("dd1"); would work</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.log("won't cause error because Y is the scope");</span>
<span class="c"> * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.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;&nbsp;&nbsp;console.log("transaction failed");</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="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="c"> * <dd>node or node id that will become the new node's nextSibling</dd></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"> * Y.Get.css(["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",</span>
<span class="c"> * "http://yui.yahooapis.com/2.3.1/build/logger/assets/skins/sam/logger.css"]);</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>