Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
21ae8c5
Update Browser Detection to Support iPod, Kindle and BlackBerry devices.
bhamodi Nov 23, 2014
4bb46ae
Restore and improve ordering of `match` and `platform_match`, fix inc…
Dec 12, 2014
751896d
Merge pull request #52 from gabceb/bhamodi-new-browsers
Dec 12, 2014
7ed56e7
Update version to v0.0.7
Dec 12, 2014
c41db05
Merge pull request #53 from gabceb/release-007
gabceb Dec 15, 2014
551e464
Support for node/browserify
mwiencek Dec 24, 2014
4ad34a3
Ignore JSLint "window is not defined" warning
mwiencek Dec 24, 2014
890ce60
Move JSLint hint to top of file
mwiencek Dec 24, 2014
e4a01fd
Remove newline
mwiencek Dec 24, 2014
a6a2576
Merge pull request #55 from mwiencek/master
Dec 24, 2014
28e2f4d
Add travis testing to project
gabceb Dec 25, 2014
2866804
Fixed travis config filename
gabceb Dec 25, 2014
4936b77
Fixed Node version on travis file
gabceb Dec 25, 2014
0780928
Added build status to README file
gabceb Dec 25, 2014
471b236
Removed test src file so we can gitignore it
gabceb Dec 25, 2014
269a616
Ignore the copied test src file
gabceb Dec 25, 2014
bc41bf8
Updated min file
gabceb Dec 25, 2014
ece5dce
Make gitignore more specific
gabceb Dec 25, 2014
3f6c1da
Added simple RequireJs testing using browserify
gabceb Dec 25, 2014
c6f7f62
Fixed Gruntfile
gabceb Dec 25, 2014
1795363
Use specific package and remove unused one
gabceb Dec 25, 2014
3a4f38f
Updated test command on readme file
gabceb Dec 25, 2014
2daa751
Convert `jQuery.uaMatch()` to traditional function
Jan 17, 2015
9d1323b
If an UA is not provided, default to browser UA.
Jan 17, 2015
17658df
Allow calling of jQBrowser if jQuery is not defined
Jan 17, 2015
85deb50
Fix JSHint and indentation errors
Jan 17, 2015
fa811c8
Auto-run function on page load,
Jan 21, 2015
63b620e
Always return browser to be able to require the module
gabceb Jan 21, 2015
5c17c77
Added tests for new jQuery-less function and manual UA matching
gabceb Jan 21, 2015
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ lib-cov
*.pid
*.gz

test/src/jquery.browser.js
test/test-require.js

pids
logs
results

npm-debug.log
node_modules

.DS_STORE
.DS_STORE
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.10"
before_install: npm install -g grunt-cli; npm install -g casperjs
install: npm install
21 changes: 18 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -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'],

Expand All @@ -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
}
}
});
Expand All @@ -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']);
};
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,17 +30,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
```
Expand Down Expand Up @@ -83,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

Expand Down
207 changes: 134 additions & 73 deletions dist/jquery.browser.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
/*!
* 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
*/
/*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);
define(['jquery'], function($) {
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 ) ||
Expand All @@ -44,80 +50,135 @@
[];

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.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
// 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;
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
// 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;
return browser;
}

// 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;
}));
8 changes: 4 additions & 4 deletions dist/jquery.browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading