yui.js.html revision eb9b6f817df5c660be9f00fc5d27fe33479fdc98
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>API: yui yui.js (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/api.css">
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
<h3>yui&nbsp; <span class="subtitle">3.00PR1</span></h3>
<p>
<a href="/index.html">Yahoo! UI Library</a>
&gt; <a href="/module_yui.html">yui</a>
&gt; yui.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> Show Deprecated</span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre><span class="o">(</span><span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">_instances</span> <span class="o">=</span> <span class="o">{},</span>
<span class="c">// @TODO: this needs to be created at build time from module metadata</span>
<span class="c"></span>
<span class="nx">_APPLY_TO_WHITE_LIST</span> <span class="o">=</span> <span class="o">{</span>
<span class="s1">&#39;io.xdrReady&#39;</span><span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="s1">&#39;io.start&#39;</span><span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="s1">&#39;io.success&#39;</span><span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="s1">&#39;io.failure&#39;</span><span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="s1">&#39;io.abort&#39;</span><span class="o">:</span> <span class="m">1</span>
<span class="o">};</span>
<span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">YUI</span> <span class="o">===</span> <span class="s1">&#39;undefined&#39;</span> <span class="o">||</span> <span class="o">!</span><span class="nx">YUI</span><span class="o">)</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * The YUI global namespace object. If YUI is already defined, the</span>
<span class="c"> * existing YUI object will not be overwritten so that defined</span>
<span class="c"> * namespaces are preserved. </span>
<span class="c"> *</span>
<span class="c"> * @class YUI</span>
<span class="c"> * @constructor</span>
<span class="c"> * @global</span>
<span class="c"> * @uses Event.Target</span>
<span class="c"> * @param o Optional configuration object. Options:</span>
<span class="c"> * &lt;ul&gt;</span>
<span class="c"> * &lt;li&gt;------------------------------------------------------------------------&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;Global:&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;------------------------------------------------------------------------&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;debug:</span>
<span class="c"> * Turn debug statements on or off&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;useConsole:</span>
<span class="c"> * Log to the browser console if debug is on and the console is available&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;logInclude:</span>
<span class="c"> * A list of log sources that should be logged. If specified, only log messages from these sources will be logged.&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;logExclude:</span>
<span class="c"> * A list of log sources that should be not be logged. If specified, all sources are logged if not on this list.&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;throwFail:</span>
<span class="c"> * If throwFail is set, Y.fail will generate or re-throw a JS error. Otherwise the failure is logged.</span>
<span class="c"> * &lt;li&gt;win:</span>
<span class="c"> * The target window/frame&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;core:</span>
<span class="c"> * A list of modules that defines the YUI core (overrides the default)&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;------------------------------------------------------------------------&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;For event and get:&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;------------------------------------------------------------------------&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;pollInterval:</span>
<span class="c"> * The default poll interval&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;-------------------------------------------------------------------------&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;For loader:&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;-------------------------------------------------------------------------&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;base:</span>
<span class="c"> * The base dir&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;secureBase:</span>
<span class="c"> * The secure base dir (not implemented)&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;comboBase:</span>
<span class="c"> * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;root:</span>
<span class="c"> * The root path to prepend to module names for the combo service. Ex: 2.5.2/build/&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;filter:</span>
<span class="c"> * </span>
<span class="c"> * A filter to apply to result urls. This filter will modify the default</span>
<span class="c"> * path for all modules. The default path for the YUI library is the</span>
<span class="c"> * minified version of the files (e.g., event-min.js). The filter property</span>
<span class="c"> * can be a predefined filter or a custom filter. The valid predefined </span>
<span class="c"> * filters are:</span>
<span class="c"> * &lt;dl&gt;</span>
<span class="c"> * &lt;dt&gt;DEBUG&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;Selects the debug versions of the library (e.g., event-debug.js).</span>
<span class="c"> * This option will automatically include the logger widget&lt;/dd&gt;</span>
<span class="c"> * &lt;dt&gt;RAW&lt;/dt&gt;</span>
<span class="c"> * &lt;dd&gt;Selects the non-minified version of the library (e.g., event.js).&lt;/dd&gt;</span>
<span class="c"> * &lt;/dl&gt;</span>
<span class="c"> * You can also define a custom filter, which must be an object literal </span>
<span class="c"> * containing a search expression and a replace string:</span>
<span class="c"> * &lt;pre&gt;</span>
<span class="c"> * myFilter: &amp;#123; </span>
<span class="c"> * &#39;searchExp&#39;: &quot;-min\\.js&quot;, </span>
<span class="c"> * &#39;replaceStr&#39;: &quot;-debug.js&quot;</span>
<span class="c"> * &amp;#125;</span>
<span class="c"> * &lt;/pre&gt;</span>
<span class="c"> *</span>
<span class="c"> * &lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;combine:</span>
<span class="c"> * Use the YUI combo service to reduce the number of http connections required to load your dependencies&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;ignore:</span>
<span class="c"> * A list of modules that should never be dynamically loaded&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;force:</span>
<span class="c"> * A list of modules that should always be loaded when required, even if already present on the page&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;insertBefore:</span>
<span class="c"> * Node or id for a node that should be used as the insertion point for new nodes&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;charset:</span>
<span class="c"> * charset for dynamic nodes&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;timeout:</span>
<span class="c"> * number of milliseconds before a timeout occurs when dynamically loading nodes. in not set, there is no timeout&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;context:</span>
<span class="c"> * execution context for all callbacks&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;onSuccess:</span>
<span class="c"> * callback for the &#39;success&#39; event&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;onFailure:</span>
<span class="c"> * callback for the &#39;failure&#39; event&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;onTimeout:</span>
<span class="c"> * callback for the &#39;timeout&#39; event&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;onProgress:</span>
<span class="c"> * callback executed each time a script or css file is loaded&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;modules:</span>
<span class="c"> * A list of module definitions. See Loader.addModule for the supported module metadata&lt;/li&gt;</span>
<span class="c"> * &lt;/ul&gt;</span>
<span class="c"> */</span>
<span class="c">/*global YUI*/</span>
<span class="nx">YUI</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">Y</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="c">// Allow var yui = YUI() instead of var yui = new YUI()</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span> <span class="o">==</span> <span class="nb">window</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">YUI</span><span class="o">(</span><span class="nx">o</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="c">// set up the core environment</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">_init</span><span class="o">(</span><span class="nx">o</span><span class="o">);</span>
<span class="c">// bind the specified additional modules for this instance</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">_setup</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="o">}</span>
<span class="c">// The prototype contains the functions that are required to allow the external</span>
<span class="c">// modules to be registered and for the instance to be initialized.</span>
<span class="c"></span><span class="nx">YUI</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Initialize this YUI instance</span>
<span class="c"> * @param o config options</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_init</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="nx">o</span> <span class="o">=</span> <span class="nx">o</span> <span class="o">||</span> <span class="o">{};</span>
<span class="c">// find targeted window and @TODO create facades</span>
<span class="c"></span> <span class="k">var</span> <span class="nx">w</span> <span class="o">=</span> <span class="o">(</span><span class="nx">o</span><span class="o">.</span><span class="nx">win</span><span class="o">)</span> <span class="o">?</span> <span class="o">(</span><span class="nx">o</span><span class="o">.</span><span class="nx">win</span><span class="o">.</span><span class="nx">contentWindow</span><span class="o">)</span> <span class="o">:</span> <span class="nx">o</span><span class="o">.</span><span class="nx">win</span> <span class="o">||</span> <span class="nb">window</span><span class="o">;</span>
<span class="nx">o</span><span class="o">.</span><span class="nx">win</span> <span class="o">=</span> <span class="nx">w</span><span class="o">;</span>
<span class="nx">o</span><span class="o">.</span><span class="nx">doc</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">o</span><span class="o">.</span><span class="nx">debug</span> <span class="o">=</span> <span class="o">(</span><span class="s1">&#39;debug&#39;</span> <span class="k">in</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">debug</span> <span class="o">:</span> <span class="kc">true</span><span class="o">;</span>
<span class="nx">o</span><span class="o">.</span><span class="nx">useConsole</span> <span class="o">=</span> <span class="o">(</span><span class="s1">&#39;useConsole&#39;</span> <span class="k">in</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">debug</span> <span class="o">:</span> <span class="kc">true</span><span class="o">;</span>
<span class="c">// add a reference to o for anything that needs it</span>
<span class="c"></span> <span class="c">// before _setup is called.</span>
<span class="c"></span> <span class="k">this</span><span class="o">.</span><span class="nx">config</span> <span class="o">=</span> <span class="nx">o</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="nx">Env</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">// @todo expand the new module metadata</span>
<span class="c"></span> <span class="nx">mods</span><span class="o">:</span> <span class="o">{},</span>
<span class="nx">_idx</span><span class="o">:</span> <span class="m">0</span><span class="o">,</span>
<span class="nx">_pre</span><span class="o">:</span> <span class="s1">&#39;yuid&#39;</span><span class="o">,</span>
<span class="nx">_used</span><span class="o">:</span> <span class="o">{},</span>
<span class="nx">_attached</span><span class="o">:</span> <span class="o">{},</span>
<span class="nx">_yidx</span><span class="o">:</span> <span class="m">0</span><span class="o">,</span>
<span class="nx">_uidx</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">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_yidx</span> <span class="o">=</span> <span class="o">++</span><span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_idx</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="nx">id</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="nx">_instances</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">id</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">constructor</span> <span class="o">=</span> <span class="nx">YUI</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">id</span> <span class="o">+</span> <span class="s1">&#39;) init &#39;</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Finishes the instance setup. Attaches whatever modules were defined</span>
<span class="c"> * when the yui modules was registered.</span>
<span class="c"> * @method _setup</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">_setup</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">this</span><span class="o">.</span><span class="nx">use</span><span class="o">(</span><span class="s2">&quot;yui&quot;</span><span class="o">);</span>
<span class="c">// @TODO eval the need to copy the config</span>
<span class="c"></span> <span class="k">this</span><span class="o">.</span><span class="nx">config</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">merge</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">config</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Executes a method on a YUI instance with</span>
<span class="c"> * the specified id if the specified method is whitelisted.</span>
<span class="c"> * @method applyTo</span>
<span class="c"> * @param id {string} the YUI instance id</span>
<span class="c"> * @param method {string} the name of the method to exectute.</span>
<span class="c"> * Ex: &#39;Object.keys&#39;</span>
<span class="c"> * @param args {Array} the arguments to apply to the method</span>
<span class="c"> * @return {object} the return value from the applied method or null</span>
<span class="c"> */</span>
<span class="nx">applyTo</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">method</span><span class="o">,</span> <span class="nx">args</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!(</span><span class="nx">method</span> <span class="k">in</span> <span class="nx">_APPLY_TO_WHITE_LIST</span><span class="o">))</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">fail</span><span class="o">(</span><span class="nx">method</span> <span class="o">+</span> <span class="s1">&#39;: applyTo not allowed&#39;</span><span class="o">);</span>
<span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">instance</span> <span class="o">=</span> <span class="nx">_instances</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">instance</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">nest</span> <span class="o">=</span> <span class="nx">method</span><span class="o">.</span><span class="nx">split</span><span class="o">(</span><span class="s1">&#39;.&#39;</span><span class="o">),</span> <span class="nx">m</span> <span class="o">=</span> <span class="nx">instance</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">&lt;</span><span class="nx">nest</span><span class="o">.</span><span class="nx">length</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">m</span> <span class="o">=</span> <span class="nx">m</span><span class="o">[</span><span class="nx">nest</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">m</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">fail</span><span class="o">(</span><span class="s1">&#39;applyTo not found: &#39;</span> <span class="o">+</span> <span class="nx">method</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">m</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">instance</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Register a module</span>
<span class="c"> * @method add</span>
<span class="c"> * @param name {string} module name</span>
<span class="c"> * @param namespace {string} name space for the module</span>
<span class="c"> * @param fn {Function} entry point into the module that</span>
<span class="c"> * is used to bind module to the YUI instance</span>
<span class="c"> * @param version {string} version string</span>
<span class="c"> * @return {YUI} the YUI instance</span>
<span class="c"> *</span>
<span class="c"> * requires - features that should be present before loading</span>
<span class="c"> * optional - optional features that should be present if load optional defined</span>
<span class="c"> * use - features that should be attached automatically</span>
<span class="c"> * skinnable -</span>
<span class="c"> * rollup</span>
<span class="c"> * omit - features that should not be loaded if this module is present</span>
<span class="c"> */</span>
<span class="nx">add</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">version</span><span class="o">,</span> <span class="nx">details</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// this.log(&#39;Adding a new component &#39; + name);</span>
<span class="c"></span>
<span class="c">// @todo expand this to include version mapping</span>
<span class="c"></span>
<span class="c">// @todo allow requires/supersedes</span>
<span class="c"></span>
<span class="c">// @todo may want to restore the build property</span>
<span class="c"></span>
<span class="c">// @todo fire moduleAvailable event</span>
<span class="c"></span>
<span class="k">var</span> <span class="nx">m</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">name</span><span class="o">:</span> <span class="nx">name</span><span class="o">,</span>
<span class="nx">fn</span><span class="o">:</span> <span class="nx">fn</span><span class="o">,</span>
<span class="nx">version</span><span class="o">:</span> <span class="nx">version</span><span class="o">,</span>
<span class="nx">details</span><span class="o">:</span> <span class="nx">details</span> <span class="o">||</span> <span class="o">{}</span>
<span class="o">};</span>
<span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">mods</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">=</span> <span class="nx">m</span><span class="o">;</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span> <span class="c">// chain support</span>
<span class="c"></span> <span class="o">},</span>
<span class="nx">_attach</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">r</span><span class="o">,</span> <span class="nx">fromLoader</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">mods</span> <span class="o">=</span> <span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">mods</span><span class="o">,</span>
<span class="nx">attached</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_attached</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">l</span><span class="o">=</span><span class="nx">r</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</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="k">var</span> <span class="nx">name</span> <span class="o">=</span> <span class="nx">r</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> <span class="nx">m</span> <span class="o">=</span> <span class="nx">mods</span><span class="o">[</span><span class="nx">name</span><span class="o">],</span> <span class="nx">mm</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">attached</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nx">m</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">attached</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">d</span> <span class="o">=</span> <span class="nx">m</span><span class="o">.</span><span class="nx">details</span><span class="o">,</span> <span class="nx">req</span> <span class="o">=</span> <span class="nx">d</span><span class="o">.</span><span class="nx">requires</span><span class="o">,</span> <span class="nx">use</span> <span class="o">=</span> <span class="nx">d</span><span class="o">.</span><span class="nx">use</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">req</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_attach</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nb">Array</span><span class="o">(</span><span class="nx">req</span><span class="o">));</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;attaching &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;YUI&#39;</span><span class="o">);</span>
<span class="nx">m</span><span class="o">.</span><span class="nx">fn</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">use</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_attach</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nb">Array</span><span class="o">(</span><span class="nx">use</span><span class="o">));</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Bind a module to a YUI instance</span>
<span class="c"> * @param modules* {string} 1-n modules to bind (uses arguments array)</span>
<span class="c"> * @param *callback {function} callback function executed when </span>
<span class="c"> * the instance has the required functionality. If included, it</span>
<span class="c"> * must be the last parameter.</span>
<span class="c"> *</span>
<span class="c"> * @TODO </span>
<span class="c"> * Implement versioning? loader can load different versions?</span>
<span class="c"> * Should sub-modules/plugins be normal modules, or do</span>
<span class="c"> * we add syntax for specifying these?</span>
<span class="c"> *</span>
<span class="c"> * YUI().use(&#39;dragdrop&#39;)</span>
<span class="c"> * YUI().use(&#39;dragdrop:2.4.0&#39;); // specific version</span>
<span class="c"> * YUI().use(&#39;dragdrop:2.4.0-&#39;); // at least this version</span>
<span class="c"> * YUI().use(&#39;dragdrop:2.4.0-2.9999.9999&#39;); // version range</span>
<span class="c"> * YUI().use(&#39;*&#39;); // use all available modules</span>
<span class="c"> * YUI().use(&#39;lang+dump+substitute&#39;); // use lang and some plugins</span>
<span class="c"> * YUI().use(&#39;lang+*&#39;); // use lang and all known plugins</span>
<span class="c"> *</span>
<span class="c"> *</span>
<span class="c"> * @return {YUI} the YUI instance</span>
<span class="c"> */</span>
<span class="nx">use</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">Y</span> <span class="o">=</span> <span class="k">this</span><span class="o">,</span>
<span class="nx">a</span><span class="o">=</span><span class="nb">Array</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">slice</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">arguments</span><span class="o">,</span> <span class="m">0</span><span class="o">),</span>
<span class="nx">mods</span> <span class="o">=</span> <span class="nx">YUI</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">mods</span><span class="o">,</span>
<span class="nx">used</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_used</span><span class="o">,</span>
<span class="nx">loader</span><span class="o">,</span>
<span class="nx">firstArg</span> <span class="o">=</span> <span class="nx">a</span><span class="o">[</span><span class="m">0</span><span class="o">],</span>
<span class="nx">dynamic</span> <span class="o">=</span> <span class="kc">false</span><span class="o">,</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="nx">a</span><span class="o">[</span><span class="nx">a</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">];</span>
<span class="c">// Y.log(Y.id + &#39;: use called: &#39; + a + &#39; :: &#39; + callback);</span>
<span class="c"></span>
<span class="c">// The last argument supplied to use can be a load complete callback</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">callback</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">a</span><span class="o">.</span><span class="nx">pop</span><span class="o">();</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_callback</span> <span class="o">=</span> <span class="nx">callback</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">}</span>
<span class="c">// YUI().use(&#39;*&#39;); // bind everything available</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">firstArg</span> <span class="o">===</span> <span class="s2">&quot;*&quot;</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">a</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">k</span> <span class="k">in</span> <span class="nx">mods</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">mods</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">k</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">a</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">k</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="c">// if (callback) {</span>
<span class="c"></span> <span class="c">// a.push(callback);</span>
<span class="c"></span> <span class="c">// }</span>
<span class="c"></span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">use</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">Y</span><span class="o">,</span> <span class="nx">a</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">// Y.log(&#39;loader before: &#39; + a.join(&#39;,&#39;));</span>
<span class="c"></span>
<span class="c">// use loader to optimize and sort the requirements if it</span>
<span class="c"></span> <span class="c">// is available.</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Loader</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">dynamic</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="nx">loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Loader</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">loader</span><span class="o">.</span><span class="nx">require</span><span class="o">(</span><span class="nx">a</span><span class="o">);</span>
<span class="nx">loader</span><span class="o">.</span><span class="nx">ignoreRegistered</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="nx">loader</span><span class="o">.</span><span class="nx">calculate</span><span class="o">();</span>
<span class="nx">a</span> <span class="o">=</span> <span class="nx">loader</span><span class="o">.</span><span class="nx">sorted</span><span class="o">;</span>
<span class="o">}</span>
<span class="c">// Y.log(&#39;loader after: &#39; + a.join(&#39;,&#39;));</span>
<span class="c"></span>
<span class="k">var</span> <span class="nx">missing</span> <span class="o">=</span> <span class="o">[],</span> <span class="nx">r</span> <span class="o">=</span> <span class="o">[],</span> <span class="nx">f</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// only attach a module once</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">used</span><span class="o">[</span><span class="nx">name</span><span class="o">])</span> <span class="o">{</span>
<span class="c">// Y.log(name + &#39; already used&#39;);</span>
<span class="c"></span> <span class="k">return</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">m</span> <span class="o">=</span> <span class="nx">mods</span><span class="o">[</span><span class="nx">name</span><span class="o">],</span> <span class="nx">j</span><span class="o">,</span> <span class="nx">req</span><span class="o">,</span> <span class="nx">use</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">m</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">used</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="c">// if (dynamic) {</span>
<span class="c"></span> <span class="c">// Y.mix(l, YUI.Env.mods);</span>
<span class="c"></span> <span class="c">// Y.log(&#39;attaching &#39; + name, &#39;info&#39;, &#39;YUI&#39;);</span>
<span class="c"></span> <span class="c">// m.fn(Y);</span>
<span class="c"></span> <span class="c">// }</span>
<span class="c"></span>
<span class="c">// Y.log(&#39;found &#39; + name);</span>
<span class="c"></span> <span class="nx">req</span> <span class="o">=</span> <span class="nx">m</span><span class="o">.</span><span class="nx">details</span><span class="o">.</span><span class="nx">requires</span><span class="o">;</span>
<span class="nx">use</span> <span class="o">=</span> <span class="nx">m</span><span class="o">.</span><span class="nx">details</span><span class="o">.</span><span class="nx">use</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;module not found: &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">&#39;info&#39;</span><span class="o">,</span> <span class="s1">&#39;YUI&#39;</span><span class="o">);</span>
<span class="nx">missing</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="o">}</span>
<span class="c">// make sure requirements are attached</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">req</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Lang</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">req</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">f</span><span class="o">(</span><span class="nx">req</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">j</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">j</span> <span class="o">&lt;</span> <span class="nx">req</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">j</span> <span class="o">=</span> <span class="nx">j</span> <span class="o">+</span> <span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">f</span><span class="o">(</span><span class="nx">req</span><span class="o">[</span><span class="nx">j</span><span class="o">]);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="c">// add this module to full list of things to attach</span>
<span class="c"></span> <span class="c">// Y.log(&#39;using &#39; + name);</span>
<span class="c"></span> <span class="nx">r</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="c">// auto-attach sub-modules</span>
<span class="c"></span> <span class="c">/*</span>
<span class="c"> if (use) {</span>
<span class="c"> if (Y.Lang.isString(use)) {</span>
<span class="c"> f(use);</span>
<span class="c"> } else {</span>
<span class="c"> for (j = 0; j &lt; use.length; j = j + 1) {</span>
<span class="c"> f(use[j]);</span>
<span class="c"> }</span>
<span class="c"> }</span>
<span class="c"> }</span>
<span class="c"> */</span>
<span class="o">};</span>
<span class="c">// process each requirement and any additional requirements </span>
<span class="c"></span> <span class="c">// the module metadata specifies</span>
<span class="c"></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">l</span><span class="o">=</span><span class="nx">a</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</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">f</span><span class="o">(</span><span class="nx">a</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="nx">log</span><span class="o">(</span><span class="s1">&#39;all reqs: &#39;</span> <span class="o">+</span> <span class="nx">r</span> <span class="o">+</span> <span class="s1">&#39; --- missing: &#39;</span> <span class="o">+</span> <span class="nx">missing</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">onComplete</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">fromLoader</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="s1">&#39;Use complete&#39;</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_callback</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">cb</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_callback</span><span class="o">;</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_callback</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="nx">cb</span><span class="o">(</span><span class="nx">Y</span><span class="o">,</span> <span class="nx">fromLoader</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">fire</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="s1">&#39;yui:load&#39;</span><span class="o">,</span> <span class="nx">Y</span><span class="o">,</span> <span class="nx">fromLoader</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Loader</span> <span class="o">&amp;&amp;</span> <span class="nx">missing</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// dynamic load</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">&#39;trying to get the missing modules &#39;</span> <span class="o">+</span> <span class="nx">missing</span><span class="o">);</span>
<span class="nx">loader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Loader</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="c">// loader.subscribe(&#39;success&#39;, onComplete, Y);</span>
<span class="c"></span> <span class="c">// loader.subscribe(&#39;failure&#39;, onComplete, Y);</span>
<span class="c"></span> <span class="c">// loader.subscribe(&#39;timeout&#39;, onComplete, Y);</span>
<span class="c"></span> <span class="nx">loader</span><span class="o">.</span><span class="nx">onSuccess</span> <span class="o">=</span> <span class="nx">onComplete</span><span class="o">;</span>
<span class="nx">loader</span><span class="o">.</span><span class="nx">onFailure</span> <span class="o">=</span> <span class="nx">onComplete</span><span class="o">;</span>
<span class="nx">loader</span><span class="o">.</span><span class="nx">onTimeout</span> <span class="o">=</span> <span class="nx">onComplete</span><span class="o">;</span>
<span class="nx">loader</span><span class="o">.</span><span class="nx">attaching</span> <span class="o">=</span> <span class="nx">a</span><span class="o">;</span>
<span class="nx">loader</span><span class="o">.</span><span class="nx">require</span><span class="o">(</span><span class="nx">missing</span><span class="o">);</span>
<span class="c">// loader calls use to automatically attach when finished</span>
<span class="c"></span> <span class="c">// but we still need to execute the callback.</span>
<span class="c"></span> <span class="nx">loader</span><span class="o">.</span><span class="nx">insert</span><span class="o">();</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="c">// if (!dynamic) {</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">_attach</span><span class="o">(</span><span class="nx">r</span><span class="o">);</span>
<span class="c">// }</span>
<span class="c"></span> <span class="nx">onComplete</span><span class="o">();</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">;</span> <span class="c">// chain support var yui = YUI().use(&#39;dragdrop&#39;);</span>
<span class="c"></span> <span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the namespace specified and creates it if it doesn&#39;t exist</span>
<span class="c"> * &lt;pre&gt;</span>
<span class="c"> * YUI.namespace(&quot;property.package&quot;);</span>
<span class="c"> * YUI.namespace(&quot;YUI.property.package&quot;);</span>
<span class="c"> * &lt;/pre&gt;</span>
<span class="c"> * Either of the above would create YUI.property, then</span>
<span class="c"> * YUI.property.package</span>
<span class="c"> *</span>
<span class="c"> * Be careful when naming packages. Reserved words may work in some browsers</span>
<span class="c"> * and not others. For instance, the following will fail in Safari:</span>
<span class="c"> * &lt;pre&gt;</span>
<span class="c"> * YUI.namespace(&quot;really.long.nested.namespace&quot;);</span>
<span class="c"> * &lt;/pre&gt;</span>
<span class="c"> * This fails because &quot;long&quot; is a future reserved word in ECMAScript</span>
<span class="c"> *</span>
<span class="c"> * @method namespace</span>
<span class="c"> * @param {string*} arguments 1-n namespaces to create </span>
<span class="c"> * @return {object} A reference to the last namespace object created</span>
<span class="c"> */</span>
<span class="nx">namespace</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">a</span><span class="o">=</span><span class="nx">arguments</span><span class="o">,</span> <span class="nx">o</span><span class="o">=</span><span class="kc">null</span><span class="o">,</span> <span class="nx">i</span><span class="o">,</span> <span class="nx">j</span><span class="o">,</span> <span class="nx">d</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</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">&lt;</span><span class="nx">a</span><span class="o">.</span><span class="nx">length</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">d</span> <span class="o">=</span> <span class="nx">a</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">split</span><span class="o">(</span><span class="s2">&quot;.&quot;</span><span class="o">);</span>
<span class="nx">o</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="nx">j</span><span class="o">=(</span><span class="nx">d</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">==</span> <span class="s2">&quot;YUI&quot;</span><span class="o">)</span> <span class="o">?</span> <span class="m">1</span> <span class="o">:</span> <span class="m">0</span><span class="o">;</span> <span class="nx">j</span><span class="o">&lt;</span><span class="nx">d</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">j</span><span class="o">=</span><span class="nx">j</span><span class="o">+</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">o</span><span class="o">[</span><span class="nx">d</span><span class="o">[</span><span class="nx">j</span><span class="o">]]</span> <span class="o">=</span> <span class="nx">o</span><span class="o">[</span><span class="nx">d</span><span class="o">[</span><span class="nx">j</span><span class="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">d</span><span class="o">[</span><span class="nx">j</span><span class="o">]];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">o</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">// this is replaced if the log module is included</span>
<span class="c"></span> <span class="nx">log</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Report an error. The reporting mechanism is controled by</span>
<span class="c"> * the &#39;throwFail&#39; configuration attribute. If throwFail is</span>
<span class="c"> * not specified, the message is written to the logger, otherwise</span>
<span class="c"> * a JS error is thrown</span>
<span class="c"> * @method fail</span>
<span class="c"> * @param msg {string} the failure message</span>
<span class="c"> * @param e {Error} Optional JS error that was caught. If supplied</span>
<span class="c"> * and throwFail is specified, this error will be re-thrown.</span>
<span class="c"> * @return {YUI} this YUI instance</span>
<span class="c"> */</span>
<span class="nx">fail</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">msg</span><span class="o">,</span> <span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">instance</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="nx">instance</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="nx">msg</span><span class="o">,</span> <span class="s2">&quot;error&quot;</span><span class="o">);</span> <span class="c">// don&#39;t scrub this one</span>
<span class="c"></span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">config</span><span class="o">.</span><span class="nx">throwFail</span><span class="o">)</span> <span class="o">{</span>
<span class="k">throw</span> <span class="nx">e</span> <span class="o">||</span> <span class="k">new</span> <span class="nb">Error</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="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Generate an id that is unique among all YUI instances</span>
<span class="c"> * @method guid</span>
<span class="c"> * @param pre {string} optional guid prefix</span>
<span class="c"> * @return {string} the guid</span>
<span class="c"> */</span>
<span class="nx">guid</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">pre</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">e</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">Env</span><span class="o">,</span> <span class="nx">p</span> <span class="o">=</span> <span class="o">(</span><span class="nx">pre</span><span class="o">)</span> <span class="o">||</span> <span class="nx">e</span><span class="o">.</span><span class="nx">_pre</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">p</span> <span class="o">+</span><span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="nx">e</span><span class="o">.</span><span class="nx">_yidx</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="nx">e</span><span class="o">.</span><span class="nx">_uidx</span><span class="o">++;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Stamps an object with a guid. If the object already</span>
<span class="c"> * has one, a new one is not created</span>
<span class="c"> * @method stamp</span>
<span class="c"> * @param o The object to stamp</span>
<span class="c"> * @return {string} The object&#39;s guid</span>
<span class="c"> */</span>
<span class="nx">stamp</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">if</span> <span class="o">(!</span><span class="nx">o</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">o</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">uid</span> <span class="o">=</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">o</span> <span class="o">===</span> <span class="s1">&#39;string&#39;</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">_yuid</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">uid</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">uid</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">guid</span><span class="o">();</span>
<span class="nx">o</span><span class="o">.</span><span class="nx">_yuid</span> <span class="o">=</span> <span class="nx">uid</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">uid</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="c">// Give the YUI global the same properties as an instance.</span>
<span class="c">// This makes it so that the YUI global can be used like the YAHOO</span>
<span class="c">// global was used prior to 3.x. More importantly, the YUI global</span>
<span class="c">// provides global metadata, so env needs to be configured.</span>
<span class="c">// @TODO review</span>
<span class="c"></span>
<span class="k">var</span> <span class="nx">Y</span> <span class="o">=</span> <span class="nx">YUI</span><span class="o">,</span> <span class="nx">p</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">prototype</span><span class="o">,</span> <span class="nx">i</span><span class="o">;</span>
<span class="c">// inheritance utilities are not available yet</span>
<span class="c"></span> <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="k">in</span> <span class="nx">p</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="kc">true</span><span class="o">)</span> <span class="o">{</span> <span class="c">// hasOwnProperty not available yet and not needed</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="nx">p</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="c">// set up the environment</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">_init</span><span class="o">();</span>
<span class="o">})();</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_anim.html">anim</a></li>
<li class=""><a href="module_anim-color.html">anim-color</a></li>
<li class=""><a href="module_anim-curve.html">anim-curve</a></li>
<li class=""><a href="module_anim-easing.html">anim-easing</a></li>
<li class=""><a href="module_anim-scroll.html">anim-scroll</a></li>
<li class=""><a href="module_anim-xy.html">anim-xy</a></li>
<li class=""><a href="module_attribute.html">attribute</a></li>
<li class=""><a href="module_base.html">base</a></li>
<li class=""><a href="module_dd-plugin.html">dd-plugin</a></li>
<li class=""><a href="module_event.html">event</a></li>
<li class=""><a href="module_get.html">get</a></li>
<li class=""><a href="module_io.html">io</a></li>
<li class=""><a href="module_loader.html">loader</a></li>
<li class=""><a href="module_node.html">node</a></li>
<li class=""><a href="module_node-class.html">node-class</a></li>
<li class=""><a href="module_node-region.html">node-region</a></li>
<li class=""><a href="module_node-screen.html">node-screen</a></li>
<li class=""><a href="module_Queue.html">Queue</a></li>
<li class="selected"><a href="module_yui.html">yui</a></li>
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
<li class=""><a href="Array.html">Array</a></li>
<li class=""><a href="Lang.html">Lang</a></li>
<li class=""><a href="Object.html">Object</a></li>
<li class=""><a href="UA.html">UA</a></li>
<li class=""><a href="YUI.html">YUI</a></li>
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="yui-array.js.html">yui-array.js</a></li>
<li class=""><a href="yui-core.js.html">yui-core.js</a></li>
<li class=""><a href="yui-dump.js.html">yui-dump.js</a></li>
<li class=""><a href="yui-init.js.html">yui-init.js</a></li>
<li class=""><a href="yui-lang.js.html">yui-lang.js</a></li>
<li class=""><a href="yui-later.js.html">yui-later.js</a></li>
<li class=""><a href="yui-log.js.html">yui-log.js</a></li>
<li class=""><a href="yui-object.js.html">yui-object.js</a></li>
<li class=""><a href="yui-ua.js.html">yui-ua.js</a></li>
<li class="selected"><a href="yui.js.html">yui.js</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>