mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Revise jQuery plugin API
This commit is contained in:
parent
217cef226a
commit
3eb1c1c352
@ -1,7 +1,7 @@
|
||||
{
|
||||
"title": "UA-Parser.JS",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.5.12",
|
||||
"version": "0.5.13",
|
||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
|
@ -104,7 +104,7 @@ 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.
|
||||
If you're using jQuery, `$.ua` object will be created automatically based on container's user-agent. Use `$.ua.get()` / `$.ua.set(uastring)` to get/set user-agent. In case you need, `UAParser` constructor 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':
|
||||
@ -113,9 +113,10 @@ If you're using jQuery, `$.ua` object will be created automatically based on con
|
||||
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"
|
||||
console.log($.ua.get()); // "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0"
|
||||
|
||||
// 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');
|
||||
$.ua.set('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"}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"title": "UA-Parser.JS",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.5.12",
|
||||
"version": "0.5.13",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user-agent",
|
||||
|
18
ua-parser.js
18
ua-parser.js
@ -1,4 +1,4 @@
|
||||
// UA-Parser.JS v0.5.12
|
||||
// UA-Parser.JS v0.5.13
|
||||
// Lightweight JavaScript-based User-Agent string parser
|
||||
// https://github.com/faisalman/ua-parser-js
|
||||
//
|
||||
@ -427,10 +427,18 @@
|
||||
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();
|
||||
}
|
||||
var parser = new UAParser();
|
||||
global.jQuery.ua = parser.getResult();
|
||||
global.jQuery.ua.get = function() {
|
||||
return parser.getUA();
|
||||
};
|
||||
global.jQuery.ua.set = function(uastring) {
|
||||
parser.setUA(uastring);
|
||||
var result = parser.getResult();
|
||||
for (var prop in result) {
|
||||
global.jQuery.ua[prop] = result[prop];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
})(this);
|
||||
|
4
ua-parser.min.js
vendored
4
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