-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefixer.js
72 lines (50 loc) · 1.42 KB
/
prefixer.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
/**!
* @license prefixer.js v0.2
* (c) 2014 Giuseppe Scotto Lavina <mailto:gscotto78{at}gmail.com>
* Available under MIT license
*/
;(function( name, style, prefixes, len ) {
"use strict"
var
cache = {},
idx = len,
prefix = "",
key = prefix,
reg1 = /-+(.)?/g,
reg2 = /([A-Z])/g,
reg3 = /[-_\s]+/g,
camelize = (function( fn1, fn2, nill ) {
return function camelize( str, noFirst ) {
return str.replace(reg1, noFirst ? fn1 : fn2)
}
})(
function regMatch1(match, chr, idx) {
return chr ? (!idx ? chr.toLowerCase() : chr.toUpperCase()) : nill
},
function regMatch2(match, chr, idx) {
return chr ? chr.toUpperCase() : nill
},
""
)
function dasherize( str ) {
return str.trim().replace(reg2, "-$1").replace(reg3, "-").toLowerCase()
}
function prefixer( prop, camel ) {
key = camel ? prop + "C" : prop
if(!(key in cache) && (idx = len))
while(idx--) if((prefix = prefixes[idx] + prop) in style || camelize(prefix) in style) {
cache[key] = camel ? camelize(prefix, idx === 3) : dasherize(prefix)
break
}
return key in cache ? cache[key] : prop
}
prefixer.dasherize = dasherize
prefixer.camelize = camelize
this[name] = prefixer
}).call(
this,
"prefixer",
document.documentElement.style,
["-o-", "-ms-", "-moz-", "-webkit-", ""],
5
)