mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Merge pull request #81 from duzun/patch-2
Keep global scope clean with AMD. Always check for jQuery global.
This commit is contained in:
commit
4d3656bb9c
@ -739,30 +739,37 @@
|
||||
}
|
||||
exports.UAParser = UAParser;
|
||||
} else {
|
||||
// browser env
|
||||
window.UAParser = UAParser;
|
||||
// requirejs env (optional)
|
||||
// requirejs env
|
||||
if (typeof(define) === FUNC_TYPE && define.amd) {
|
||||
define(function () {
|
||||
return UAParser;
|
||||
});
|
||||
}
|
||||
// jQuery/Zepto specific (optional)
|
||||
var $ = window.jQuery || window.Zepto;
|
||||
if (typeof($) !== UNDEF_TYPE) {
|
||||
var parser = new UAParser();
|
||||
$.ua = parser.getResult();
|
||||
$.ua.get = function() {
|
||||
return parser.getUA();
|
||||
};
|
||||
$.ua.set = function (uastring) {
|
||||
parser.setUA(uastring);
|
||||
var result = parser.getResult();
|
||||
for (var prop in result) {
|
||||
$.ua[prop] = result[prop];
|
||||
}
|
||||
};
|
||||
else {
|
||||
// browser env
|
||||
window.UAParser = UAParser;
|
||||
}
|
||||
}
|
||||
|
||||
// jQuery/Zepto specific (optional)
|
||||
// Note:
|
||||
// In AMD env the global scope should be kept clean, but jQuery is an exception.
|
||||
// jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
|
||||
// and we should catch that.
|
||||
var $ = window.jQuery || window.Zepto;
|
||||
if (typeof($) !== UNDEF_TYPE) {
|
||||
var parser = new UAParser();
|
||||
$.ua = parser.getResult();
|
||||
$.ua.get = function() {
|
||||
return parser.getUA();
|
||||
};
|
||||
$.ua.set = function (uastring) {
|
||||
parser.setUA(uastring);
|
||||
var result = parser.getResult();
|
||||
for (var prop in result) {
|
||||
$.ua[prop] = result[prop];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
})(this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user