mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Keep global scope clean with AMD. Always check for jQuery global.
If an AMD environment, don't export `UAParser` to global scope. Even in AMD environment jQuery exports to global scope. We should catch it even then. It also can happen then one joins the jQuery source file with other jQuery plugins in a CommonJS env.
This commit is contained in:
parent
0951cebd09
commit
551fbf100c
@ -739,15 +739,23 @@
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
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();
|
||||
@ -763,6 +771,5 @@
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
})(this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user