mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Automatically create $.ua object if jQuery is present
This commit is contained in:
parent
d1120a4d5d
commit
0109c76858
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"title": "UA-Parser.JS",
|
"title": "UA-Parser.JS",
|
||||||
"name": "ua-parser-js",
|
"name": "ua-parser-js",
|
||||||
"version": "0.5.3",
|
"version": "0.5.11",
|
||||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"user agent",
|
"user-agent",
|
||||||
"parser",
|
"parser",
|
||||||
"browser",
|
"browser",
|
||||||
"engine",
|
"engine",
|
||||||
|
26
readme.md
26
readme.md
@ -11,7 +11,7 @@ Lightweight JavaScript-based User-Agent string parser
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string.
|
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string with relatively lightweight footprint (~7KB minified / ~3KB gzipped).
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -91,9 +91,31 @@ console.log(parser.getOS()) // {name: "RIM Tablet OS
|
|||||||
console.log(parser.getEngine().name); // "WebKit"
|
console.log(parser.getEngine().name); // "WebKit"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using jQuery
|
||||||
|
|
||||||
|
If you're using jQuery, `$.ua` object will be created automatically based on container's user-agent. To change different user-agent use `$.setUA(uastring)`. In case you need, `UAParser` is still present in global though.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// In browser with default user-agent: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0':
|
||||||
|
|
||||||
|
// Do some tests
|
||||||
|
console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
|
||||||
|
console.log($.ua.os); // {name: "Android", version: "2.3.4"}
|
||||||
|
console.log($.ua.os.name); // "Android"
|
||||||
|
|
||||||
|
// reset to custom user-agent
|
||||||
|
$.setUA('Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; Xoom Build/HWI69) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13');
|
||||||
|
|
||||||
|
// Test again
|
||||||
|
console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
|
||||||
|
console.log($.ua.engine.name); // "Webkit"
|
||||||
|
console.log($.ua.browser.version); // "4.0"
|
||||||
|
console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright © 2012 Faisalman <<fyzlman@gmail.com>>
|
Copyright © 2012-2013 Faisalman <<fyzlman@gmail.com>>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
31
ua-parser-js.jquery.json
Normal file
31
ua-parser-js.jquery.json
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"title": "UA-Parser.JS",
|
||||||
|
"name": "ua-parser-js",
|
||||||
|
"version": "0.5.11",
|
||||||
|
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||||
|
"keywords": [
|
||||||
|
"user-agent",
|
||||||
|
"parser",
|
||||||
|
"browser",
|
||||||
|
"engine",
|
||||||
|
"os",
|
||||||
|
"device"
|
||||||
|
],
|
||||||
|
"homepage": "https://faisalman.github.com/ua-parser-js",
|
||||||
|
"author": {
|
||||||
|
"name": "Faisal Salman",
|
||||||
|
"email": "fyzlman@gmail.com"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jquery": ">=1.5"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "MIT",
|
||||||
|
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bugs": "https://github.com/faisalman/ua-parser-js/issues",
|
||||||
|
"docs": "https://github.com/faisalman/ua-parser-js",
|
||||||
|
"download": "https://raw.github.com/faisalman/ua-parser-js/master/ua-parser.min.js"
|
||||||
|
}
|
13
ua-parser.js
13
ua-parser.js
@ -1,8 +1,8 @@
|
|||||||
// UA-Parser.JS v0.5.3
|
// UA-Parser.JS v0.5.11
|
||||||
// Lightweight JavaScript-based User-Agent string parser
|
// Lightweight JavaScript-based User-Agent string parser
|
||||||
// https://github.com/faisalman/ua-parser-js
|
// https://github.com/faisalman/ua-parser-js
|
||||||
//
|
//
|
||||||
// Copyright © 2012 Faisalman
|
// Copyright © 2012-2013 Faisalman
|
||||||
// Dual licensed under GPLv2 & MIT
|
// Dual licensed under GPLv2 & MIT
|
||||||
|
|
||||||
(function (global, undefined) {
|
(function (global, undefined) {
|
||||||
@ -419,6 +419,13 @@
|
|||||||
exports.UAParser = UAParser;
|
exports.UAParser = UAParser;
|
||||||
} else {
|
} else {
|
||||||
// browser env
|
// browser env
|
||||||
global['UAParser'] = UAParser;
|
global.UAParser = UAParser;
|
||||||
|
// jQuery specific
|
||||||
|
if (typeof global.jQuery !== UNDEF) {
|
||||||
|
global.jQuery.ua = new UAParser().getResult();
|
||||||
|
global.jQuery.setUA = function (uastring) {
|
||||||
|
global.jQuery.ua = new UAParser(uastring).getResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})(this);
|
})(this);
|
||||||
|
6
ua-parser.min.js
vendored
6
ua-parser.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user