Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['gruntfile.js', 'jquery.browser.js', 'test/test.js'],
files: ['Gruntfile.js', 'dist/jquery.browser.js', 'test/test.js'],

options: {
globals: {
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Include script *after* the jQuery library:

## Usage

Returns true if the current useragent is some version of Microsoft's Internet Explorer. Supports all IE versions including IE11
Returns true if the current useragent is some version of Microsoft's Internet Explorer. Supports all IE versions including IE 12.

$.browser.msie;

Expand Down Expand Up @@ -66,7 +66,7 @@ Reading the browser verion
$.browser.versionNumber // Returns 32 as a number
```

- Support for new useragent on IE11
- Support for new useragent on IE 11 and IE 12
- Support for WebKit based Opera browsers
- Added testing using PhantomJS and different browser user agents

Expand Down Expand Up @@ -94,6 +94,3 @@ Once Casperjs and the grunt-cli npm package is installed you can execute all the

- [Examples and original implementation](http://api.jquery.com/jQuery.browser/)
- [Original Gist used for the plugin](https://gist.github.com/adeelejaz/4714079)

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gabceb/jquery-browser-plugin/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

14 changes: 8 additions & 6 deletions dist/jquery.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], function ($) {
factory($, root);
factory($, root);
});
} else {
// Browser globals
Expand All @@ -34,7 +34,8 @@
var match = /(edge)\/([\w.]+)/.exec( ua ) ||
/(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(version)[ \/]([\w.]+).*(safari)[ \/]([\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 ) ||
Expand All @@ -49,12 +50,13 @@
/(win)/.exec( ua ) ||
/(mac)/.exec( ua ) ||
/(linux)/.exec( ua ) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was left over from when I added ChromeOS support. I did not know you already converted the UA to lowercase.

/(cros)/i.exec( ua ) ||
/(cros)/.exec( ua ) ||
[];

return {
browser: match[ 3 ] || match[ 1 ] || "",
version: 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 ] || ""
};
};
Expand All @@ -65,7 +67,7 @@
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
browser.versionNumber = parseInt(matched.version);
browser.versionNumber = parseInt(matched.versionNumber, 10);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the error JSHint caught.

}

if ( matched.platform ) {
Expand Down
27 changes: 14 additions & 13 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ casper.test.begin("when using IE10", 7, function(test) {
});
});

casper.test.begin("when using IE11", 7, function(test) {
casper.userAgent(ua.ie.windows.v_11);

casper.test.begin("when using IE10 on a Windows Phone", 7, function(test) {
casper.userAgent(ua.ie.win_phone.v_10);

casper.start(test_url).then(function(){

Expand All @@ -410,21 +411,21 @@ casper.test.begin("when using IE11", 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.assertEquals(browser.version, "10.0", "Version should be 10.0");
test.assertEquals(browser.versionNumber, 10, "Version should be 10");

test.assert(browser.desktop, "Browser platform should be desktop");
test.assert(browser.win, "Platform should be Windows");
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();
test.done();
});
});

casper.test.begin("when using IE10 on a Windows Phone", 7, function(test) {
casper.userAgent(ua.ie.win_phone.v_10);
casper.test.begin("when using IE11", 7, function(test) {
casper.userAgent(ua.ie.windows.v_11);

casper.start(test_url).then(function(){

Expand All @@ -435,11 +436,11 @@ casper.test.begin("when using IE10 on a Windows Phone", 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, "10.0", "Version should be 10.0");
test.assertEquals(browser.versionNumber, 10, "Version should be 10");
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.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");

Expand Down