diff --git a/.gitignore b/.gitignore
index 1d6f27b..b76bbf2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,9 @@ lib-cov
*.pid
*.gz
+test/src/jquery.browser.js
+test/test-require.js
+
pids
logs
results
@@ -14,4 +17,4 @@ results
npm-debug.log
node_modules
-.DS_STORE
\ No newline at end of file
+.DS_STORE
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..0a7a84e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,6 @@
+sudo: false
+language: node_js
+node_js:
+ - "0.10"
+before_install: npm install -g grunt-cli; npm install -g casperjs
+install: npm install
\ No newline at end of file
diff --git a/Gruntfile.js b/Gruntfile.js
index bf401eb..4d3c2fb 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'],
@@ -14,7 +20,7 @@ module.exports = function(grunt) {
},
uglify: {
options: {
- banner: '/*!\n * jQuery Browser Plugin <%= pkg.version %>\n * https://github.com/gabceb/jquery-browser-plugin\n *\n * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors\n * http://jquery.org/license\n *\n * Modifications Copyright <%= grunt.template.today("yyyy") %> Gabriel Cebrian\n * https://github.com/gabceb\n *\n * Released under the MIT license\n *\n * Date: <%= grunt.template.today("dd-mm-yyyy")%>\n */'
+ banner: '/*!\n * jQuery Browser Plugin <%= pkg.version %>\n * https://github.com/gabceb/jquery-browser-plugin\n *\n * Original jquery-browser code Copyright 2005, 2015 jQuery Foundation, Inc. and other contributors\n * http://jquery.org/license\n *\n * Modifications Copyright <%= grunt.template.today("yyyy") %> Gabriel Cebrian\n * https://github.com/gabceb\n *\n * Released under the MIT license\n *\n * Date: <%= grunt.template.today("dd-mm-yyyy")%>\n */'
},
dist: {
files: {
@@ -23,16 +29,21 @@ module.exports = function(grunt) {
}
},
copy: {
- main:{
+ main: {
src: "dist/<%= pkg.name %>.js",
dest: "test/src/<%= pkg.name %>.js"
}
},
exec: {
- test: {
+ 'test-jquery': {
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:test-jquery']);
+ grunt.registerTask('test-require', ['default', 'browserify', 'exec:test-require']);
+ grunt.registerTask('test', ['test-jquery', 'test-require']);
};
diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt
index d04f9a7..c6ae678 100644
--- a/MIT-LICENSE.txt
+++ b/MIT-LICENSE.txt
@@ -1,5 +1,5 @@
-Copyright 2013 jQuery Foundation and other contributors, http://jquery.com/
-Modifications Copyright 2013 Gabriel Cebrian, https://www.github.com/gabceb
+Copyright 2015 jQuery Foundation and other contributors, http://jquery.com/
+Modifications Copyright 2015 Gabriel Cebrian, https://www.github.com/gabceb
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/README.md b/README.md
index 2a48746..11c9f8e 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,21 @@
[](https://nodei.co/npm/jquery.browser/)
-A jQuery plugin for browser detection. jQuery removed support for browser detection on 1.9.1 so it was abstracted into a jQuery plugin
+[](https://travis-ci.org/gabceb/jquery-browser-plugin)
+
+A jQuery plugin for browser detection. jQuery v1.9.1 dropped support for browser detection, and this project aims to keep the detection up-to-date.
## Installation
Include script *after* the jQuery library:
+```html
+
+```
-
+Alternatively, you can use the plugin without jQuery by using the global object `jQBrowser` instead of `$.browser`.
## Usage
-Returns true if the current useragent is some version of Microsoft's Internet Explorer. Supports all IE versions including IE 12.
+Returns true if the current useragent is some version of Microsoft's Internet Explorer. Supports all IE versions including IE 11.
$.browser.msie;
@@ -22,23 +27,38 @@ Returns true if the current useragent is some version of Firefox
$.browser.mozilla;
-Reading the browser verion
-
+Reading the browser version
+
$.browser.version
+You can also examine arbitrary useragents
+
+ jQBrowser.uaMatch();
+
## 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.msedge
+ $.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
```
@@ -66,7 +86,8 @@ Reading the browser verion
$.browser.versionNumber // Returns 32 as a number
```
-- Support for new useragent on IE 11 and IE 12
+- Support for new useragent on IE 11
+- Support for Microsoft Edge
- Support for WebKit based Opera browsers
- Added testing using PhantomJS and different browser user agents
@@ -83,7 +104,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
diff --git a/bower.json b/bower.json
index 686c626..6955a43 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "jquery.browser",
- "version": "0.0.6",
+ "version": "0.1.0",
"homepage": "https://github.com/gabceb/jquery-browser-plugin",
"authors": ["Gabriel Cebrian ", "jQuery Team "],
"description": "A jQuery plugin for browser detection.",
diff --git a/browser.jquery.json b/browser.jquery.json
index 4e4c14c..79868a6 100644
--- a/browser.jquery.json
+++ b/browser.jquery.json
@@ -9,7 +9,7 @@
"html5",
"support"
],
- "version": "0.0.6",
+ "version": "0.1.0",
"author": {
"name": "Gabriel Cebrian. Initial implementation by the jQuery Team",
"url": "https://github.com/gabceb/jquery-browser-plugin/wiki/Authors"
diff --git a/dist/jquery.browser.js b/dist/jquery.browser.js
index a56e816..223eca6 100644
--- a/dist/jquery.browser.js
+++ b/dist/jquery.browser.js
@@ -1,39 +1,46 @@
/*!
- * jQuery Browser Plugin v0.0.6
+ * jQuery Browser Plugin 0.1.0
* https://github.com/gabceb/jquery-browser-plugin
*
- * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors
+ * Original jquery-browser code Copyright 2005, 2015 jQuery Foundation, Inc. and other contributors
* http://jquery.org/license
*
- * Modifications Copyright 2013 Gabriel Cebrian
+ * Modifications Copyright 2015 Gabriel Cebrian
* https://github.com/gabceb
*
* Released under the MIT license
*
- * Date: 2013-07-29T17:23:27-07:00
+ * Date: 05-07-2015
*/
+/*global window: false */
-(function (root, factory) {
+(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], function ($) {
- factory($, root);
+ return 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(window.jQuery);
}
-}(this, function(jQuery, window) {
+}(function(jQuery) {
"use strict";
- var matched, browser;
-
- jQuery.uaMatch = function( ua ) {
+ function uaMatch( 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 ) ||
/(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
+ /(iemobile)[\/]([\w.]+)/.exec( ua ) ||
/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
@@ -44,80 +51,143 @@
[];
var platform_match = /(ipad)/.exec( ua ) ||
+ /(ipod)/.exec( ua ) ||
+ /(windows phone)/.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.ipad || browser.iphone || 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;
+ 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;
+ 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
+ if ( browser.rv || browser.iemobile) {
+ var ie = "msie";
+
+ matched.browser = ie;
+ browser[ie] = true;
+ }
+
+ // Edge is officially known as Microsoft Edge, so rewrite the key to match
+ if ( browser.edge ) {
+ delete browser.edge;
+ var msedge = "msedge";
+
+ matched.browser = msedge;
+ browser[msedge] = 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;
+ return browser;
}
- // 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;
- }
-
- // Opera 15+ are identified as opr
- if ( browser.opr ) {
- var opera = "opera";
+ // 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;
- matched.browser = opera;
- browser[opera] = true;
+ // Only assign to jQuery.browser if jQuery is loaded
+ if ( jQuery ) {
+ jQuery.browser = window.jQBrowser;
}
- // Stock Android browsers are marked as Safari on Android.
- if ( browser.safari && browser.android ) {
- var android = "android";
-
- matched.browser = android;
- browser[android] = true;
- }
-
- // Assign the name and platform variable
- browser.name = matched.browser;
- browser.platform = matched.platform;
-
- jQuery.browser = browser;
- return browser;
+ return window.jQBrowser;
}));
diff --git a/dist/jquery.browser.min.js b/dist/jquery.browser.min.js
index d5f6aa3..491da7c 100644
--- a/dist/jquery.browser.min.js
+++ b/dist/jquery.browser.min.js
@@ -1,14 +1,14 @@
/*!
- * jQuery Browser Plugin 0.0.6
+ * jQuery Browser Plugin 0.1.0
* https://github.com/gabceb/jquery-browser-plugin
*
- * Original jquery-browser code Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors
+ * Original jquery-browser code Copyright 2005, 2015 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: 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: 23-11-2015
+ */!function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){return 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)||/(iemobile)[\/]([\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)||/(windows phone)/.exec(a)||/(iphone)/.exec(a)||/(kindle)/.exec(a)||/(silk)/.exec(a)||/(android)/.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.iemobile){var f="msie";e.browser=f,d[f]=!0}if(d.edge){delete d.edge;var g="msedge";e.browser=g,d[g]=!0}if(d.safari&&d.blackberry){var h="blackberry";e.browser=h,d[h]=!0}if(d.safari&&d.playbook){var i="playbook";e.browser=i,d[i]=!0}if(d.bb){var j="blackberry";e.browser=j,d[j]=!0}if(d.opr){var k="opera";e.browser=k,d[k]=!0}if(d.safari&&d.android){var l="android";e.browser=l,d[l]=!0}if(d.safari&&d.kindle){var m="kindle";e.browser=m,d[m]=!0}if(d.safari&&d.silk){var n="silk";e.browser=n,d[n]=!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/package.json b/package.json
index 4312f40..421f8d5 100644
--- a/package.json
+++ b/package.json
@@ -1,21 +1,27 @@
{
"name": "jquery.browser",
- "version": "0.0.6",
+ "version": "0.1.0",
"authors": [
"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",
"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",
+ "webserver": "^1.1.2"
},
"license": "MIT",
"engines": {
diff --git a/test/src/jquery.browser.js b/test/src/jquery.browser.js
deleted file mode 100644
index ceea0e4..0000000
--- a/test/src/jquery.browser.js
+++ /dev/null
@@ -1,113 +0,0 @@
-/*!
- * jQuery Browser Plugin v0.0.6
- * 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
- * https://github.com/gabceb
- *
- * Released under the MIT license
- *
- * Date: 2013-07-29T17:23:27-07:00
- */
-
-(function( jQuery, window, undefined ) {
- "use strict";
-
- var matched, browser;
-
- 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 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 ) ||
- [];
-
- return {
- browser: match[ 3 ] || match[ 1 ] || "",
- version: match[ 4 ] || match[ 2 ],
- versionNumber: 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);
- }
-
- if ( matched.platform ) {
- browser[ matched.platform ] = true;
- }
-
- // These are all considered mobile platforms, meaning they run a mobile browser
- if ( browser.android || browser.ipad || browser.iphone || 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
- if ( browser.rv )
- {
- var ie = "msie";
-
- matched.browser = ie;
- browser[ie] = 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;
- }
-
- // Assign the name and platform variable
- browser.name = matched.browser;
- browser.platform = matched.platform;
-
-
- jQuery.browser = browser;
-})( jQuery, window );
diff --git a/test/src/require/test.js b/test/src/require/test.js
new file mode 100644
index 0000000..596b114
--- /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('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;
+ browser.desktop.should.be.ok;
+
+ done();
+ });
+})
+
diff --git a/test/test.js b/test/test.js
index 82e3937..35db474 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"
@@ -39,17 +40,27 @@ var ua = {
name: "mozilla"
},
ie: {
- windows : {
+ windows: {
v_9: "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)",
v_10: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
- v_11: "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
- v_12: "Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 Edge/12.0"
+ v_11: "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"
},
- win_phone : {
- v_10: "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 1020)"
+ win_phone: {
+ v_10: "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 1020)",
+ v_11: "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537"
},
name: "msie"
},
+ msedge: {
+ windows: {
+ v_12: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.0",
+ v_13: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586"
+ },
+ win_phone: {
+ v_13: "Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; NOKIA; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/13.10586"
+ },
+ name: "msedge"
+ },
opera: {
v_15: {
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.20 Safari/537.36 OPR/15.0.1147.18",
@@ -78,6 +89,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 +399,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);
@@ -398,7 +473,6 @@ casper.test.begin("when using IE10", 7, function(test) {
});
});
-
casper.test.begin("when using IE10 on a Windows Phone", 7, function(test) {
casper.userAgent(ua.ie.win_phone.v_10);
@@ -449,8 +523,8 @@ casper.test.begin("when using IE11", 7, function(test) {
});
});
-casper.test.begin("when using IE12", 7, function(test) {
- casper.userAgent(ua.ie.windows.v_12);
+casper.test.begin("when using IE11 on a Windows Phone", 7, function(test) {
+ casper.userAgent(ua.ie.win_phone.v_11);
casper.start(test_url).then(function(){
@@ -461,6 +535,31 @@ casper.test.begin("when using IE12", 7, function(test) {
test.assert(browser.msie, "Browser should be IE");
test.assertEquals(browser.name, ua.ie.name,"Browser name should be " + ua.ie.name);
+ test.assertEquals(browser.version, "11.0", "Version should be 11.0");
+ test.assertEquals(browser.versionNumber, 11, "Version should be 11");
+
+ test.assert(browser.mobile, "Browser platform should be mobile");
+ test.assert(browser["windows phone"], "Platform should be Windows Phone");
+
+ test.assertFalsy(browser.webkit, "Browser should NOT be WebKit based");
+
+ }).run(function(){
+ test.done();
+ });
+});
+
+casper.test.begin("when using Microsoft Edge 12", 7, function(test) {
+ casper.userAgent(ua.msedge.windows.v_12);
+
+ casper.start(test_url).then(function(){
+
+ var browser = casper.evaluate(function(){
+ return $.browser;
+ });
+
+ test.assert(browser.msedge, "Browser should be MS Edge");
+ test.assertEquals(browser.name, ua.msedge.name,"Browser name should be " + ua.msedge.name);
+
test.assertEquals(browser.version, "12.0", "Version should be 12.0");
test.assertEquals(browser.versionNumber, 12, "Version should be 12");
@@ -474,6 +573,57 @@ casper.test.begin("when using IE12", 7, function(test) {
});
});
+casper.test.begin("when using Microsoft Edge 13", 7, function(test) {
+ casper.userAgent(ua.msedge.windows.v_13);
+
+ casper.start(test_url).then(function(){
+
+ var browser = casper.evaluate(function(){
+ return $.browser;
+ });
+
+ test.assert(browser.msedge, "Browser should be MS Edge");
+ test.assertEquals(browser.name, ua.msedge.name,"Browser name should be " + ua.msedge.name);
+
+ test.assertEquals(browser.version, "13.10586", "Version should be 13.10586");
+ test.assertEquals(browser.versionNumber, 13, "Version should be 13");
+
+ test.assert(browser.desktop, "Browser platform should be desktop");
+ test.assert(browser.win, "Platform should be Windows");
+
+ test.assertFalsy(browser.webkit, "Browser should NOT be WebKit based");
+
+ }).run(function(){
+ test.done();
+ });
+});
+
+casper.test.begin("when using Microsoft Edge v13 on a Windows Phone", 7, function(test) {
+ casper.userAgent(ua.msedge.win_phone.v_13);
+
+ casper.start(test_url).then(function(){
+
+ var browser = casper.evaluate(function(){
+ return $.browser;
+ });
+
+ test.assert(browser.msedge, "Browser should be MS Edge");
+ test.assertEquals(browser.name, ua.msedge.name,"Browser name should be " + ua.msedge.name);
+
+ test.assertEquals(browser.version, "13.10586", "Version should be 13.10586");
+ test.assertEquals(browser.versionNumber, 13, "Version should be 13");
+
+ test.assert(browser.mobile, "Browser platform should be mobile");
+ test.assert(browser["windows phone"], "Platform should be Windows Phone");
+
+ test.assertFalsy(browser.webkit, "Browser should NOT be WebKit based");
+
+ }).run(function(){
+ test.done();
+ });
+});
+
+
casper.test.begin("when using Opera 15+ on Windows", 7, function(test) {
casper.userAgent(ua.opera.v_15.windows);
@@ -642,8 +792,171 @@ 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();
});
});
+
+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();
+ });
+});