From 21ae8c571a8f3772478981ee62d9cb34d32fe0a1 Mon Sep 17 00:00:00 2001 From: Baraa Date: Sat, 22 Nov 2014 21:57:14 -0800 Subject: [PATCH 01/26] Update Browser Detection to Support iPod, Kindle and BlackBerry devices. --- README.md | 22 +++-- dist/jquery.browser.js | 37 ++++++--- test/test.js | 180 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2a48746..2dd1943 100644 --- a/README.md +++ b/README.md @@ -28,17 +28,27 @@ Reading the browser verion ## Things not included in the original jQuery $.browser implementation -- Detect Windows, Mac, Linux, iPad, iPhone, Android, Chrome OS, and Windows Phone useragents, in addition to desktop and mobile browsers +- Detect specifically Windows, Mac, Linux, iPad, iPhone, iPod, Android, Kindle, BlackBerry, Chrome OS, and Windows Phone useragents ```javascript - $.browser.ipad - $.browser.iphone - $.browser["windows phone"] $.browser.android + $.browser.blackberry $.browser.cros - $.browser.win - $.browser.mac + $.browser.ipad + $.browser.iphone + $.browser.ipod + $.browser.kindle $.browser.linux + $.browser.mac + $.browser.playbook + $.browser.silk + $.browser.win + $.browser["windows phone"] +``` + +Alternatively, you can detect for generic classifications such as desktop or mobile + +```javascript $.browser.desktop $.browser.mobile ``` diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index a56e816..dd3c9d3 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -31,26 +31,32 @@ jQuery.uaMatch = function( ua ) { ua = ua.toLowerCase(); - var match = /(edge)\/([\w.]+)/.exec( ua ) || + var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || + /(edge)\/([\w.]+)/.exec( ua ) || + /(msie) ([\w.]+)/.exec( ua ) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || /(opr)[\/]([\w.]+)/.exec( ua ) || - /(chrome)[ \/]([\w.]+)/.exec( ua ) || /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+)/.exec( ua ) || - /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || - /(msie) ([\w.]+)/.exec( ua ) || ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || []; - var platform_match = /(ipad)/.exec( ua ) || + var platform_match = /(android)/.exec( ua ) || + /(bb)/.exec( ua ) || + /(blackberry)/.exec( ua ) || + /(cros)/.exec( ua ) || + /(ipad)/.exec( ua ) || /(iphone)/.exec( ua ) || - /(android)/.exec( ua ) || - /(windows phone)/.exec( ua ) || - /(win)/.exec( ua ) || - /(mac)/.exec( ua ) || + /(ipod)/.exec( ua ) || + /(kindle)/.exec( ua ) || /(linux)/.exec( ua ) || - /(cros)/.exec( ua ) || + /(mac)/.exec( ua ) || + /(playbook)/.exec( ua ) || + /(silk)/.exec( ua ) || + /(win)/.exec( ua ) || + /(windows phone)/.exec( ua ) || []; return { @@ -75,7 +81,8 @@ } // These are all considered mobile platforms, meaning they run a mobile browser - if ( browser.android || browser.ipad || browser.iphone || browser[ "windows phone" ] ) { + if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone || + browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) { browser.mobile = true; } @@ -98,6 +105,14 @@ browser[ie] = true; } + // BB10 is a newer OS version of BlackBerry + if ( browser.bb ) { + var blackberry = "blackberry"; + + matched.browser = blackberry; + browser[blackberry] = true; + } + // Opera 15+ are identified as opr if ( browser.opr ) { var opera = "opera"; diff --git a/test/test.js b/test/test.js index 82e3937..43b4232 100644 --- a/test/test.js +++ b/test/test.js @@ -26,6 +26,7 @@ var ua = { mac: "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71", ipad: "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53", iphone: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53", + ipod: "Mozilla/5.0 (iPod; CPU iPod OS 7_0 like Mac OS X) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53", version: "537.71", versionNumber: 7, name: "safari" @@ -78,6 +79,46 @@ var ua = { versionNumber: 4 }, name: "android" + }, + kindle : { + v_4: { + kindle : "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", + version: "533.1", + versionNumber: 4 + }, + name: "kindle" + }, + silk : { + v_5: { + silk : "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true", + version: "533.16", + versionNumber: 5 + }, + name: "silk" + }, + blackberry : { + v_7: { + blackberry : "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+", + version: "534.11", + versionNumber: 7 + }, + name: "blackberry" + }, + bb : { + v_10: { + bb : "Mozilla/5.0 (BB10; Touch) AppleWebKit/537.1 (KHTML, like Gecko) Version/10.0.0.1337 Mobile Safari/537.1", + version: "537.1", + versionNumber: 10 + }, + name: "bb" + }, + playbook : { + v_7: { + playbook : "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+", + version: "536.2", + versionNumber: 7 + }, + name: "playbook" } }; @@ -348,6 +389,30 @@ casper.test.begin("when using Safari on iPhone", 7, function(test) { }); }); +casper.test.begin("when using Safari on iPod", 7, function(test) { + casper.userAgent(ua.safari.ipod); + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return $.browser; + }); + + test.assert(browser.safari, "Browser should be Safari"); + test.assertEquals(browser.name, ua.safari.name,"Browser name should be " + ua.safari.name); + + test.assert(browser.webkit, "Browser should be WebKit based"); + test.assertEquals(browser.version, ua.safari.version, "Version should be " + ua.safari.version); + test.assertEquals(browser.versionNumber, ua.safari.versionNumber, "Version number should be " + ua.safari.versionNumber); + + test.assert(browser.mobile, "Browser platform should be mobile"); + test.assert(browser.ipod, "Platform should be iPod"); + + }).run(function(){ + test.done(); + }); +}); + casper.test.begin("when using IE9", 7, function(test) { casper.userAgent(ua.ie.windows.v_9); @@ -642,6 +707,121 @@ casper.test.begin("when using Android 4.4 stock browser on Android", 6, function test.assert(browser.mobile, "Browser platform should be mobile"); test.assert(browser.webkit, "Browser should be WebKit based"); + }).run(function(){ + test.done(); + }); +}); + +casper.test.begin("when using Kindle 4 stock browser", 6, function(test) { + casper.userAgent(ua.kindle.v_4.kindle); + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return $.browser; + }); + + test.assert(browser.kindle, "Browser should be Kindle"); + test.assertEquals(browser.name, ua.kindle.name,"Browser name should be " + ua.kindle.name); + + test.assertEquals(browser.version, ua.kindle.v_4.version, "Version should be " + ua.kindle.v_4.version); + test.assertEquals(browser.versionNumber, ua.kindle.v_4.versionNumber, "Version number should be " + ua.kindle.v_4.versionNumber); + + test.assert(browser.mobile, "Browser platform should be mobile"); + test.assert(browser.webkit, "Browser should be WebKit based"); + + }).run(function(){ + test.done(); + }); +}); + +casper.test.begin("when using Kindle Silk 5 browser", 6, function(test) { + casper.userAgent(ua.silk.v_5.silk); + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return $.browser; + }); + + test.assert(browser.silk, "Browser should be Silk"); + test.assertEquals(browser.name, ua.silk.name,"Browser name should be " + ua.silk.name); + + test.assertEquals(browser.version, ua.silk.v_5.version, "Version should be " + ua.silk.v_5.version); + test.assertEquals(browser.versionNumber, ua.silk.v_5.versionNumber, "Version number should be " + ua.silk.v_5.versionNumber); + + test.assert(browser.mobile, "Browser platform should be mobile"); + test.assert(browser.webkit, "Browser should be WebKit based"); + + }).run(function(){ + test.done(); + }); +}); + +casper.test.begin("when using BlackBerry 7 stock browser", 6, function(test) { + casper.userAgent(ua.blackberry.v_7.blackberry); + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return $.browser; + }); + + test.assert(browser.blackberry, "Browser should be BlackBerry"); + test.assertEquals(browser.name, ua.blackberry.name,"Browser name should be " + ua.blackberry.name); + + test.assertEquals(browser.version, ua.blackberry.v_7.version, "Version should be " + ua.blackberry.v_7.version); + test.assertEquals(browser.versionNumber, ua.blackberry.v_7.versionNumber, "Version number should be " + ua.blackberry.v_7.versionNumber); + + test.assert(browser.mobile, "Browser platform should be mobile"); + test.assert(browser.webkit, "Browser should be WebKit based"); + + }).run(function(){ + test.done(); + }); +}); + +casper.test.begin("when using BB10 stock browser", 6, function(test) { + casper.userAgent(ua.bb.v_10.bb); + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return $.browser; + }); + + test.assert(browser.blackberry, "Browser should be BlackBerry"); + test.assertEquals(browser.name, ua.blackberry.name,"Browser name should be " + ua.blackberry.name); + + test.assertEquals(browser.version, ua.bb.v_10.version, "Version should be " + ua.bb.v_10.version); + test.assertEquals(browser.versionNumber, ua.bb.v_10.versionNumber, "Version number should be " + ua.bb.v_10.versionNumber); + + test.assert(browser.mobile, "Browser platform should be mobile"); + test.assert(browser.webkit, "Browser should be WebKit based"); + + }).run(function(){ + test.done(); + }); +}); + +casper.test.begin("when using BlackBerry PlayBook stock browser", 6, function(test) { + casper.userAgent(ua.playbook.v_7.playbook); + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return $.browser; + }); + + test.assert(browser.playbook, "Browser should be BlackBerry PlayBook"); + test.assertEquals(browser.name, ua.playbook.name,"Browser name should be " + ua.playbook.name); + + test.assertEquals(browser.version, ua.playbook.v_7.version, "Version should be " + ua.playbook.v_7.version); + test.assertEquals(browser.versionNumber, ua.playbook.v_7.versionNumber, "Version number should be " + ua.playbook.v_7.versionNumber); + + test.assert(browser.mobile, "Browser platform should be mobile"); + test.assert(browser.webkit, "Browser should be WebKit based"); + }).run(function(){ test.done(); casper.exit(); From 4bb46ae5018e40a3d19745a21558cf3c7306a915 Mon Sep 17 00:00:00 2001 From: Triangle717 Date: Fri, 12 Dec 2014 12:02:52 -0500 Subject: [PATCH 02/26] Restore and improve ordering of `match` and `platform_match`, fix incorrect identification of all Blackberry and Kindle browers --- dist/jquery.browser.js | 64 +++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index dd3c9d3..064e75f 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -31,32 +31,32 @@ jQuery.uaMatch = function( ua ) { ua = ua.toLowerCase(); - var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || - /(edge)\/([\w.]+)/.exec( ua ) || - /(msie) ([\w.]+)/.exec( ua ) || - /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || + var match = /(edge)\/([\w.]+)/.exec( ua ) || /(opr)[\/]([\w.]+)/.exec( ua ) || + /(chrome)[ \/]([\w.]+)/.exec( ua ) || /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+)/.exec( ua ) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || + /(msie) ([\w.]+)/.exec( ua ) || ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || []; - var platform_match = /(android)/.exec( ua ) || - /(bb)/.exec( ua ) || - /(blackberry)/.exec( ua ) || - /(cros)/.exec( ua ) || - /(ipad)/.exec( ua ) || - /(iphone)/.exec( ua ) || + var platform_match = /(ipad)/.exec( ua ) || /(ipod)/.exec( ua ) || + /(iphone)/.exec( ua ) || /(kindle)/.exec( ua ) || - /(linux)/.exec( ua ) || - /(mac)/.exec( ua ) || - /(playbook)/.exec( ua ) || /(silk)/.exec( ua ) || - /(win)/.exec( ua ) || + /(android)/.exec( ua ) || /(windows phone)/.exec( ua ) || + /(win)/.exec( ua ) || + /(mac)/.exec( ua ) || + /(linux)/.exec( ua ) || + /(cros)/.exec( ua ) || + /(playbook)/.exec( ua ) || + /(bb)/.exec( ua ) || + /(blackberry)/.exec( ua ) || []; return { @@ -105,14 +105,30 @@ browser[ie] = true; } - // BB10 is a newer OS version of BlackBerry - if ( browser.bb ) { + // Blackberry browsers are marked as Safari on BlackBerry + if ( browser.safari && browser.blackberry ) { var blackberry = "blackberry"; matched.browser = blackberry; browser[blackberry] = true; } + // Playbook browsers are marked as Safari on Playbook + if ( browser.safari && browser.playbook ) { + var playbook = "playbook"; + + matched.browser = playbook; + browser[playbook] = true; + } + + // BB10 is a newer OS version of BlackBerry + if ( browser.bb ) { + var bb = "blackberry"; + + matched.browser = bb; + browser[bb] = true; + } + // Opera 15+ are identified as opr if ( browser.opr ) { var opera = "opera"; @@ -129,6 +145,22 @@ browser[android] = true; } + // Kindle browsers are marked as Safari on Kindle + if ( browser.safari && browser.kindle ) { + var kindle = "kindle"; + + matched.browser = kindle; + browser[kindle] = true; + } + + // Kindle Silk browsers are marked as Safari on Kindle + if ( browser.safari && browser.silk ) { + var silk = "silk"; + + matched.browser = silk; + browser[silk] = true; + } + // Assign the name and platform variable browser.name = matched.browser; browser.platform = matched.platform; From 7ed56e71bc4500dabbc39615a6ad1195fc3e8173 Mon Sep 17 00:00:00 2001 From: Triangle717 Date: Fri, 12 Dec 2014 17:54:35 -0500 Subject: [PATCH 03/26] Update version to v0.0.7 --- dist/jquery.browser.js | 6 +- dist/jquery.browser.min.js | 6 +- package.json | 2 +- test/src/jquery.browser.js | 125 +++++++++++++++++++++++++++---------- 4 files changed, 98 insertions(+), 41 deletions(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index 064e75f..e105e95 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -1,16 +1,16 @@ /*! - * jQuery Browser Plugin v0.0.6 + * jQuery Browser Plugin 0.0.7 * https://github.com/gabceb/jquery-browser-plugin * * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors * http://jquery.org/license * - * Modifications Copyright 2013 Gabriel Cebrian + * Modifications Copyright 2014 Gabriel Cebrian * https://github.com/gabceb * * Released under the MIT license * - * Date: 2013-07-29T17:23:27-07:00 + * Date: 12-12-2014 */ (function (root, factory) { diff --git a/dist/jquery.browser.min.js b/dist/jquery.browser.min.js index d5f6aa3..f8e0482 100644 --- a/dist/jquery.browser.min.js +++ b/dist/jquery.browser.min.js @@ -1,5 +1,5 @@ /*! - * jQuery Browser Plugin 0.0.6 + * jQuery Browser Plugin 0.0.7 * https://github.com/gabceb/jquery-browser-plugin * * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors @@ -10,5 +10,5 @@ * * Released under the MIT license * - * Date: 28-09-2014 - */!function(a,b){"use strict";var c,d;if(a.uaMatch=function(a){a=a.toLowerCase();var b=/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(iphone)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||/(cros)/.exec(a)||[];return{browser:b[3]||b[1]||"",version:b[4]||b[2],versionNumber:b[2]||"0",platform:c[0]||""}},c=a.uaMatch(b.navigator.userAgent),d={},c.browser&&(d[c.browser]=!0,d.version=c.version,d.versionNumber=parseInt(c.versionNumber)),c.platform&&(d[c.platform]=!0),(d.android||d.ipad||d.iphone||d["windows phone"])&&(d.mobile=!0),(d.cros||d.mac||d.linux||d.win)&&(d.desktop=!0),(d.chrome||d.opr||d.safari)&&(d.webkit=!0),d.rv){var e="msie";c.browser=e,d[e]=!0}if(d.opr){var f="opera";c.browser=f,d[f]=!0}if(d.safari&&d.android){var g="android";c.browser=g,d[g]=!0}d.name=c.browser,d.platform=c.platform,a.browser=d}(jQuery,window); \ No newline at end of file + * Date: 12-12-2014 + */!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){b(c,a)}):b(jQuery,a)}(this,function(a,b){"use strict";var c,d;if(a.uaMatch=function(a){a=a.toLowerCase();var b=/(edge)\/([\w.]+)/.exec(a)||/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(ipod)/.exec(a)||/(iphone)/.exec(a)||/(kindle)/.exec(a)||/(silk)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||/(cros)/.exec(a)||/(playbook)/.exec(a)||/(bb)/.exec(a)||/(blackberry)/.exec(a)||[];return{browser:b[5]||b[3]||b[1]||"",version:b[2]||b[4]||"0",versionNumber:b[4]||b[2]||"0",platform:c[0]||""}},c=a.uaMatch(b.navigator.userAgent),d={},c.browser&&(d[c.browser]=!0,d.version=c.version,d.versionNumber=parseInt(c.versionNumber,10)),c.platform&&(d[c.platform]=!0),(d.android||d.bb||d.blackberry||d.ipad||d.iphone||d.ipod||d.kindle||d.playbook||d.silk||d["windows phone"])&&(d.mobile=!0),(d.cros||d.mac||d.linux||d.win)&&(d.desktop=!0),(d.chrome||d.opr||d.safari)&&(d.webkit=!0),d.rv||d.edge){var e="msie";c.browser=e,d[e]=!0}if(d.safari&&d.blackberry){var f="blackberry";c.browser=f,d[f]=!0}if(d.safari&&d.playbook){var g="playbook";c.browser=g,d[g]=!0}if(d.bb){var h="blackberry";c.browser=h,d[h]=!0}if(d.opr){var i="opera";c.browser=i,d[i]=!0}if(d.safari&&d.android){var j="android";c.browser=j,d[j]=!0}if(d.safari&&d.kindle){var k="kindle";c.browser=k,d[k]=!0}if(d.safari&&d.silk){var l="silk";c.browser=l,d[l]=!0}return d.name=c.browser,d.platform=c.platform,a.browser=d,d}); \ No newline at end of file diff --git a/package.json b/package.json index 4312f40..df0b02b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.browser", - "version": "0.0.6", + "version": "0.0.7", "authors": [ "Gabriel Cebrian ", "jQuery Team " diff --git a/test/src/jquery.browser.js b/test/src/jquery.browser.js index ceea0e4..e105e95 100644 --- a/test/src/jquery.browser.js +++ b/test/src/jquery.browser.js @@ -1,19 +1,29 @@ /*! - * jQuery Browser Plugin v0.0.6 + * jQuery Browser Plugin 0.0.7 * https://github.com/gabceb/jquery-browser-plugin * * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors * http://jquery.org/license * - * Modifications Copyright 2013 Gabriel Cebrian + * Modifications Copyright 2014 Gabriel Cebrian * https://github.com/gabceb * * Released under the MIT license * - * Date: 2013-07-29T17:23:27-07:00 + * Date: 12-12-2014 */ -(function( jQuery, window, undefined ) { +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], function ($) { + factory($, root); + }); + } else { + // Browser globals + factory(jQuery, root); + } +}(this, function(jQuery, window) { "use strict"; var matched, browser; @@ -21,30 +31,38 @@ jQuery.uaMatch = function( ua ) { ua = ua.toLowerCase(); - var match = /(opr)[\/]([\w.]+)/.exec( ua ) || - /(chrome)[ \/]([\w.]+)/.exec( ua ) || - /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || - /(webkit)[ \/]([\w.]+)/.exec( ua ) || - /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || - /(msie) ([\w.]+)/.exec( ua ) || - ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) || - ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || - []; + var match = /(edge)\/([\w.]+)/.exec( ua ) || + /(opr)[\/]([\w.]+)/.exec( ua ) || + /(chrome)[ \/]([\w.]+)/.exec( ua ) || + /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || + /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || + /(webkit)[ \/]([\w.]+)/.exec( ua ) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || + /(msie) ([\w.]+)/.exec( ua ) || + ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) || + ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || + []; var platform_match = /(ipad)/.exec( ua ) || - /(iphone)/.exec( ua ) || - /(android)/.exec( ua ) || - /(windows phone)/.exec( ua ) || - /(win)/.exec( ua ) || - /(mac)/.exec( ua ) || - /(linux)/.exec( ua ) || - /(cros)/.exec( ua ) || - []; + /(ipod)/.exec( ua ) || + /(iphone)/.exec( ua ) || + /(kindle)/.exec( ua ) || + /(silk)/.exec( ua ) || + /(android)/.exec( ua ) || + /(windows phone)/.exec( ua ) || + /(win)/.exec( ua ) || + /(mac)/.exec( ua ) || + /(linux)/.exec( ua ) || + /(cros)/.exec( ua ) || + /(playbook)/.exec( ua ) || + /(bb)/.exec( ua ) || + /(blackberry)/.exec( ua ) || + []; return { - browser: match[ 3 ] || match[ 1 ] || "", - version: match[ 4 ] || match[ 2 ], - versionNumber: match[ 2 ] || "0", + browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "", + version: match[ 2 ] || match[ 4 ] || "0", + versionNumber: match[ 4 ] || match[ 2 ] || "0", platform: platform_match[ 0 ] || "" }; }; @@ -55,7 +73,7 @@ if ( matched.browser ) { browser[ matched.browser ] = true; browser.version = matched.version; - browser.versionNumber = parseInt(matched.versionNumber); + browser.versionNumber = parseInt(matched.versionNumber, 10); } if ( matched.platform ) { @@ -63,7 +81,8 @@ } // These are all considered mobile platforms, meaning they run a mobile browser - if ( browser.android || browser.ipad || browser.iphone || browser[ "windows phone" ] ) { + if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone || + browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) { browser.mobile = true; } @@ -78,17 +97,40 @@ } // IE11 has a new token so we will assign it msie to avoid breaking changes - if ( browser.rv ) - { + // IE12 disguises itself as Chrome, but adds a new Edge token. + if ( browser.rv || browser.edge ) { var ie = "msie"; matched.browser = ie; browser[ie] = true; } + // Blackberry browsers are marked as Safari on BlackBerry + if ( browser.safari && browser.blackberry ) { + var blackberry = "blackberry"; + + matched.browser = blackberry; + browser[blackberry] = true; + } + + // Playbook browsers are marked as Safari on Playbook + if ( browser.safari && browser.playbook ) { + var playbook = "playbook"; + + matched.browser = playbook; + browser[playbook] = true; + } + + // BB10 is a newer OS version of BlackBerry + if ( browser.bb ) { + var bb = "blackberry"; + + matched.browser = bb; + browser[bb] = true; + } + // Opera 15+ are identified as opr - if ( browser.opr ) - { + if ( browser.opr ) { var opera = "opera"; matched.browser = opera; @@ -96,18 +138,33 @@ } // Stock Android browsers are marked as Safari on Android. - if ( browser.safari && browser.android ) - { + if ( browser.safari && browser.android ) { var android = "android"; matched.browser = android; browser[android] = true; } + // Kindle browsers are marked as Safari on Kindle + if ( browser.safari && browser.kindle ) { + var kindle = "kindle"; + + matched.browser = kindle; + browser[kindle] = true; + } + + // Kindle Silk browsers are marked as Safari on Kindle + if ( browser.safari && browser.silk ) { + var silk = "silk"; + + matched.browser = silk; + browser[silk] = true; + } + // Assign the name and platform variable browser.name = matched.browser; browser.platform = matched.platform; - jQuery.browser = browser; -})( jQuery, window ); + return browser; +})); From 551e46471fe3df20e9bcdd35fe42eb2f77b0a2f2 Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Wed, 24 Dec 2014 13:41:58 -0600 Subject: [PATCH 04/26] Support for node/browserify Fixes two compatibility issues: 1. Inside wrapped browserify modules, `this` does not refer to `window`, it's the `exports` object. Since it doesn't really make sense to use this plugin in environments that don't have a window.navigator object, the code now just references 'window' directly. 2. The plugin did a global export if AMD wasn't detected, which assumed there was a global jQuery object. The added `module.exports`-detection uses `require` to pull in jQuery instead. --- dist/jquery.browser.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index e105e95..c36fb85 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -13,17 +13,20 @@ * Date: 12-12-2014 */ -(function (root, factory) { +(function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['jquery'], function ($) { - factory($, root); + factory($); }); + } else if (typeof module === 'object' && typeof module.exports === 'object') { + // Node-like environment + module.exports = factory(require('jquery')); } else { // Browser globals - factory(jQuery, root); + factory(jQuery); } -}(this, function(jQuery, window) { +}(function(jQuery) { "use strict"; var matched, browser; From 4ad34a3deee392e555d7a71288ec3d0006920ab4 Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Wed, 24 Dec 2014 14:47:50 -0600 Subject: [PATCH 05/26] Ignore JSLint "window is not defined" warning --- dist/jquery.browser.js | 1 + 1 file changed, 1 insertion(+) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index c36fb85..1bd144a 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -70,6 +70,7 @@ }; }; + /*global window: false */ matched = jQuery.uaMatch( window.navigator.userAgent ); browser = {}; From 890ce608ed2293e57b9ef6467b2e0d2ffb72ecf3 Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Wed, 24 Dec 2014 16:39:00 -0600 Subject: [PATCH 06/26] Move JSLint hint to top of file --- dist/jquery.browser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index 1bd144a..57b58e7 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -13,6 +13,8 @@ * Date: 12-12-2014 */ +/*global window: false */ + (function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. @@ -70,7 +72,6 @@ }; }; - /*global window: false */ matched = jQuery.uaMatch( window.navigator.userAgent ); browser = {}; From e4a01fd783d4684659b3193626b5553f0d8f6758 Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Wed, 24 Dec 2014 16:40:41 -0600 Subject: [PATCH 07/26] Remove newline --- dist/jquery.browser.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index 57b58e7..cb3db86 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -12,7 +12,6 @@ * * Date: 12-12-2014 */ - /*global window: false */ (function (factory) { From 28e2f4d6965150d9bd44aec4ee35754ff67329a7 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 15:21:44 -0500 Subject: [PATCH 08/26] Add travis testing to project --- package.json | 3 +++ travis.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 travis.yml diff --git a/package.json b/package.json index df0b02b..1359416 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "Gabriel Cebrian ", "jQuery Team " ], + "scripts": { + "test": "grunt test" + }, "description": "A jQuery plugin for browser detection.", "main": "dist/jquery.browser.js", "repository": "git@github.com:gabceb/jquery-browser-plugin.git", diff --git a/travis.yml b/travis.yml new file mode 100644 index 0000000..feb6515 --- /dev/null +++ b/travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - "0.10.x" +before_install: npm install -g grunt-cli; npm install -g casperjs +install: npm install \ No newline at end of file From 28668043dc93aec6f923226e0ae3e93de63ed60b Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 15:23:39 -0500 Subject: [PATCH 09/26] Fixed travis config filename --- travis.yml => .travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename travis.yml => .travis.yml (100%) diff --git a/travis.yml b/.travis.yml similarity index 100% rename from travis.yml rename to .travis.yml From 4936b779c939d0ba4d64fa8ae3e80bdd63e7ebbe Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 15:25:49 -0500 Subject: [PATCH 10/26] Fixed Node version on travis file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index feb6515..8deaf3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: - - "0.10.x" + - "0.10" before_install: npm install -g grunt-cli; npm install -g casperjs install: npm install \ No newline at end of file From 0780928fba9c0dce01ef2e6ceece24d7f47d9bc7 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 15:31:11 -0500 Subject: [PATCH 11/26] Added build status to README file Fixes #45 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2dd1943..99c60ee 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ [![NPM](https://nodei.co/npm/jquery.browser.png)](https://nodei.co/npm/jquery.browser/) +[![Build Status](https://travis-ci.org/gabceb/jquery-browser-plugin.svg?branch=master)](https://travis-ci.org/gabceb/jquery-browser-plugin) + A jQuery plugin for browser detection. jQuery removed support for browser detection on 1.9.1 so it was abstracted into a jQuery plugin ## Installation From 471b236a18f7aff3d3b9c4372eaef641ddda03d8 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 15:41:48 -0500 Subject: [PATCH 12/26] Removed test src file so we can gitignore it --- test/src/jquery.browser.js | 170 ------------------------------------- 1 file changed, 170 deletions(-) delete mode 100644 test/src/jquery.browser.js diff --git a/test/src/jquery.browser.js b/test/src/jquery.browser.js deleted file mode 100644 index e105e95..0000000 --- a/test/src/jquery.browser.js +++ /dev/null @@ -1,170 +0,0 @@ -/*! - * jQuery Browser Plugin 0.0.7 - * https://github.com/gabceb/jquery-browser-plugin - * - * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors - * http://jquery.org/license - * - * Modifications Copyright 2014 Gabriel Cebrian - * https://github.com/gabceb - * - * Released under the MIT license - * - * Date: 12-12-2014 - */ - -(function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define(['jquery'], function ($) { - factory($, root); - }); - } else { - // Browser globals - factory(jQuery, root); - } -}(this, function(jQuery, window) { - "use strict"; - - var matched, browser; - - jQuery.uaMatch = function( ua ) { - ua = ua.toLowerCase(); - - var match = /(edge)\/([\w.]+)/.exec( ua ) || - /(opr)[\/]([\w.]+)/.exec( ua ) || - /(chrome)[ \/]([\w.]+)/.exec( ua ) || - /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || - /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || - /(webkit)[ \/]([\w.]+)/.exec( ua ) || - /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || - /(msie) ([\w.]+)/.exec( ua ) || - ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) || - ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || - []; - - var platform_match = /(ipad)/.exec( ua ) || - /(ipod)/.exec( ua ) || - /(iphone)/.exec( ua ) || - /(kindle)/.exec( ua ) || - /(silk)/.exec( ua ) || - /(android)/.exec( ua ) || - /(windows phone)/.exec( ua ) || - /(win)/.exec( ua ) || - /(mac)/.exec( ua ) || - /(linux)/.exec( ua ) || - /(cros)/.exec( ua ) || - /(playbook)/.exec( ua ) || - /(bb)/.exec( ua ) || - /(blackberry)/.exec( ua ) || - []; - - return { - browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "", - version: match[ 2 ] || match[ 4 ] || "0", - versionNumber: match[ 4 ] || match[ 2 ] || "0", - platform: platform_match[ 0 ] || "" - }; - }; - - matched = jQuery.uaMatch( window.navigator.userAgent ); - browser = {}; - - if ( matched.browser ) { - browser[ matched.browser ] = true; - browser.version = matched.version; - browser.versionNumber = parseInt(matched.versionNumber, 10); - } - - if ( matched.platform ) { - browser[ matched.platform ] = true; - } - - // These are all considered mobile platforms, meaning they run a mobile browser - if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone || - browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) { - browser.mobile = true; - } - - // These are all considered desktop platforms, meaning they run a desktop browser - if ( browser.cros || browser.mac || browser.linux || browser.win ) { - browser.desktop = true; - } - - // Chrome, Opera 15+ and Safari are webkit based browsers - if ( browser.chrome || browser.opr || browser.safari ) { - browser.webkit = true; - } - - // IE11 has a new token so we will assign it msie to avoid breaking changes - // IE12 disguises itself as Chrome, but adds a new Edge token. - if ( browser.rv || browser.edge ) { - var ie = "msie"; - - matched.browser = ie; - browser[ie] = true; - } - - // Blackberry browsers are marked as Safari on BlackBerry - if ( browser.safari && browser.blackberry ) { - var blackberry = "blackberry"; - - matched.browser = blackberry; - browser[blackberry] = true; - } - - // Playbook browsers are marked as Safari on Playbook - if ( browser.safari && browser.playbook ) { - var playbook = "playbook"; - - matched.browser = playbook; - browser[playbook] = true; - } - - // BB10 is a newer OS version of BlackBerry - if ( browser.bb ) { - var bb = "blackberry"; - - matched.browser = bb; - browser[bb] = true; - } - - // Opera 15+ are identified as opr - if ( browser.opr ) { - var opera = "opera"; - - matched.browser = opera; - browser[opera] = true; - } - - // Stock Android browsers are marked as Safari on Android. - if ( browser.safari && browser.android ) { - var android = "android"; - - matched.browser = android; - browser[android] = true; - } - - // Kindle browsers are marked as Safari on Kindle - if ( browser.safari && browser.kindle ) { - var kindle = "kindle"; - - matched.browser = kindle; - browser[kindle] = true; - } - - // Kindle Silk browsers are marked as Safari on Kindle - if ( browser.safari && browser.silk ) { - var silk = "silk"; - - matched.browser = silk; - browser[silk] = true; - } - - // Assign the name and platform variable - browser.name = matched.browser; - browser.platform = matched.platform; - - jQuery.browser = browser; - return browser; -})); From 269a616e961cad95768fba86a0f334ca02cb3ad3 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 15:43:07 -0500 Subject: [PATCH 13/26] Ignore the copied test src file --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1d6f27b..edfa242 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ lib-cov *.pid *.gz +test/src/ + pids logs results @@ -14,4 +16,4 @@ results npm-debug.log node_modules -.DS_STORE \ No newline at end of file +.DS_STORE From bc41bf89481ee3e009178c3c2dbf34e23622764b Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 15:43:20 -0500 Subject: [PATCH 14/26] Updated min file --- dist/jquery.browser.min.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/jquery.browser.min.js b/dist/jquery.browser.min.js index f8e0482..adbfd0a 100644 --- a/dist/jquery.browser.min.js +++ b/dist/jquery.browser.min.js @@ -10,5 +10,5 @@ * * Released under the MIT license * - * Date: 12-12-2014 - */!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){b(c,a)}):b(jQuery,a)}(this,function(a,b){"use strict";var c,d;if(a.uaMatch=function(a){a=a.toLowerCase();var b=/(edge)\/([\w.]+)/.exec(a)||/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(ipod)/.exec(a)||/(iphone)/.exec(a)||/(kindle)/.exec(a)||/(silk)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||/(cros)/.exec(a)||/(playbook)/.exec(a)||/(bb)/.exec(a)||/(blackberry)/.exec(a)||[];return{browser:b[5]||b[3]||b[1]||"",version:b[2]||b[4]||"0",versionNumber:b[4]||b[2]||"0",platform:c[0]||""}},c=a.uaMatch(b.navigator.userAgent),d={},c.browser&&(d[c.browser]=!0,d.version=c.version,d.versionNumber=parseInt(c.versionNumber,10)),c.platform&&(d[c.platform]=!0),(d.android||d.bb||d.blackberry||d.ipad||d.iphone||d.ipod||d.kindle||d.playbook||d.silk||d["windows phone"])&&(d.mobile=!0),(d.cros||d.mac||d.linux||d.win)&&(d.desktop=!0),(d.chrome||d.opr||d.safari)&&(d.webkit=!0),d.rv||d.edge){var e="msie";c.browser=e,d[e]=!0}if(d.safari&&d.blackberry){var f="blackberry";c.browser=f,d[f]=!0}if(d.safari&&d.playbook){var g="playbook";c.browser=g,d[g]=!0}if(d.bb){var h="blackberry";c.browser=h,d[h]=!0}if(d.opr){var i="opera";c.browser=i,d[i]=!0}if(d.safari&&d.android){var j="android";c.browser=j,d[j]=!0}if(d.safari&&d.kindle){var k="kindle";c.browser=k,d[k]=!0}if(d.safari&&d.silk){var l="silk";c.browser=l,d[l]=!0}return d.name=c.browser,d.platform=c.platform,a.browser=d,d}); \ No newline at end of file + * Date: 25-12-2014 + */!function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){a(b)}):"object"==typeof module&&"object"==typeof module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){"use strict";var b,c;if(a.uaMatch=function(a){a=a.toLowerCase();var b=/(edge)\/([\w.]+)/.exec(a)||/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(ipod)/.exec(a)||/(iphone)/.exec(a)||/(kindle)/.exec(a)||/(silk)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||/(cros)/.exec(a)||/(playbook)/.exec(a)||/(bb)/.exec(a)||/(blackberry)/.exec(a)||[];return{browser:b[5]||b[3]||b[1]||"",version:b[2]||b[4]||"0",versionNumber:b[4]||b[2]||"0",platform:c[0]||""}},b=a.uaMatch(window.navigator.userAgent),c={},b.browser&&(c[b.browser]=!0,c.version=b.version,c.versionNumber=parseInt(b.versionNumber,10)),b.platform&&(c[b.platform]=!0),(c.android||c.bb||c.blackberry||c.ipad||c.iphone||c.ipod||c.kindle||c.playbook||c.silk||c["windows phone"])&&(c.mobile=!0),(c.cros||c.mac||c.linux||c.win)&&(c.desktop=!0),(c.chrome||c.opr||c.safari)&&(c.webkit=!0),c.rv||c.edge){var d="msie";b.browser=d,c[d]=!0}if(c.safari&&c.blackberry){var e="blackberry";b.browser=e,c[e]=!0}if(c.safari&&c.playbook){var f="playbook";b.browser=f,c[f]=!0}if(c.bb){var g="blackberry";b.browser=g,c[g]=!0}if(c.opr){var h="opera";b.browser=h,c[h]=!0}if(c.safari&&c.android){var i="android";b.browser=i,c[i]=!0}if(c.safari&&c.kindle){var j="kindle";b.browser=j,c[j]=!0}if(c.safari&&c.silk){var k="silk";b.browser=k,c[k]=!0}return c.name=b.browser,c.platform=b.platform,a.browser=c,c}); \ No newline at end of file From ece5dcecf7b7ad338919caedb6757e7fb3c888b9 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 16:52:39 -0500 Subject: [PATCH 15/26] Make gitignore more specific --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index edfa242..1bdc9b3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ lib-cov *.pid *.gz -test/src/ +test/src/jquery.browser.js pids logs From 3f6c1da52cb5c3d5f4a9fc2d6af6e61f4529574a Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 16:58:10 -0500 Subject: [PATCH 16/26] Added simple RequireJs testing using browserify --- .gitignore | 1 + Gruntfile.js | 17 ++++++++++++++++- package.json | 12 ++++++++---- test/src/require/test.js | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 test/src/require/test.js diff --git a/.gitignore b/.gitignore index 1bdc9b3..b76bbf2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ lib-cov *.gz test/src/jquery.browser.js +test/test-require.js pids logs diff --git a/Gruntfile.js b/Gruntfile.js index bf401eb..2e6961b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,12 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), + browserify: { + 'test/test-require.js': ['test/src/require/test.js'], + options: { + banner: '/*\n\n ****** Testing Require file ****** \n\n*/' + } + }, jshint: { files: ['Gruntfile.js', 'dist/jquery.browser.js', 'test/test.js'], @@ -33,6 +39,11 @@ module.exports = function(grunt) { command: "casperjs test test/test.js", stdout: true, stderr: true + }, + 'test-require': { + command: "./node_modules/.bin/mocha test/test-require.js", + stdout: true, + stderr: true } } }); @@ -41,7 +52,11 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-exec'); + grunt.loadNpmTasks('grunt-browserify'); grunt.registerTask('default', ['jshint', 'uglify', 'copy']); - grunt.registerTask('test', ['default', 'exec']); + + grunt.registerTask('test-jquery', ['default', 'exec']); + grunt.registerTask('test-require', ['default', 'browserify', 'exec:test-require']); + grunt.registerTask('test', ['test-jquery', 'test-require']); }; diff --git a/package.json b/package.json index 1359416..7116c1d 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,17 @@ "main": "dist/jquery.browser.js", "repository": "git@github.com:gabceb/jquery-browser-plugin.git", "devDependencies": { - "webserver": "*", - "utils": "*", + "chai": "^1.10.0", "grunt": "~0.4.0", + "grunt-browserify": "^3.2.1", + "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "~0.1.1", "grunt-contrib-uglify": "~0.2.7", - "grunt-contrib-copy": "~0.4.1", - "grunt-exec": "~0.4.2" + "grunt-exec": "~0.4.2", + "jquery": "^2.1.3", + "mocha": "^2.1.0", + "utils": "*", + "webserver": "*" }, "license": "MIT", "engines": { diff --git a/test/src/require/test.js b/test/src/require/test.js new file mode 100644 index 0000000..4fde14b --- /dev/null +++ b/test/src/require/test.js @@ -0,0 +1,21 @@ +// Emulate the browser +global.window = { + navigator: { + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.45 Safari/537.36' + } +}; + +var browser = require('../jquery.browser.js'); + +var should = require('chai').should(); + +describe('jQuery browser', function() { + it('should have the correct properties for a Chrome browser on a Mac', function(done) { + browser.webkit.should.be.ok; + browser.mac.should.be.ok; + browser.desktop.should.be.ok; + + done(); + }); +}) + From c6f7f62521d212e0a2adb033050b30389cdc62f6 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 17:03:05 -0500 Subject: [PATCH 17/26] Fixed Gruntfile --- Gruntfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 2e6961b..d3406d8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -35,7 +35,7 @@ module.exports = function(grunt) { } }, exec: { - test: { + 'test-jquery': { command: "casperjs test test/test.js", stdout: true, stderr: true @@ -56,7 +56,7 @@ module.exports = function(grunt) { grunt.registerTask('default', ['jshint', 'uglify', 'copy']); - grunt.registerTask('test-jquery', ['default', 'exec']); + grunt.registerTask('test-jquery', ['default', 'exec:test-jquery']); grunt.registerTask('test-require', ['default', 'browserify', 'exec:test-require']); grunt.registerTask('test', ['test-jquery', 'test-require']); }; From 17953638a73d2cd741e2133af18aea3f242d3c00 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 17:03:33 -0500 Subject: [PATCH 18/26] Use specific package and remove unused one --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 7116c1d..abc22ab 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,7 @@ "grunt-exec": "~0.4.2", "jquery": "^2.1.3", "mocha": "^2.1.0", - "utils": "*", - "webserver": "*" + "webserver": "^1.1.2" }, "license": "MIT", "engines": { From 3a4f38ff0aeeeb65691f5c91b33f4acb811d2838 Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Thu, 25 Dec 2014 17:23:40 -0500 Subject: [PATCH 19/26] Updated test command on readme file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99c60ee..abbdc88 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Run `npm install` to install all dependencies including grunt and all tasks Once Casperjs and the grunt-cli npm package is installed you can execute all the tests by using: - grunt test + npm test ## Development From 2daa751d9cbfd18f0a984b7d77767a302d5e6ed5 Mon Sep 17 00:00:00 2001 From: Triangle717 Date: Fri, 16 Jan 2015 22:11:48 -0500 Subject: [PATCH 20/26] Convert `jQuery.uaMatch()` to traditional function I've chosen `jQBrowser()` as this is the jQuery.browser plugin, and because I cannot think of an uncommon but descriptive name for it, for I do not want to pollute the common namespace. --- dist/jquery.browser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index cb3db86..b6fb765 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -32,7 +32,7 @@ var matched, browser; - jQuery.uaMatch = function( ua ) { + window.jQBrowser = function( ua ) { ua = ua.toLowerCase(); var match = /(edge)\/([\w.]+)/.exec( ua ) || @@ -71,7 +71,7 @@ }; }; - matched = jQuery.uaMatch( window.navigator.userAgent ); + matched = jQBrowser( window.navigator.userAgent ); browser = {}; if ( matched.browser ) { From 9d1323bf7c464536e2ad21bd606bc5b7479b7cd8 Mon Sep 17 00:00:00 2001 From: Triangle717 Date: Fri, 16 Jan 2015 22:19:16 -0500 Subject: [PATCH 21/26] If an UA is not provided, default to browser UA. By optionally going jQuery free, this allows a new use-case: detecting a browser from an arbitrary UA. However, because the majority of cases will involve detecting the current browser, default to the UA if the function is called without passing parameters. When using jQuery, the UA is always provided. --- dist/jquery.browser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index b6fb765..38a4ec3 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -33,6 +33,10 @@ var matched, browser; window.jQBrowser = function( ua ) { + // If an UA is not provided, default to the current browser UA. + if ( ua === undefined ) { + ua = window.navigator.userAgent; + } ua = ua.toLowerCase(); var match = /(edge)\/([\w.]+)/.exec( ua ) || From 17658dfc91236f4d30232f365d456954b48f2d6b Mon Sep 17 00:00:00 2001 From: Triangle717 Date: Fri, 16 Jan 2015 22:41:44 -0500 Subject: [PATCH 22/26] Allow calling of jQBrowser if jQuery is not defined This required a tad bit of restructuring, mainly making the browser matching a part of the function and not outside of it. This also prevents the code from running twice if jQuery is loaded and the function is called. It may be that we want the function to be called on page load regardless. In that case, the changes required are trivial. --- dist/jquery.browser.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index 38a4ec3..b565f2c 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -17,7 +17,7 @@ (function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. - define(['jquery'], function ($) { + define(['jquery'], function($) { factory($); }); } else if (typeof module === 'object' && typeof module.exports === 'object') { @@ -25,7 +25,7 @@ module.exports = factory(require('jquery')); } else { // Browser globals - factory(jQuery); + factory(window.jQuery); } }(function(jQuery) { "use strict"; @@ -67,16 +67,13 @@ /(blackberry)/.exec( ua ) || []; - return { - browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "", - version: match[ 2 ] || match[ 4 ] || "0", - versionNumber: match[ 4 ] || match[ 2 ] || "0", - platform: platform_match[ 0 ] || "" - }; - }; - - matched = jQBrowser( window.navigator.userAgent ); - browser = {}; + var browser = {}, + matched = { + browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "", + version: match[ 2 ] || match[ 4 ] || "0", + versionNumber: match[ 4 ] || match[ 2 ] || "0", + platform: platform_match[ 0 ] || "" + }; if ( matched.browser ) { browser[ matched.browser ] = true; @@ -172,7 +169,13 @@ // Assign the name and platform variable browser.name = matched.browser; browser.platform = matched.platform; - - jQuery.browser = browser; return browser; + + }; + + // Only assign to jQuery.browser if jQuery is loaded + if ( jQuery ) { + var browser = jQBrowser( window.navigator.userAgent ); + jQuery.browser = browser; + } })); From 85deb50dc817eff38c224ed5db3e6b85b2dfc606 Mon Sep 17 00:00:00 2001 From: Triangle717 Date: Sat, 17 Jan 2015 12:05:45 -0500 Subject: [PATCH 23/26] Fix JSHint and indentation errors --- dist/jquery.browser.js | 153 ++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 78 deletions(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index b565f2c..3040936 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -12,7 +12,7 @@ * * Date: 12-12-2014 */ -/*global window: false */ +/*global window: false, jQBrowser */ (function (factory) { if (typeof define === 'function' && define.amd) { @@ -30,8 +30,6 @@ }(function(jQuery) { "use strict"; - var matched, browser; - window.jQBrowser = function( ua ) { // If an UA is not provided, default to the current browser UA. if ( ua === undefined ) { @@ -75,102 +73,101 @@ platform: platform_match[ 0 ] || "" }; - if ( matched.browser ) { - browser[ matched.browser ] = true; - browser.version = matched.version; - browser.versionNumber = parseInt(matched.versionNumber, 10); - } - - if ( matched.platform ) { - browser[ matched.platform ] = true; - } + if ( matched.browser ) { + browser[ matched.browser ] = true; + browser.version = matched.version; + browser.versionNumber = parseInt(matched.versionNumber, 10); + } - // These are all considered mobile platforms, meaning they run a mobile browser - if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone || - browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) { - browser.mobile = true; - } + if ( matched.platform ) { + browser[ matched.platform ] = true; + } - // These are all considered desktop platforms, meaning they run a desktop browser - if ( browser.cros || browser.mac || browser.linux || browser.win ) { - browser.desktop = true; - } + // These are all considered mobile platforms, meaning they run a mobile browser + if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone || + browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) { + browser.mobile = true; + } - // Chrome, Opera 15+ and Safari are webkit based browsers - if ( browser.chrome || browser.opr || browser.safari ) { - browser.webkit = true; - } + // These are all considered desktop platforms, meaning they run a desktop browser + if ( browser.cros || browser.mac || browser.linux || browser.win ) { + browser.desktop = true; + } - // IE11 has a new token so we will assign it msie to avoid breaking changes - // IE12 disguises itself as Chrome, but adds a new Edge token. - if ( browser.rv || browser.edge ) { - var ie = "msie"; + // Chrome, Opera 15+ and Safari are webkit based browsers + if ( browser.chrome || browser.opr || browser.safari ) { + browser.webkit = true; + } - matched.browser = ie; - browser[ie] = true; - } + // IE11 has a new token so we will assign it msie to avoid breaking changes + // IE12 disguises itself as Chrome, but adds a new Edge token. + if ( browser.rv || browser.edge ) { + var ie = "msie"; - // Blackberry browsers are marked as Safari on BlackBerry - if ( browser.safari && browser.blackberry ) { - var blackberry = "blackberry"; + matched.browser = ie; + browser[ie] = true; + } - matched.browser = blackberry; - browser[blackberry] = true; - } + // Blackberry browsers are marked as Safari on BlackBerry + if ( browser.safari && browser.blackberry ) { + var blackberry = "blackberry"; - // Playbook browsers are marked as Safari on Playbook - if ( browser.safari && browser.playbook ) { - var playbook = "playbook"; + matched.browser = blackberry; + browser[blackberry] = true; + } - matched.browser = playbook; - browser[playbook] = true; - } + // Playbook browsers are marked as Safari on Playbook + if ( browser.safari && browser.playbook ) { + var playbook = "playbook"; - // BB10 is a newer OS version of BlackBerry - if ( browser.bb ) { - var bb = "blackberry"; + matched.browser = playbook; + browser[playbook] = true; + } - matched.browser = bb; - browser[bb] = true; - } + // BB10 is a newer OS version of BlackBerry + if ( browser.bb ) { + var bb = "blackberry"; - // Opera 15+ are identified as opr - if ( browser.opr ) { - var opera = "opera"; + matched.browser = bb; + browser[bb] = true; + } - matched.browser = opera; - browser[opera] = true; - } + // Opera 15+ are identified as opr + if ( browser.opr ) { + var opera = "opera"; - // Stock Android browsers are marked as Safari on Android. - if ( browser.safari && browser.android ) { - var android = "android"; + matched.browser = opera; + browser[opera] = true; + } - matched.browser = android; - browser[android] = true; - } + // Stock Android browsers are marked as Safari on Android. + if ( browser.safari && browser.android ) { + var android = "android"; - // Kindle browsers are marked as Safari on Kindle - if ( browser.safari && browser.kindle ) { - var kindle = "kindle"; + matched.browser = android; + browser[android] = true; + } - matched.browser = kindle; - browser[kindle] = true; - } + // Kindle browsers are marked as Safari on Kindle + if ( browser.safari && browser.kindle ) { + var kindle = "kindle"; - // Kindle Silk browsers are marked as Safari on Kindle - if ( browser.safari && browser.silk ) { - var silk = "silk"; + matched.browser = kindle; + browser[kindle] = true; + } - matched.browser = silk; - browser[silk] = true; - } + // Kindle Silk browsers are marked as Safari on Kindle + if ( browser.safari && browser.silk ) { + var silk = "silk"; - // Assign the name and platform variable - browser.name = matched.browser; - browser.platform = matched.platform; - return browser; + matched.browser = silk; + browser[silk] = true; + } + // Assign the name and platform variable + browser.name = matched.browser; + browser.platform = matched.platform; + return browser; }; // Only assign to jQuery.browser if jQuery is loaded From fa811c883101f974f32affc0914c7c66b70e1ce3 Mon Sep 17 00:00:00 2001 From: Triangle717 Date: Tue, 20 Jan 2015 21:03:17 -0500 Subject: [PATCH 24/26] Auto-run function on page load, add the `uaMatch` function to the returned object for use if desired --- Gruntfile.js | 2 +- dist/jquery.browser.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index d3406d8..95dc931 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,7 +29,7 @@ module.exports = function(grunt) { } }, copy: { - main:{ + main: { src: "dist/<%= pkg.name %>.js", dest: "test/src/<%= pkg.name %>.js" } diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index 3040936..078dbd0 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -12,7 +12,7 @@ * * Date: 12-12-2014 */ -/*global window: false, jQBrowser */ +/*global window: false */ (function (factory) { if (typeof define === 'function' && define.amd) { @@ -30,7 +30,7 @@ }(function(jQuery) { "use strict"; - window.jQBrowser = function( ua ) { + function uaMatch( ua ) { // If an UA is not provided, default to the current browser UA. if ( ua === undefined ) { ua = window.navigator.userAgent; @@ -168,11 +168,15 @@ browser.name = matched.browser; browser.platform = matched.platform; return browser; - }; + } + + // Run the matching process, also assign the function to the returned object + // for manual, jQuery-free use if desired + window.jQBrowser = uaMatch( window.navigator.userAgent ); + window.jQBrowser.uaMatch = uaMatch; // Only assign to jQuery.browser if jQuery is loaded if ( jQuery ) { - var browser = jQBrowser( window.navigator.userAgent ); - jQuery.browser = browser; + jQuery.browser = window.jQBrowser; } })); From 63b620e30a384c624690e48334a2a745266e946c Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Tue, 20 Jan 2015 18:45:56 -0800 Subject: [PATCH 25/26] Always return browser to be able to require the module Added 'require' to the require test so you can differentiate with other tests --- dist/jquery.browser.js | 2 ++ dist/jquery.browser.min.js | 6 +++--- test/src/require/test.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js index 078dbd0..9bd4648 100644 --- a/dist/jquery.browser.js +++ b/dist/jquery.browser.js @@ -179,4 +179,6 @@ if ( jQuery ) { jQuery.browser = window.jQBrowser; } + + return window.jQBrowser; })); diff --git a/dist/jquery.browser.min.js b/dist/jquery.browser.min.js index adbfd0a..55f8cf5 100644 --- a/dist/jquery.browser.min.js +++ b/dist/jquery.browser.min.js @@ -5,10 +5,10 @@ * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors * http://jquery.org/license * - * Modifications Copyright 2014 Gabriel Cebrian + * Modifications Copyright 2015 Gabriel Cebrian * https://github.com/gabceb * * Released under the MIT license * - * Date: 25-12-2014 - */!function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){a(b)}):"object"==typeof module&&"object"==typeof module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){"use strict";var b,c;if(a.uaMatch=function(a){a=a.toLowerCase();var b=/(edge)\/([\w.]+)/.exec(a)||/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(ipod)/.exec(a)||/(iphone)/.exec(a)||/(kindle)/.exec(a)||/(silk)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||/(cros)/.exec(a)||/(playbook)/.exec(a)||/(bb)/.exec(a)||/(blackberry)/.exec(a)||[];return{browser:b[5]||b[3]||b[1]||"",version:b[2]||b[4]||"0",versionNumber:b[4]||b[2]||"0",platform:c[0]||""}},b=a.uaMatch(window.navigator.userAgent),c={},b.browser&&(c[b.browser]=!0,c.version=b.version,c.versionNumber=parseInt(b.versionNumber,10)),b.platform&&(c[b.platform]=!0),(c.android||c.bb||c.blackberry||c.ipad||c.iphone||c.ipod||c.kindle||c.playbook||c.silk||c["windows phone"])&&(c.mobile=!0),(c.cros||c.mac||c.linux||c.win)&&(c.desktop=!0),(c.chrome||c.opr||c.safari)&&(c.webkit=!0),c.rv||c.edge){var d="msie";b.browser=d,c[d]=!0}if(c.safari&&c.blackberry){var e="blackberry";b.browser=e,c[e]=!0}if(c.safari&&c.playbook){var f="playbook";b.browser=f,c[f]=!0}if(c.bb){var g="blackberry";b.browser=g,c[g]=!0}if(c.opr){var h="opera";b.browser=h,c[h]=!0}if(c.safari&&c.android){var i="android";b.browser=i,c[i]=!0}if(c.safari&&c.kindle){var j="kindle";b.browser=j,c[j]=!0}if(c.safari&&c.silk){var k="silk";b.browser=k,c[k]=!0}return c.name=b.browser,c.platform=b.platform,a.browser=c,c}); \ No newline at end of file + * Date: 20-01-2015 + */!function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){a(b)}):"object"==typeof module&&"object"==typeof module.exports?module.exports=a(require("jquery")):a(window.jQuery)}(function(a){"use strict";function b(a){void 0===a&&(a=window.navigator.userAgent),a=a.toLowerCase();var b=/(edge)\/([\w.]+)/.exec(a)||/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(ipod)/.exec(a)||/(iphone)/.exec(a)||/(kindle)/.exec(a)||/(silk)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||/(cros)/.exec(a)||/(playbook)/.exec(a)||/(bb)/.exec(a)||/(blackberry)/.exec(a)||[],d={},e={browser:b[5]||b[3]||b[1]||"",version:b[2]||b[4]||"0",versionNumber:b[4]||b[2]||"0",platform:c[0]||""};if(e.browser&&(d[e.browser]=!0,d.version=e.version,d.versionNumber=parseInt(e.versionNumber,10)),e.platform&&(d[e.platform]=!0),(d.android||d.bb||d.blackberry||d.ipad||d.iphone||d.ipod||d.kindle||d.playbook||d.silk||d["windows phone"])&&(d.mobile=!0),(d.cros||d.mac||d.linux||d.win)&&(d.desktop=!0),(d.chrome||d.opr||d.safari)&&(d.webkit=!0),d.rv||d.edge){var f="msie";e.browser=f,d[f]=!0}if(d.safari&&d.blackberry){var g="blackberry";e.browser=g,d[g]=!0}if(d.safari&&d.playbook){var h="playbook";e.browser=h,d[h]=!0}if(d.bb){var i="blackberry";e.browser=i,d[i]=!0}if(d.opr){var j="opera";e.browser=j,d[j]=!0}if(d.safari&&d.android){var k="android";e.browser=k,d[k]=!0}if(d.safari&&d.kindle){var l="kindle";e.browser=l,d[l]=!0}if(d.safari&&d.silk){var m="silk";e.browser=m,d[m]=!0}return d.name=e.browser,d.platform=e.platform,d}return window.jQBrowser=b(window.navigator.userAgent),window.jQBrowser.uaMatch=b,a&&(a.browser=window.jQBrowser),window.jQBrowser}); \ No newline at end of file diff --git a/test/src/require/test.js b/test/src/require/test.js index 4fde14b..596b114 100644 --- a/test/src/require/test.js +++ b/test/src/require/test.js @@ -9,7 +9,7 @@ var browser = require('../jquery.browser.js'); var should = require('chai').should(); -describe('jQuery browser', function() { +describe('require jQuery browser', function() { it('should have the correct properties for a Chrome browser on a Mac', function(done) { browser.webkit.should.be.ok; browser.mac.should.be.ok; From 5c17c77d276fd7dcb36a551d5909aa14959f8cad Mon Sep 17 00:00:00 2001 From: Gabriel Cebrian Date: Tue, 20 Jan 2015 18:53:33 -0800 Subject: [PATCH 26/26] Added tests for new jQuery-less function and manual UA matching --- test/test.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/test.js b/test/test.js index 43b4232..122923b 100644 --- a/test/test.js +++ b/test/test.js @@ -827,3 +827,51 @@ casper.test.begin("when using BlackBerry PlayBook stock browser", 6, function(te casper.exit(); }); }); + +casper.test.begin("when using Chrome on Windows w/o jQuery", 7, function(test) { + casper.userAgent(ua.chrome.windows); + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return window.jQBrowser; + }); + + test.assert(browser.chrome, "Browser should be Chrome"); + test.assertEquals(browser.name, ua.chrome.name,"Browser name should be " + ua.chrome.name); + + test.assert(browser.webkit, "Browser should be WebKit based"); + test.assertEquals(browser.version, ua.chrome.version, "String version should be " + ua.chrome.version); + test.assertEquals(browser.versionNumber, ua.chrome.versionNumber, "Number version should be " + ua.chrome.versionNumber); + + test.assert(browser.desktop, "Browser platform should be desktop"); + test.assert(browser.win, "Platform should be Windows"); + + }).run(function(){ + test.done(); + }); +}); + +casper.test.begin("when trying to match a browser that is not the browser used by the user", 7, function(test) { + casper.userAgent(ua.chrome.mac); // Use the Mac Chrome browser + + casper.start(test_url).then(function(){ + + var browser = casper.evaluate(function(){ + return window.jQBrowser.uaMatch(ua.chrome.windows); // Match the Windows Chrome browser + }); + + test.assert(browser.chrome, "Browser should be Chrome"); + test.assertEquals(browser.name, ua.chrome.name,"Browser name should be " + ua.chrome.name); + + test.assert(browser.webkit, "Browser should be WebKit based"); + test.assertEquals(browser.version, ua.chrome.version, "String version should be " + ua.chrome.version); + test.assertEquals(browser.versionNumber, ua.chrome.versionNumber, "Number version should be " + ua.chrome.versionNumber); + + test.assert(browser.desktop, "Browser platform should be desktop"); + test.assert(browser.win, "Platform should be Windows"); + + }).run(function(){ + test.done(); + }); +});