forked from brandonaaron/jquery-cssHooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathborderradius.js
62 lines (55 loc) · 2.57 KB
/
borderradius.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
/*! Copyright (c) 2010 Burin Asavesna (http://helloburin.com)
* Licensed under the MIT License (LICENSE.txt).
*/
(function($) {
// borderRadius get hooks
var div = document.createElement('div'),
divStyle = div.style,
support = $.support,
dirs = "TopLeft TopRight BottomRight BottomLeft".split(" ");
// WebKit supports "borderRadius" as well as "WebKitBorderRadius", weird
support.borderRadius =
divStyle.MozBorderRadius === ''? 'MozBorderRadius' :
(divStyle.MsBorderRadius === ''? 'MsBorderRadius' :
(divStyle.WebkitBorderRadius === ''? 'WebkitBorderRadius' :
(divStyle.OBorderRadius === ''? 'OBorderRadius' :
(divStyle.borderRadius === ''? 'BorderRadius' :
false))));
div = null;
function borderCornerRadius(direction, prefix) {
prefix = prefix === undefined || prefix === '' ? 'border' : prefix + 'Border';
if ( support.borderRadius && support.borderRadius == "MozBorderRadius" ) {
// e.g. MozBorderRadiusTopleft
return prefix + "Radius" + direction.charAt(0).toUpperCase()+direction.substr(1).toLowerCase();
} else {
// e.g. WebKitBorderTopLeftRadius, borderTopLeftRadius, etc
return prefix + direction + "Radius";
}
}
if ( support.borderRadius && support.borderRadius !== "BorderRadius" ) {
var vendor_prefix = support.borderRadius.replace('BorderRadius','');
$.cssHooks.borderRadius = {
get: function( elem, computed, extra ) {
// return each of the directions, topleft, topright, bottomright, bottomleft
return $.map(dirs, function( dir ) {
return $.css(elem, borderCornerRadius( dir, vendor_prefix ));
}).join(" ");
},
set: function( elem, value ) {
// takes in a single value or shorthand (just letting the browser handle this)
// e.g. 5px to set all, or 5px 0 0 5px to set left corners
elem.style[ borderCornerRadius( '', vendor_prefix ) ] = value;
}
};
$.each(dirs, function( i, dir ) {
$.cssHooks[ "borderRadius" + dir ] = {
get: function( elem, computed, extra ) {
return $.css(elem, borderCornerRadius( dir, vendor_prefix ));
},
set: function( elem, value ) {
elem.style[ borderCornerRadius( dir, vendor_prefix ) ] = value;
}
};
});
}
})(jQuery);