Stephen McKamey avatar Stephen McKamey committed 4c1b0c0

- mobile tweaks

Comments (0)

Files changed (4)

+glob:ga.js
 	User-agent specific CSS support
 
 	Created: 2006-06-10-1635
-	Modified: 2011-01-04-0934
+	Modified: 2011-01-06-1132
 
 	Copyright (c)2006-2011 Stephen M. McKamey
 	Distributed under The MIT License.
 		R_MSPIE = /\b(mspie|microsoft pocket internet explorer)[\s\/]*(\d+(\.\d+)*)/,
 		R_iCab = /\bicab[\s\/]*(\d+(\.\d+)*)/,
 		R_BlackBerry = /\bblackberry\w*[\s\/]+(\d+(\.\d+)*)/,
-		R_mobile = /(\w*mobile[\/]\w*|\bandroid\b|\bipad\b|\bipod\b|\w*phone\w*|\bpda\b|\bchtml\b|\bmidp\b|\bcldc\b|blackberry\w*|windows ce\b|palm\w*\b|symbian\w*\b)/;
+		R_mobile = /(\w*mobile[\/]\w*|\bandroid\b|\bipad\b|\bipod\b|\w*phone\w*|\bpda\b|\bchtml\b|\bmidp\b|\bcldc\b|blackberry\w*|\bwebos\b|windows ce\b|palm\w*\b|symbian\w*\b)/;
 
 	var cssua = {
 
 
 			// version standardization
 			if (ua.safari) {
-				if (ua.chrome || ua.blackberry) {
+				if (ua.chrome || ua.android || ua.blackberry || ua.webos) {
 					delete ua.safari;
 
 				} else if (ua.version) {
-var cssua=function(i,l){var m=/[\w\-\.]+[\/][v]?\d+(\.\d+)*/g,n=/\b(aol|america online browser)[\s\/]*(\d+(\.\d+)*)/,o=/\b(msie|microsoft internet explorer)[\s\/]*(\d+(\.\d+)*)/,p=/rv[:](\d+(\.\d+)*).*?\bgecko[\/]\d+/,q=/\bopera[\s\/]*(\d+(\.\d+)*)/,r=/\bandroid[\s]+(\d+(\.\d+)*)/,s=/\bos[\s]+(\d+(\_\d+)*) like mac os x/,t=/\b(mspie|microsoft pocket internet explorer)[\s\/]*(\d+(\.\d+)*)/,u=/\bicab[\s\/]*(\d+(\.\d+)*)/,v=/\bblackberry\w*[\s\/]+(\d+(\.\d+)*)/,w=/(\w*mobile[\/]\w*|\bandroid\b|\bipad\b|\bipod\b|\w*phone\w*|\bpda\b|\bchtml\b|\bmidp\b|\bcldc\b|blackberry\w*|windows ce\b|palm\w*\b|symbian\w*\b)/,
+var cssua=function(i,l){var m=/[\w\-\.]+[\/][v]?\d+(\.\d+)*/g,n=/\b(aol|america online browser)[\s\/]*(\d+(\.\d+)*)/,o=/\b(msie|microsoft internet explorer)[\s\/]*(\d+(\.\d+)*)/,p=/rv[:](\d+(\.\d+)*).*?\bgecko[\/]\d+/,q=/\bopera[\s\/]*(\d+(\.\d+)*)/,r=/\bandroid[\s]+(\d+(\.\d+)*)/,s=/\bos[\s]+(\d+(\_\d+)*) like mac os x/,t=/\b(mspie|microsoft pocket internet explorer)[\s\/]*(\d+(\.\d+)*)/,u=/\bicab[\s\/]*(\d+(\.\d+)*)/,v=/\bblackberry\w*[\s\/]+(\d+(\.\d+)*)/,w=/(\w*mobile[\/]\w*|\bandroid\b|\bipad\b|\bipod\b|\w*phone\w*|\bpda\b|\bchtml\b|\bmidp\b|\bcldc\b|blackberry\w*|\bwebos\b|windows ce\b|palm\w*\b|symbian\w*\b)/,
 g={parse:function(b){var a={};b=(""+b).toLowerCase();if(!b)return a;var c=b.match(m);if(c)for(var e=0;e<c.length;e++){var f=c[e].indexOf("/"),d=c[e].substring(0,f);if(d&&d!=="mozilla"){if(d==="applewebkit")d="webkit";a[d]=c[e].substr(f+1)}}if(n.exec(b))a.aol=RegExp.$2;if(q.exec(b))a.opera=RegExp.$1;else if(u.exec(b))a.icab=RegExp.$1;else if(o.exec(b))a.ie=RegExp.$2;else if(t.exec(b))a.mspie=RegExp.$2;else if(p.exec(b))a.gecko=RegExp.$1;else if(r.exec(b))a.android=RegExp.$1;else if(s.exec(b))a.ios=
-RegExp.$1.split("_").join(".");if(!a.blackberry&&v.exec(b))a.blackberry=RegExp.$1;if(w.exec(b))a.mobile=RegExp.$1;if(a.safari)if(a.chrome||a.blackberry)delete a.safari;else a.safari=a.version?a.version:{"419":"2.0.4","417":"2.0.3","416":"2.0.2","412":"2.0","312":"1.3","125":"1.2","85":"1.0"}[parseInt(a.safari,10)]||a.safari;else if(a.opera&&a.version)a.opera=a.version;a.version&&delete a.version;return a},format:function(b){function a(f,d){f=f.split(".").join("-");var j=" ua-"+f;if(d){d=d.split(".").join("-");
-for(var h=d.indexOf("-");h>0;){j+=" ua-"+f+"-"+d.substring(0,h);h=d.indexOf("-",h+1)}j+=" ua-"+f+"-"+d}return j}var c="",e;for(e in b)if(e&&b.hasOwnProperty(e))c+=a(e,b[e]);return c},encode:function(b){var a="",c;for(c in b)if(c&&b.hasOwnProperty(c)){if(a)a+="&";a+=encodeURIComponent(c)+"="+encodeURIComponent(b[c])}return a}};g.userAgent=g.ua=g.parse(l);var k=g.format(g.ua);if(i.className)i.className+=k;else i.className=k.substr(1);return g}(document.documentElement,navigator.userAgent);
+RegExp.$1.split("_").join(".");if(!a.blackberry&&v.exec(b))a.blackberry=RegExp.$1;if(w.exec(b))a.mobile=RegExp.$1;if(a.safari)if(a.chrome||a.android||a.blackberry||a.webos)delete a.safari;else a.safari=a.version?a.version:{"419":"2.0.4","417":"2.0.3","416":"2.0.2","412":"2.0","312":"1.3","125":"1.2","85":"1.0"}[parseInt(a.safari,10)]||a.safari;else if(a.opera&&a.version)a.opera=a.version;a.version&&delete a.version;return a},format:function(b){function a(f,d){f=f.split(".").join("-");var j=" ua-"+
+f;if(d){d=d.split(".").join("-");for(var h=d.indexOf("-");h>0;){j+=" ua-"+f+"-"+d.substring(0,h);h=d.indexOf("-",h+1)}j+=" ua-"+f+"-"+d}return j}var c="",e;for(e in b)if(e&&b.hasOwnProperty(e))c+=a(e,b[e]);return c},encode:function(b){var a="",c;for(c in b)if(c&&b.hasOwnProperty(c)){if(a)a+="&";a+=encodeURIComponent(c)+"="+encodeURIComponent(b[c])}return a}};g.userAgent=g.ua=g.parse(l);var k=g.format(g.ua);if(i.className)i.className+=k;else i.className=k.substr(1);return g}(document.documentElement,
+navigator.userAgent);

test/parseTests.js

 	same(actual, expected, "");
 });
 
