-
Notifications
You must be signed in to change notification settings - Fork 4
/
stylePrefixr.js
76 lines (65 loc) · 1.55 KB
/
stylePrefixr.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
var el;
if(!!global.document){
el = global.document.createElement('div');
}
var prefixes = ["ms", "Moz", "Webkit", "O"];
var properties = [
'userSelect',
'transform',
'transition',
'transformOrigin',
'transformStyle',
'transitionProperty',
'transitionDuration',
'transitionTimingFunction',
'transitionDelay',
'borderImage',
'borderImageSlice',
'boxShadow',
'backgroundClip',
'backfaceVisibility',
'perspective',
'perspectiveOrigin',
'animation',
'animationDuration',
'animationName',
'animationDelay',
'animationDirection',
'animationIterationCount',
'animationTimingFunction',
'animationPlayState',
'animationFillMode',
'appearance'
];
function GetVendorPrefix(property) {
if(properties.indexOf(property) == -1 || !global.document || typeof el.style[property] !== 'undefined'){
return property;
}
property = property[0].toUpperCase() + property.slice(1);
var temp;
for(var i = 0; i < prefixes.length; i++){
temp = prefixes[i] + property;
if(typeof el.style[temp] !== 'undefined'){
prefixes = [prefixes[i]]; // we only need to check this one prefix from now on.
return temp;
}
}
return property[0].toLowerCase() + property.slice(1);
}
module.exports = (function(){
var cache = {};
return function(obj){
if(!global.document){
return obj;
}
var result = {};
for(var key in obj){
if(cache[key] === undefined){
cache[key] = GetVendorPrefix(key);
}
result[cache[key]] = obj[key];
}
return result;
};
})();