22 var style = document.createElement(
'div').style,
23 moz = style[
'MozBorderRadius'] !== undefined,
24 webkit = style[
'WebkitBorderRadius'] !== undefined,
25 radius = style[
'borderRadius'] !== undefined || style[
'BorderRadius'] !== undefined,
26 mode = document.documentMode || 0,
27 noBottomFold = $.browser.msie && (($.browser.version < 8 && !mode) || mode < 8),
29 expr = $.browser.msie && (
function() {
30 var div = document.createElement(
'div');
31 try { div.style.setExpression(
'width',
'0+0'); div.style.removeExpression(
'width'); }
32 catch(e) {
return false; }
36 $.support = $.support || {};
37 $.support.borderRadius = moz || webkit || radius;
40 return parseInt($.css(el,p))||0;
43 s = parseInt(s).toString(16);
44 return ( s.length < 2 ) ?
'0'+s : s;
48 var v = $.css(node,
'backgroundColor'), rgb;
49 if (v && v !=
'transparent' && v !=
'rgba(0, 0, 0, 0)') {
50 if (v.indexOf(
'rgb') >= 0) {
51 rgb = v.match(/\d+/g);
52 return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
56 if (node.nodeName.toLowerCase() ==
'html')
58 node = node.parentNode;
63 function getWidth(fx, i, width) {
65 case 'round':
return Math.round(width*(1-Math.cos(Math.asin(i/width))));
66 case 'cool':
return Math.round(width*(1+Math.cos(Math.asin(i/width))));
67 case 'sharp':
return width-i;
68 case 'bite':
return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
69 case 'slide':
return Math.round(width*(Math.atan2(i,width/i)));
70 case 'jut':
return Math.round(width*(Math.atan2(width,(width-i-1))));
71 case 'curl':
return Math.round(width*(Math.atan(i)));
72 case 'tear':
return Math.round(width*(Math.cos(i)));
73 case 'wicked':
return Math.round(width*(Math.tan(i)));
74 case 'long':
return Math.round(width*(Math.sqrt(i)));
75 case 'sculpt':
return Math.round(width*(Math.log((width-i-1),width)));
77 case 'dog':
return (i&1) ? (i+1) : width;
78 case 'dog2':
return (i&2) ? (i+1) : width;
79 case 'dog3':
return (i&3) ? (i+1) : width;
80 case 'fray':
return (i%2)*width;
81 case 'notch':
return width;
83 case 'bevel':
return i+1;
84 case 'steep':
return i/2 + 1;
85 case 'invsteep':
return (width-i)/2+1;
89 $.fn.corner =
function(options) {
91 if (this.length == 0) {
92 if (!$.isReady && this.selector) {
93 var s = this.selector, c = this.context;
95 $(s,c).corner(options);
101 return this.each(
function(index){
104 o = [$this.attr($.fn.corner.defaults.metaAttr) ||
'', options ||
''].join(
' ').toLowerCase(),
105 keep = /keep/.test(o),
106 cc = ((o.match(/cc:(#[0-9
a-f]+)/)||[])[1]),
107 sc = ((o.match(/sc:(#[0-9
a-f]+)/)||[])[1]),
108 width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10,
109 re = /round|bevelfold|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|
long|dog3|dog2|dogfold|dog|invsteep|steep/,
110 fx = ((o.match(re)||[
'round'])[0]),
111 fold = /dogfold|bevelfold/.test(o),
112 edges = { T:0, B:1 },
114 TL: /top|tl|left/.test(o), TR: /top|tr|right/.test(o),
115 BL: /bottom|bl|left/.test(o), BR: /bottom|br|right/.test(o)
118 strip, pad, cssHeight, j, bot, d, ds, bw, i, w, e, c, common, $horz;
120 if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
121 opts = { TL:1, TR:1, BL:1, BR:1 };
124 if ($.fn.corner.defaults.useNative && fx ==
'round' && (radius || moz || webkit) && !cc && !sc) {
126 $this.css(radius ?
'border-top-left-radius' : moz ?
'-moz-border-radius-topleft' :
'-webkit-border-top-left-radius', width +
'px');
128 $this.css(radius ?
'border-top-right-radius' : moz ?
'-moz-border-radius-topright' :
'-webkit-border-top-right-radius', width +
'px');
130 $this.css(radius ?
'border-bottom-left-radius' : moz ?
'-moz-border-radius-bottomleft' :
'-webkit-border-bottom-left-radius', width +
'px');
132 $this.css(radius ?
'border-bottom-right-radius' : moz ?
'-moz-border-radius-bottomright' :
'-webkit-border-bottom-right-radius', width +
'px');
136 strip = document.createElement(
'div');
142 backgroundColor: sc ||
'transparent',
147 T: parseInt($.css(
this,
'paddingTop'))||0, R: parseInt($.css(
this,
'paddingRight'))||0,
148 B: parseInt($.css(
this,
'paddingBottom'))||0, L: parseInt($.css(
this,
'paddingLeft'))||0
151 if (typeof this.style.zoom != undefined) this.style.zoom = 1;
152 if (!keep) this.style.border =
'none';
153 strip.style.borderColor = cc || gpc(this.parentNode);
154 cssHeight = $(
this).outerHeight();
159 if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
160 strip.style.borderStyle =
'none '+(opts[j+
'R']?
'solid':
'none')+
' none '+(opts[j+
'L']?
'solid':
'none');
161 d = document.createElement(
'div');
162 $(d).addClass(
'jquery-corner');
165 bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);
167 if (bot && cssHeight !=
'auto') {
168 if ($.css(
this,
'position') ==
'static')
169 this.style.position =
'relative';
170 ds.position =
'absolute';
171 ds.bottom = ds.left = ds.padding = ds.margin =
'0';
173 ds.setExpression(
'width',
'this.parentNode.offsetWidth');
177 else if (!bot && $.browser.msie) {
178 if ($.css(
this,
'position') ==
'static')
179 this.style.position =
'relative';
180 ds.position =
'absolute';
181 ds.top = ds.left = ds.right = ds.padding = ds.margin =
'0';
185 bw = sz(
this,
'borderLeftWidth') + sz(
this,
'borderRightWidth');
186 ds.setExpression(
'width',
'this.parentNode.offsetWidth - '+bw+
'+ "px"');
192 ds.position =
'relative';
193 ds.margin = !bot ?
'-'+pad.T+
'px -'+pad.R+
'px '+(pad.T-width)+
'px -'+pad.L+
'px' :
194 (pad.B-width)+
'px -'+pad.R+
'px -'+pad.B+
'px -'+pad.L+
'px';
197 for (i=0; i < width; i++) {
198 w = Math.max(0,getWidth(fx,i, width));
199 e = strip.cloneNode(
false);
200 e.style.borderWidth =
'0 '+(opts[j+
'R']?w:0)+
'px 0 '+(opts[j+
'L']?w:0)+
'px';
201 bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
204 if (fold && $.support.boxModel) {
205 if (bot && noBottomFold)
continue;
207 if (!opts[c])
continue;
208 if (bot && (c ==
'TL' || c ==
'TR'))
continue;
209 if (!bot && (c ==
'BL' || c ==
'BR'))
continue;
211 common = { position:
'absolute', border:
'none', margin: 0, padding: 0, overflow:
'hidden', backgroundColor: strip.style.borderColor };
212 $horz = $(
'<div/>').css(common).css({ width: width +
'px', height:
'1px' });
214 case 'TL': $horz.css({ bottom: 0, left: 0 });
break;
215 case 'TR': $horz.css({ bottom: 0, right: 0 });
break;
216 case 'BL': $horz.css({ top: 0, left: 0 });
break;
217 case 'BR': $horz.css({ top: 0, right: 0 });
break;
219 d.appendChild($horz[0]);
221 var $vert = $(
'<div/>').css(common).css({ top: 0, bottom: 0, width:
'1px', height: width +
'px' });
223 case 'TL': $vert.css({ left: width });
break;
224 case 'TR': $vert.css({ right: width });
break;
225 case 'BL': $vert.css({ left: width });
break;
226 case 'BR': $vert.css({ right: width });
break;
228 d.appendChild($vert[0]);
236 $.fn.uncorner =
function() {
237 if (radius || moz || webkit)
238 this.css(radius ?
'border-radius' : moz ?
'-moz-border-radius' :
'-webkit-border-radius', 0);
239 $(
'div.jquery-corner',
this).
remove();
244 $.fn.corner.defaults = {
246 metaAttr:
'data-corner'