yui.js.html revision eb9b6f817df5c660be9f00fc5d27fe33479fdc98
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>yui <span class="subtitle">3.00PR1</span></h3>
<p>
> 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">'io.xdrReady'</span><span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="s1">'io.start'</span><span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="s1">'io.success'</span><span class="o">:</span> <span class="m">1</span><span class="o">,</span>
<span class="s1">'io.failure'</span><span class="o">:</span> <span class="m">1</span><span class="o">,</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">'undefined'</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"> * @param o Optional configuration object. Options:</span>
<span class="c"> * <ul></span>
<span class="c"> * <li>------------------------------------------------------------------------</li></span>
<span class="c"> * <li>Global:</li></span>
<span class="c"> * <li>------------------------------------------------------------------------</li></span>
<span class="c"> * <li>debug:</span>
<span class="c"> * Turn debug statements on or off</li></span>
<span class="c"> * <li>useConsole:</span>
<span class="c"> * Log to the browser console if debug is on and the console is available</li></span>
<span class="c"> * <li>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.</li></span>
<span class="c"> * <li>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.</li></span>
<span class="c"> * <li>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"> * <li>win:</span>
<span class="c"> * <li>core:</span>
<span class="c"> * A list of modules that defines the YUI core (overrides the default)</li></span>
<span class="c"> * <li>------------------------------------------------------------------------</li></span>
<span class="c"> * <li>For event and get:</li></span>
<span class="c"> * <li>------------------------------------------------------------------------</li></span>
<span class="c"> * <li>pollInterval:</span>
<span class="c"> * The default poll interval</li></span>
<span class="c"> * <li>-------------------------------------------------------------------------</li></span>
<span class="c"> * <li>For loader:</li></span>
<span class="c"> * <li>-------------------------------------------------------------------------</li></span>
<span class="c"> * <li>base:</span>
<span class="c"> * The base dir</li></span>
<span class="c"> * <li>secureBase:</span>
<span class="c"> * The secure base dir (not implemented)</li></span>
<span class="c"> * <li>comboBase:</span>
<span class="c"> * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li></span>
<span class="c"> * <li>root:</span>
<span class="c"> * The root path to prepend to module names for the combo service. Ex: 2.5.2/build/</li></span>
<span class="c"> * <li>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"> * can be a predefined filter or a custom filter. The valid predefined </span>
<span class="c"> * filters are:</span>
<span class="c"> * <dl></span>
<span class="c"> * <dt>DEBUG</dt></span>
<span class="c"> * <dd>Selects the debug versions of the library (e.g., event-debug.js).</span>
<span class="c"> * This option will automatically include the logger widget</dd></span>
<span class="c"> * <dt>RAW</dt></span>
<span class="c"> * <dd>Selects the non-minified version of the library (e.g., event.js).</dd></span>
<span class="c"> * </dl></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"> * <pre></span>
<span class="c"> * myFilter: &#123; </span>
<span class="c"> * 'searchExp': "-min\\.js", </span>
<span class="c"> * &#125;</span>
<span class="c"> * </pre></span>
<span class="c"> *</span>
<span class="c"> * </li></span>
<span class="c"> * <li>combine:</span>
<span class="c"> * Use the YUI combo service to reduce the number of http connections required to load your dependencies</li></span>
<span class="c"> * <li>ignore:</span>
<span class="c"> * A list of modules that should never be dynamically loaded</li></span>
<span class="c"> * <li>force:</span>
<span class="c"> * A list of modules that should always be loaded when required, even if already present on the page</li></span>
<span class="c"> * <li>insertBefore:</span>
<span class="c"> * Node or id for a node that should be used as the insertion point for new nodes</li></span>
<span class="c"> * <li>charset:</span>
<span class="c"> * charset for dynamic nodes</li></span>
<span class="c"> * <li>timeout:</span>
<span class="c"> * number of milliseconds before a timeout occurs when dynamically loading nodes. in not set, there is no timeout</li></span>
<span class="c"> * <li>context:</span>
<span class="c"> * execution context for all callbacks</li></span>
<span class="c"> * <li>onSuccess:</span>
<span class="c"> * callback for the 'success' event</li></span>
<span class="c"> * <li>onFailure:</span>
<span class="c"> * callback for the 'failure' event</li></span>
<span class="c"> * <li>onTimeout:</span>
<span class="c"> * callback for the 'timeout' event</li></span>
<span class="c"> * <li>onProgress:</span>
<span class="c"> * callback executed each time a script or css file is loaded</li></span>
<span class="c"> * <li>modules:</span>
<span class="c"> * A list of module definitions. See Loader.addModule for the supported module metadata</li></span>
<span class="c"> * </ul></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">'debug'</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">'useConsole'</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">'yuid'</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">') init '</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">"yui"</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"> * @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">': applyTo not allowed'</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">'.'</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"><</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">'applyTo not found: '</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"></span>
<span class="c">// @todo expand this to include version mapping</span>
<span class="c"></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"><</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">&&</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">'attaching '</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'YUI'</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"> * we add syntax for specifying these?</span>
<span class="c"> *</span>
<span class="c"> * YUI().use('dragdrop')</span>
<span class="c"> * YUI().use('dragdrop:2.4.0'); // specific version</span>
<span class="c"> * YUI().use('dragdrop:2.4.0-'); // at least this version</span>
<span class="c"> * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range</span>
<span class="c"> * YUI().use('*'); // use all available modules</span>
<span class="c"> * YUI().use('lang+dump+substitute'); // use lang and some plugins</span>
<span class="c"> * YUI().use('lang+*'); // 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"></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">'function'</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('*'); // 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">"*"</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">// }</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"></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"></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"></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.log('attaching ' + name, 'info', 'YUI');</span>
<span class="c"></span> <span class="c">// }</span>
<span class="c"></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">'module not found: '</span> <span class="o">+</span> <span class="nx">name</span><span class="o">,</span> <span class="s1">'info'</span><span class="o">,</span> <span class="s1">'YUI'</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"><</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="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"> f(use);</span>
<span class="c"> } else {</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"><</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">'all reqs: '</span> <span class="o">+</span> <span class="nx">r</span> <span class="o">+</span> <span class="s1">' --- missing: '</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">'Use complete'</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">'yui:load'</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">&&</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">'trying to get the missing modules '</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"></span> <span class="c">// loader.subscribe('failure', onComplete, Y);</span>
<span class="c"></span> <span class="c">// loader.subscribe('timeout', 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('dragdrop');</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't exist</span>
<span class="c"> * <pre></span>
<span class="c"> * </pre></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"> * <pre></span>
<span class="c"> * </pre></span>
<span class="c"> * This fails because "long" 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"><</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">"."</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">"YUI"</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"><</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 'throwFail' 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">"error"</span><span class="o">);</span> <span class="c">// don'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">'-'</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">'-'</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'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">'string'</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">// 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">
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>