yui-ua.js.html revision ace5e2555c33a0ceddef42649f6f38fa006707cc
<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-ua.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="nx">YUI</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="s2">"ua"</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="c">/**</span>
<span class="c"> * @class UA</span>
<span class="c"> */</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">UA</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">o</span><span class="o">={</span>
<span class="c">/**</span>
<span class="c"> * Internet Explorer version number or 0. Example: 6</span>
<span class="c"> * @property ie</span>
<span class="c"> * @type float</span>
<span class="c"> */</span>
<span class="nx">ie</span><span class="o">:</span><span class="m">0</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Opera version number or 0. Example: 9.2</span>
<span class="c"> * @property opera</span>
<span class="c"> * @type float</span>
<span class="c"> */</span>
<span class="nx">opera</span><span class="o">:</span><span class="m">0</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Gecko engine revision number. Will evaluate to 1 if Gecko </span>
<span class="c"> * is detected but the revision could not be found. Other browsers</span>
<span class="c"> * will be 0. Example: 1.8</span>
<span class="c"> * <pre></span>
<span class="c"> * Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7</span>
<span class="c"> * Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8</span>
<span class="c"> * Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8</span>
<span class="c"> * Firefox 3 alpha: 1.9a4 <-- Reports 1.9</span>
<span class="c"> * </pre></span>
<span class="c"> * @property gecko</span>
<span class="c"> * @type float</span>
<span class="c"> */</span>
<span class="nx">gecko</span><span class="o">:</span><span class="m">0</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * AppleWebKit version. KHTML browsers that are not WebKit browsers </span>
<span class="c"> * will evaluate to 1, other browsers 0. Example: 418.9.1</span>
<span class="c"> * <pre></span>
<span class="c"> * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the </span>
<span class="c"> * latest available for Mac OSX 10.3.</span>
<span class="c"> * Safari 2.0.2: 416 <-- hasOwnProperty introduced</span>
<span class="c"> * Safari 2.0.4: 418 <-- preventDefault fixed</span>
<span class="c"> * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run</span>
<span class="c"> * different versions of webkit</span>
<span class="c"> * Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been</span>
<span class="c"> * updated, but not updated</span>
<span class="c"> * to the latest patch.</span>
<span class="c"> * Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native SVG</span>
<span class="c"> * and many major issues fixed).</span>
<span class="c"> * Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic update</span>
<span class="c"> * </span>
<span class="c"> * </pre></span>
<span class="c"> * @property webkit</span>
<span class="c"> * @type float</span>
<span class="c"> */</span>
<span class="nx">webkit</span><span class="o">:</span><span class="m">0</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * The mobile property will be set to a string containing any relevant</span>
<span class="c"> * user agent information when a modern mobile browser is detected.</span>
<span class="c"> * devices with the WebKit-based browser, and Opera Mini. </span>
<span class="c"> * @property mobile </span>
<span class="c"> * @type string</span>
<span class="c"> */</span>
<span class="nx">mobile</span><span class="o">:</span> <span class="kc">null</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">ua</span><span class="o">=</span><span class="nx">navigator</span><span class="o">.</span><span class="nx">userAgent</span><span class="o">,</span> <span class="nx">m</span><span class="o">;</span>
<span class="c">// Modern KHTML browsers should qualify as Safari X-Grade</span>
<span class="c"></span> <span class="k">if</span> <span class="o">((</span><span class="sr">/KHTML/</span><span class="o">).</span><span class="nx">test</span><span class="o">(</span><span class="nx">ua</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">o</span><span class="o">.</span><span class="nx">webkit</span><span class="o">=</span><span class="m">1</span><span class="o">;</span>
<span class="o">}</span>
<span class="c">// Modern WebKit browsers are at least X-Grade</span>
<span class="c"></span> <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/AppleWebKit\/([^\s]*)/</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="nx">m</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">webkit</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
<span class="c">// Mobile browser check</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="sr">/ Mobile\//</span><span class="o">.</span><span class="nx">test</span><span class="o">(</span><span class="nx">ua</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">o</span><span class="o">.</span><span class="nx">mobile</span> <span class="o">=</span> <span class="s2">"Apple"</span><span class="o">;</span> <span class="c">// iPhone or iPod Touch</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/NokiaN[^\/]*/</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">o</span><span class="o">.</span><span class="nx">mobile</span> <span class="o">=</span> <span class="nx">m</span><span class="o">[</span><span class="m">0</span><span class="o">];</span> <span class="c">// Nokia N-series, ex: NokiaN95</span>
<span class="c"></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">o</span><span class="o">.</span><span class="nx">webkit</span><span class="o">)</span> <span class="o">{</span> <span class="c">// not webkit</span>
<span class="c"></span> <span class="c">// @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)</span>
<span class="c"></span> <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/Opera[\s\/]([^\s]*)/</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="nx">m</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">opera</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
<span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/Opera Mini[^;]*/</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">o</span><span class="o">.</span><span class="nx">mobile</span> <span class="o">=</span> <span class="nx">m</span><span class="o">[</span><span class="m">0</span><span class="o">];</span> <span class="c">// ex: Opera Mini/2.0.4509/1316</span>
<span class="c"></span> <span class="o">}</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="c">// not opera or webkit</span>
<span class="c"></span> <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/MSIE\s([^;]*)/</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="nx">m</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">ie</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="c">// not opera, webkit, or ie</span>
<span class="c"></span> <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/Gecko\/([^\s]*)/</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">o</span><span class="o">.</span><span class="nx">gecko</span><span class="o">=</span><span class="m">1</span><span class="o">;</span> <span class="c">// Gecko detected, look for revision</span>
<span class="c"></span> <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/rv:([^\s\)]*)/</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="nx">m</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">gecko</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</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">return</span> <span class="nx">o</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>