anim-color.js.html revision 4fcbec6145d16637205990699912fb90f6a3807c
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>anim <span class="subtitle">3.00PR1</span></h3>
<p>
> anim-color.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> <label for="showprivate">Show Private</label></span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre><span class="c">/**</span>
<span class="c"> * Adds color behaviors to Anim.</span>
<span class="c"> * @module anim</span>
<span class="c"> * @submodule anim-color</span>
<span class="c"> * @for Anim</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">NUM</span> <span class="o">=</span> <span class="nb">Number</span><span class="o">;</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Anim</span><span class="o">.</span><span class="nx">behaviors</span><span class="o">.</span><span class="nx">color</span> <span class="o">=</span> <span class="o">{</span>
<span class="nx">set</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">anim</span><span class="o">,</span> <span class="nx">att</span><span class="o">,</span> <span class="nx">from</span><span class="o">,</span> <span class="nx">to</span><span class="o">,</span> <span class="nx">elapsed</span><span class="o">,</span> <span class="nx">duration</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">from</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Color</span><span class="o">.</span><span class="nx">re_RGB</span><span class="o">.</span><span class="nx">exec</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Color</span><span class="o">.</span><span class="nx">toRGB</span><span class="o">(</span><span class="nx">from</span><span class="o">));</span>
<span class="nx">to</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Color</span><span class="o">.</span><span class="nx">re_RGB</span><span class="o">.</span><span class="nx">exec</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Color</span><span class="o">.</span><span class="nx">toRGB</span><span class="o">(</span><span class="nx">to</span><span class="o">));</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">from</span> <span class="o">||</span> <span class="o">!</span><span class="nx">to</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">fail</span><span class="o">(</span><span class="s1">'invalid from or to passed to color behavior'</span><span class="o">);</span>
<span class="o">}</span>
<span class="nx">anim</span><span class="o">.</span><span class="nx">_node</span><span class="o">.</span><span class="nx">setStyle</span><span class="o">(</span><span class="nx">att</span><span class="o">,</span> <span class="s1">'rgb('</span> <span class="o">+</span> <span class="o">[</span>
<span class="nb">Math</span><span class="o">.</span><span class="nx">floor</span><span class="o">(</span><span class="nx">fn</span><span class="o">(</span><span class="nx">elapsed</span><span class="o">,</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">from</span><span class="o">[</span><span class="m">1</span><span class="o">]),</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">to</span><span class="o">[</span><span class="m">1</span><span class="o">])</span> <span class="o">-</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">from</span><span class="o">[</span><span class="m">1</span><span class="o">]),</span> <span class="nx">duration</span><span class="o">)),</span>
<span class="nb">Math</span><span class="o">.</span><span class="nx">floor</span><span class="o">(</span><span class="nx">fn</span><span class="o">(</span><span class="nx">elapsed</span><span class="o">,</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">from</span><span class="o">[</span><span class="m">2</span><span class="o">]),</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">to</span><span class="o">[</span><span class="m">2</span><span class="o">])</span> <span class="o">-</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">from</span><span class="o">[</span><span class="m">2</span><span class="o">]),</span> <span class="nx">duration</span><span class="o">)),</span>
<span class="nb">Math</span><span class="o">.</span><span class="nx">floor</span><span class="o">(</span><span class="nx">fn</span><span class="o">(</span><span class="nx">elapsed</span><span class="o">,</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">from</span><span class="o">[</span><span class="m">3</span><span class="o">]),</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">to</span><span class="o">[</span><span class="m">3</span><span class="o">])</span> <span class="o">-</span> <span class="nx">NUM</span><span class="o">(</span><span class="nx">from</span><span class="o">[</span><span class="m">3</span><span class="o">]),</span> <span class="nx">duration</span><span class="o">))</span>
<span class="o">].</span><span class="nx">join</span><span class="o">(</span><span class="s1">', '</span><span class="o">)</span> <span class="o">+</span> <span class="s1">')'</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">// TODO: default bgcolor const</span>
<span class="c"></span> <span class="nx">get</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">anim</span><span class="o">,</span> <span class="nx">att</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">anim</span><span class="o">.</span><span class="nx">_node</span><span class="o">.</span><span class="nx">getComputedStyle</span><span class="o">(</span><span class="nx">att</span><span class="o">);</span>
<span class="nx">val</span> <span class="o">=</span> <span class="o">(</span><span class="nx">val</span> <span class="o">===</span> <span class="s1">'transparent'</span><span class="o">)</span> <span class="o">?</span> <span class="s1">'rgb(255, 255, 255)'</span> <span class="o">:</span> <span class="nx">val</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">([</span><span class="s1">'backgroundColor'</span><span class="o">,</span>
<span class="s1">'borderTopColor'</span><span class="o">,</span>
<span class="s1">'borderRightColor'</span><span class="o">,</span>
<span class="s1">'borderBottomColor'</span><span class="o">,</span>
<span class="s1">'borderLeftColor'</span><span class="o">],</span>
<span class="k">function</span><span class="o">(</span><span class="nx">v</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">Anim</span><span class="o">.</span><span class="nx">behaviors</span><span class="o">[</span><span class="nx">v</span><span class="o">]</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Anim</span><span class="o">.</span><span class="nx">behaviors</span><span class="o">.</span><span class="nx">color</span><span class="o">;</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>