1/* 2 * platformSelector: a jQuery plugin 3 * 4 * platformSelector is a simple jQuery plugin that adds classes to the body 5 * element representing the browser's environment. It adds classes for browser 6 * type, browser version, operating system, rendering engine and JS-enabled. 7 * 8 * For full documentation, visit: 9 * http://github.com/alexrabarts/jquery-platformselector 10 * 11 * Licensed under the MIT: 12 * http://www.opensource.org/licenses/mit-license.php 13 * 14 * Copyright (c) 2008 Stateless Systems (http://statelesssystems.com) 15 * 16 * @author Alex Rabarts (alexrabarts -at- gmail -dawt- com) 17 * @requires jQuery v1.2 or later 18 * @version 0.1.1 19 */ 20 21(function ($) { 22 function t(str, test) { return str.indexOf(test) !== -1; } 23 function uaIs(test) { return t(ua, test); } 24 25 var ua = navigator.userAgent.toLowerCase(); 26 27 var ie = (!uaIs('opera') && !uaIs('webtv') && (/msie (\d+)/.test(ua))) ? 'ie ie_' + RegExp.$1 : ''; 28 29 var os = 30 (uaIs('x11') || uaIs('linux')) ? 'linux' : 31 uaIs('mac') ? 'mac' : 32 uaIs('win') ? 'win' : ''; 33 34 var classNames = [ie, os, 'js']; 35 36 var agents = ua.split(' '); 37 38 $.each(agents, function () { 39 if (!this.match(/(\w+)\/([^\s]+)/)) { 40 return; 41 } 42 43 var agent = RegExp.$1; 44 var fullVersion = RegExp.$2.replace(/[\/\.]/g, '_'); 45 var majorVersion = fullVersion.replace(/_.*/, ''); 46 47 classNames = classNames.concat([agent, agent + '_' + fullVersion, agent + '_' + majorVersion]); 48 }); 49 50 // Safari splits the user agent into Safairi/<build> and Version/<version> so rename Version -> Safari 51 if ($.inArray('safari', classNames) !== -1 && $.inArray('version', classNames) !== -1) { 52 classNames = $.map(classNames, function (c) { 53 return c.replace('version', 'safari'); 54 }); 55 } 56 57 // Chrome incorrectly identifies itself as Safari 58 if ($.inArray('chrome', classNames) !== -1) { 59 classNames = $.map(classNames, function (c) { 60 return c.match(/^safari/) ? null : c; 61 }); 62 } 63 64 var engineVersion = ( 65 (ua.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0,'0'])[1] // From jQuery 1.2.6 66 ).replace(/\./g, '_'); 67 68 $.each(['opera', 'applewebkit', 'gecko'], function () { 69 if ($.inArray(String(this), classNames) !== -1) { 70 classNames.push(this + '_' + engineVersion); 71 return false; 72 } 73 }); 74 75 // Deduplicate. $.unique is only for DOM elements :-( 76 var seen = {}; 77 classNames = $.map(classNames, function (c) { 78 if (seen[c] || c.match(/^mozilla/)) { // Mozilla so abused it's pretty much useless 79 return null; 80 } else { 81 seen[c] = true; 82 return c; 83 } 84 }).join(' '); 85 86 var html = $('html'); 87 html.addClass(classNames); // Add to the html element now to avoid any FOUC 88 89 $(function () { 90 html.removeAttr('class'); 91 $('body').addClass(classNames); 92 }); 93})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.