-
Notifications
You must be signed in to change notification settings - Fork 3
/
detect.js
27 lines (23 loc) · 893 Bytes
/
detect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module.exports = function (target, prefixes) {
var prefixIdx;
var prefix;
var testName;
var scope = this || window;
// initialise to default prefixes
// (reverse order as we use a decrementing for loop)
prefixes = (prefixes || ['ms', 'o', 'moz', 'webkit']).concat('');
// iterate through the prefixes and return the class if found in global
for (prefixIdx = prefixes.length; prefixIdx--;) {
prefix = prefixes[prefixIdx];
// construct the test class name
// if we have a prefix ensure the target has an uppercase first character
// such that a test for getUserMedia would result in a search for
// webkitGetUserMedia
testName = prefix + (prefix ?
target.charAt(0).toUpperCase() + target.slice(1) :
target);
if (typeof scope[testName] == 'function' || typeof scope[testName] == 'object') {
return scope[testName];
}
}
};