yui-core.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-core.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="c">// requires lang</span>
<span class="c"></span><span class="nx">YUI</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="s2">"core"</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">Y</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">L</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Lang</span><span class="o">,</span>
<span class="nx">A</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nb">Array</span><span class="o">,</span>
<span class="nx">OP</span> <span class="o">=</span> <span class="nb">Object</span><span class="o">.</span><span class="nx">prototype</span><span class="o">,</span>
<span class="nx">IEF</span> <span class="o">=</span> <span class="o">[</span><span class="s2">"toString"</span><span class="o">,</span> <span class="s2">"valueOf"</span><span class="o">],</span>
<span class="nx">PROTO</span> <span class="o">=</span> <span class="s1">'prototype'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * IE will not enumerate native functions in a derived object even if the</span>
<span class="c"> * function was overridden. This is a workaround for specific functions </span>
<span class="c"> * we care about on the Object prototype. </span>
<span class="c"> * @property _iefix</span>
<span class="c"> * @param {Function} r the object to receive the augmentation</span>
<span class="c"> * @param {Function} s the object that supplies the properties to augment</span>
<span class="c"> * @param w a whitelist object (the keys are the valid items to reference)</span>
<span class="c"> * @private</span>
<span class="c"> * @for YUI</span>
<span class="c"> */</span>
<span class="nx">_iefix</span> <span class="o">=</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">UA</span> <span class="o">&&</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">UA</span><span class="o">.</span><span class="nx">ie</span><span class="o">)</span> <span class="o">?</span>
<span class="k">function</span><span class="o">(</span><span class="nx">r</span><span class="o">,</span> <span class="nx">s</span><span class="o">,</span> <span class="nx">w</span><span class="o">)</span> <span class="o">{</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span> <span class="nx">a</span><span class="o">=</span><span class="nx">IEF</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="k">var</span> <span class="nx">n</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">f</span> <span class="o">=</span> <span class="nx">s</span><span class="o">[</span><span class="nx">n</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">L</span><span class="o">.</span><span class="nx">isFunction</span><span class="o">(</span><span class="nx">f</span><span class="o">)</span> <span class="o">&&</span> <span class="nx">f</span> <span class="o">!=</span> <span class="nx">OP</span><span class="o">[</span><span class="nx">n</span><span class="o">])</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">w</span> <span class="o">||</span> <span class="o">(</span><span class="nx">n</span> <span class="k">in</span> <span class="nx">w</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">r</span><span class="o">[</span><span class="nx">n</span><span class="o">]=</span><span class="nx">f</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span> <span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{};</span>
<span class="c">/**</span>
<span class="c"> * Returns a new object containing all of the properties of</span>
<span class="c"> * all the supplied objects. The properties from later objects</span>
<span class="c"> * will overwrite those in earlier objects. Passing in a</span>
<span class="c"> * single object will create a shallow copy of it. For a deep</span>
<span class="c"> * copy, use clone.</span>
<span class="c"> * @method merge</span>
<span class="c"> * @param arguments {Object*} the objects to merge</span>
<span class="c"> * @return {object} the new merged object</span>
<span class="c"> */</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">merge</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="c">// var o={}, a=arguments;</span>
<span class="c"></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="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">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">o</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="kc">true</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">/**</span>
<span class="c"> * Applies the supplier's properties to the receiver. By default</span>
<span class="c"> * all prototype and static propertes on the supplier are applied</span>
<span class="c"> * to the corresponding spot on the receiver. By default all</span>
<span class="c"> * properties are applied, and a property that is already on the</span>
<span class="c"> * reciever will not be overwritten. The default behavior can</span>
<span class="c"> * be modified by supplying the appropriate parameters.</span>
<span class="c"> *</span>
<span class="c"> * @TODO add constants for the modes</span>
<span class="c"> *</span>
<span class="c"> * @method mix</span>
<span class="c"> * @param {Function} r the object to receive the augmentation</span>
<span class="c"> * @param {Function} s the object that supplies the properties to augment</span>
<span class="c"> * @param ov {boolean} if true, properties already on the receiver</span>
<span class="c"> * will be overwritten if found on the supplier.</span>
<span class="c"> * @param wl {string[]} a whitelist. If supplied, only properties in </span>
<span class="c"> * this list will be applied to the receiver.</span>
<span class="c"> * @param {int} mode what should be copies, and to where</span>
<span class="c"> * default(0): object to object</span>
<span class="c"> * 1: prototype to prototype (old augment)</span>
<span class="c"> * 2: prototype to prototype and object props (new augment)</span>
<span class="c"> * 3: prototype to object</span>
<span class="c"> * 4: object to prototype</span>
<span class="c"> * @return {object} the augmented object</span>
<span class="c"> * @TODO review for PR2</span>
<span class="c"> */</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</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">s</span><span class="o">,</span> <span class="nx">ov</span><span class="o">,</span> <span class="nx">wl</span><span class="o">,</span> <span class="nx">mode</span><span class="o">,</span> <span class="nx">merge</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">s</span><span class="o">||!</span><span class="nx">r</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="o">}</span>
<span class="k">var</span> <span class="nx">w</span> <span class="o">=</span> <span class="o">(</span><span class="nx">wl</span> <span class="o">&&</span> <span class="nx">wl</span><span class="o">.</span><span class="nx">length</span><span class="o">)</span> <span class="o">?</span> <span class="nx">A</span><span class="o">.</span><span class="nx">hash</span><span class="o">(</span><span class="nx">wl</span><span class="o">)</span> <span class="o">:</span> <span class="kc">null</span><span class="o">,</span> <span class="nx">m</span> <span class="o">=</span> <span class="nx">merge</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">fr</span><span class="o">,</span> <span class="nx">fs</span><span class="o">,</span> <span class="nx">proto</span><span class="o">,</span> <span class="nx">iwl</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">arr</span> <span class="o">=</span> <span class="nx">m</span> <span class="o">&&</span> <span class="nx">L</span><span class="o">.</span><span class="nx">isArray</span><span class="o">(</span><span class="nx">fr</span><span class="o">);</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">fs</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// We never want to overwrite the prototype</span>
<span class="c"></span> <span class="c">// if (PROTO === i) {</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">PROTO</span> <span class="o">===</span> <span class="nx">i</span> <span class="o">||</span> <span class="s1">'_yuid'</span> <span class="o">===</span> <span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="k">continue</span><span class="o">;</span>
<span class="o">}</span>
<span class="c"></span> <span class="c">// @TODO deal with the hasownprop issue</span>
<span class="c"></span>
<span class="c">// check white list if it was supplied</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(!</span><span class="nx">w</span> <span class="o">||</span> <span class="nx">iwl</span> <span class="o">||</span> <span class="o">(</span><span class="nx">i</span> <span class="k">in</span> <span class="nx">w</span><span class="o">))</span> <span class="o">{</span>
<span class="c">// if the receiver has this property, it is an object,</span>
<span class="c"></span> <span class="c">// and merge is specified, merge the two objects.</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">m</span> <span class="o">&&</span> <span class="nx">L</span><span class="o">.</span><span class="nx">isObject</span><span class="o">(</span><span class="nx">fr</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> <span class="kc">true</span><span class="o">))</span> <span class="o">{</span>
<span class="c"></span> <span class="c">// @TODO recursive or no?</span>
<span class="c"></span> <span class="nx">f</span><span class="o">(</span><span class="nx">fr</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> <span class="nx">fs</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> <span class="nx">proto</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span> <span class="c">// recursive</span>
<span class="c"></span> <span class="c">// otherwise apply the property only if overwrite</span>
<span class="c"></span> <span class="c">// is specified or the receiver doesn't have one.</span>
<span class="c"></span> <span class="c">// @TODO make sure the 'arr' check isn't desructive</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(!</span><span class="nx">arr</span> <span class="o">&&</span> <span class="o">(</span><span class="nx">ov</span> <span class="o">||</span> <span class="o">!(</span><span class="nx">i</span> <span class="k">in</span> <span class="nx">fr</span><span class="o">)))</span> <span class="o">{</span>
<span class="c"></span> <span class="nx">fr</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="nx">fs</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="c">// if merge is specified and the receiver is an array,</span>
<span class="c"></span> <span class="c">// append the array item</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">arr</span><span class="o">)</span> <span class="o">{</span>
<span class="c"></span> <span class="c">// @TODO probably will need to remove dups</span>
<span class="c"></span> <span class="nx">fr</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">fs</span><span class="o">[</span><span class="nx">i</span><span class="o">]);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="nx">_iefix</span><span class="o">(</span><span class="nx">fr</span><span class="o">,</span> <span class="nx">fs</span><span class="o">,</span> <span class="nx">w</span><span class="o">);</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">rp</span> <span class="o">=</span> <span class="nx">r</span><span class="o">.</span><span class="nx">prototype</span><span class="o">,</span> <span class="nx">sp</span> <span class="o">=</span> <span class="nx">s</span><span class="o">.</span><span class="nx">prototype</span><span class="o">;</span>
<span class="nx">switch</span> <span class="o">(</span><span class="nx">mode</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">case</span> <span class="m">1</span><span class="o">:</span> <span class="c">// proto to proto</span>
<span class="c"></span> <span class="nx">f</span><span class="o">(</span><span class="nx">rp</span><span class="o">,</span> <span class="nx">sp</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="nx">case</span> <span class="m">2</span><span class="o">:</span> <span class="c">// object to object and proto to proto</span>
<span class="c"></span> <span class="nx">f</span><span class="o">(</span><span class="nx">r</span><span class="o">,</span> <span class="nx">s</span><span class="o">);</span>
<span class="nx">f</span><span class="o">(</span><span class="nx">rp</span><span class="o">,</span> <span class="nx">sp</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="nx">case</span> <span class="m">3</span><span class="o">:</span> <span class="c">// proto to static</span>
<span class="c"></span> <span class="nx">f</span><span class="o">(</span><span class="nx">r</span><span class="o">,</span> <span class="nx">sp</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="nx">case</span> <span class="m">4</span><span class="o">:</span> <span class="c">// static to proto</span>
<span class="c"></span> <span class="nx">f</span><span class="o">(</span><span class="nx">rp</span><span class="o">,</span> <span class="nx">s</span><span class="o">);</span>
<span class="k">break</span><span class="o">;</span>
<span class="nx">default</span><span class="o">:</span> <span class="c">// object to object</span>
<span class="c"></span> <span class="nx">f</span><span class="o">(</span><span class="nx">r</span><span class="o">,</span> <span class="nx">s</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">r</span><span class="o">;</span>
<span class="o">};</span>
<span class="o">},</span> <span class="s2">"@VERSION@"</span><span class="o">);</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>