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
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# EditorConfig.org
root = true

[*]
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
88 changes: 44 additions & 44 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['gruntfile.js', 'jquery.browser.js'],
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'dist/jquery.browser.js', 'test/test.js'],

options: {
globals: {
jQuery: true,
console: true,
module: true
}
}
},
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 */'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js'
}
}
},
copy: {
main:{
src: "dist/<%= pkg.name %>.js",
dest: "test/src/<%= pkg.name %>.js"
}
},
exec: {
test: {
command: "casperjs test test/test.js",
stdout: true,
stderr: true
}
}
});
options: {
globals: {
jQuery: true,
console: true,
module: true
}
}
},
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 */'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js'
}
}
},
copy: {
main:{
src: "dist/<%= pkg.name %>.js",
dest: "test/src/<%= pkg.name %>.js"
}
},
exec: {
test: {
command: "casperjs test test/test.js",
stdout: true,
stderr: true
}
}
});

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-exec');

grunt.registerTask('default', ['jshint', 'uglify', 'copy']);
grunt.registerTask('test', ['default', 'exec']);
};
grunt.registerTask('default', ['jshint', 'uglify', 'copy']);
grunt.registerTask('test', ['default', 'exec']);
};
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")

111 changes: 61 additions & 50 deletions dist/jquery.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,100 +13,111 @@
* Date: 2013-07-29T17:23:27-07:00
*/

(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;

jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();

var match = /(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(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)/i.exec( ua ) ||
[];

return {
browser: match[ 3 ] || match[ 1 ] || "",
version: match[ 2 ] || "0",
platform: platform_match[ 0 ] || ""
};
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 ) ||
[];

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.version);
browser[ matched.browser ] = true;
browser.version = matched.version;
browser.versionNumber = parseInt(matched.versionNumber, 10);
}

if ( matched.platform ) {
browser[ matched.platform ] = true;
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;
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;
browser.desktop = true;
}

// Chrome, Opera 15+ and Safari are webkit based browsers
if ( browser.chrome || browser.opr || browser.safari ) {
browser.webkit = true;
browser.webkit = true;
}

// IE11 has a new token so we will assign it msie to avoid breaking changes
if ( browser.rv )
{
var ie = "msie";
// 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;
matched.browser = ie;
browser[ie] = true;
}

// Opera 15+ are identified as opr
if ( browser.opr )
{
var opera = "opera";
if ( browser.opr ) {
var opera = "opera";

matched.browser = opera;
browser[opera] = true;
matched.browser = opera;
browser[opera] = true;
}

// Stock Android browsers are marked as Safari on Android.
if ( browser.safari && browser.android )
{
var android = "android";
if ( browser.safari && browser.android ) {
var android = "android";

matched.browser = android;
browser[android] = true;
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 );
return browser;
}));
Loading