-test("HTC Passion, Android (webkit)", function() {
+test("Nexus One, Android (WebKit)", function() {
 
-	var input = "HTC Passion: Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
+	var input = "Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
 
 	var expected =
 		{
 			"webkit" : "533.1",
-			"safari" : "4.0",
 			"android" : "2.2.1",
 			"mobile" : "android"
 		};
 	same(actual, expected, "");
 });
 
-test("HTC Desire, Android (webkit)", function() {
+test("Nexus One, Android (WebKit)", function() {
 
-	var input = "HTC Desire: Mozilla/5.0 (Linux; U; Android 2.1-update1; fr-fr; desire_A8181 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17";
+	var input = "Mozilla/5.0 (Linux; U; Android 2.1-update1; fr-fr; desire_A8181 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17";
 
 	var expected =
 		{
 			"webkit" : "530.17",
-			"safari" : "4.0",
 			"android" : "2.1",
 			"mobile" : "android"
 		};
 	same(actual, expected, "");
 });
 
+test("Nexus S, Android (WebKit)", function() {
+
+	var input = "Mozilla/5.0 (Linux; U; Android 2.3.1; en-us; Nexus S Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
+
+	var expected =
+		{
+			"webkit" : "533.1",
+			"android" : "2.3.1",
+			"mobile" : "android"
+		};
+
+	var actual = cssua.parse(input);
+
+	same(actual, expected, "");
+});
+
 test("Blackberry 9330", function() {
 
 	var input = "BlackBerry9330/5.0.0.913 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/104";
 	same(actual, expected, "");
 });
 
+test("Palm Pre (WebKit)", function() {
+
+	var input = "Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0";
+
+	var expected =
+		{
+			"webos" : "1.0",
+			"webkit" : "525.27.1",
+			"pre" : "1.0",
+			"mobile" : "webos"
+		};
+
+	var actual = cssua.parse(input);
+
+	same(actual, expected, "");
+});
+
+test("HTC TyTN PDA (IE)", function() {
+
+	var input = "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11)";
+
+	var expected =
+		{
+			"ie" : "6.0",
+			"mobile" : "windows ce"
+		};
+
+	var actual = cssua.parse(input);
+
+	same(actual, expected, "");
+});
+
 test("AOL 9.6 (IE 8)", function() {
 
 	var input = "Mozilla/4.0 (compatible; MSIE 8.0; AOL 9.6; AOLBuild 4340.122; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8)";
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.