yui-ua.js.html revision ace5e2555c33a0ceddef42649f6f38fa006707cc
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>API: yui yui-ua.js (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/api.css">
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
<h3>yui&nbsp; <span class="subtitle">3.00PR1</span></h3>
<p>
<a href="/index.html">Yahoo! UI Library</a>
&gt; <a href="/module_yui.html">yui</a>
&gt; yui-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">&quot;ua&quot;</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"> * Browser/platform detection</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"> * &lt;pre&gt;</span>
<span class="c"> * Firefox 1.0.0.4: 1.7.8 &lt;-- Reports 1.7</span>
<span class="c"> * Firefox 1.5.0.9: 1.8.0.9 &lt;-- Reports 1.8</span>
<span class="c"> * Firefox 2.0.0.3: 1.8.1.3 &lt;-- Reports 1.8</span>
<span class="c"> * Firefox 3 alpha: 1.9a4 &lt;-- Reports 1.9</span>
<span class="c"> * &lt;/pre&gt;</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"> * &lt;pre&gt;</span>
<span class="c"> * Safari 1.3.2 (312.6): 312.8.1 &lt;-- 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 &lt;-- hasOwnProperty introduced</span>
<span class="c"> * Safari 2.0.4: 418 &lt;-- preventDefault fixed</span>
<span class="c"> * Safari 2.0.4 (419.3): 418.9.1 &lt;-- 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 &lt;-- 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+ &lt;-- 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 &lt;-- First Tiger release - automatic update</span>
<span class="c"> * from 2.x via the 10.4.11 OS patch</span>
<span class="c"> * </span>
<span class="c"> * &lt;/pre&gt;</span>
<span class="c"> * http://developer.apple.com/internet/safari/uamatrix.html</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"> * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series</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">&amp;&amp;</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">&quot;Apple&quot;</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">&amp;&amp;</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">&amp;&amp;</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">&amp;&amp;</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">&quot;@VERSION@&quot;</span><span class="o">);</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_animation.html">animation</a></li>
<li class=""><a href="module_attribute.html">attribute</a></li>
<li class=""><a href="module_base.html">base</a></li>
<li class=""><a href="module_event.html">event</a></li>
<li class=""><a href="module_io.html">io</a></li>
<li class=""><a href="module_JSON.html">JSON</a></li>
<li class=""><a href="module_node.html">node</a></li>
<li class=""><a href="module_node-region.html">node-region</a></li>
<li class=""><a href="module_nodeclassname.html">nodeclassname</a></li>
<li class=""><a href="module_nodeextras.html">nodeextras</a></li>
<li class="selected"><a href="module_yui.html">yui</a></li>
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
<li class=""><a href="Array.html">Array</a></li>
<li class=""><a href="Get.html">Get</a></li>
<li class=""><a href="Lang.html">Lang</a></li>
<li class=""><a href="Object.html">Object</a></li>
<li class=""><a href="UA.html">UA</a></li>
<li class=""><a href="YUI.html">YUI</a></li>
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="yui-array.js.html">yui-array.js</a></li>
<li class=""><a href="yui-core.js.html">yui-core.js</a></li>
<li class=""><a href="yui-dump.js.html">yui-dump.js</a></li>
<li class=""><a href="yui-get.js.html">yui-get.js</a></li>
<li class=""><a href="yui-init.js.html">yui-init.js</a></li>
<li class=""><a href="yui-lang.js.html">yui-lang.js</a></li>
<li class=""><a href="yui-later.js.html">yui-later.js</a></li>
<li class=""><a href="yui-log.js.html">yui-log.js</a></li>
<li class=""><a href="yui-object.js.html">yui-object.js</a></li>
<li class="selected"><a href="yui-ua.js.html">yui-ua.js</a></li>
<li class=""><a href="yui.js.html">yui.js</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>