1
|
/*!
|
2
|
* jQuery corner plugin: simple corner rounding
|
3
|
* Examples and documentation at: http://jquery.malsup.com/corner/
|
4
|
* version 1.96 (11-MAY-2009)
|
5
|
* Dual licensed under the MIT and GPL licenses:
|
6
|
* http://www.opensource.org/licenses/mit-license.php
|
7
|
* http://www.gnu.org/licenses/gpl.html
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* corner() takes a single string argument: $('#myDiv').corner("effect corners width")
|
12
|
*
|
13
|
* effect: name of the effect to apply, such as round, bevel, notch, bite, etc (default is round).
|
14
|
* corners: one or more of: top, bottom, tr, tl, br, or bl.
|
15
|
* by default, all four corners are adorned.
|
16
|
* width: width of the effect; in the case of rounded corners this is the radius.
|
17
|
* specify this value using the px suffix such as 10px (and yes, it must be pixels).
|
18
|
*
|
19
|
* @name corner
|
20
|
* @type jQuery
|
21
|
* @param String options Options which control the corner style
|
22
|
* @cat Plugins/Corner
|
23
|
* @return jQuery
|
24
|
* @author Dave Methvin (http://methvin.com/jquery/jq-corner.html)
|
25
|
* @author Mike Alsup (http://jquery.malsup.com/corner/)
|
26
|
*/
|
27
|
;(function($) {
|
28
|
|
29
|
var expr = (function() {
|
30
|
var div = document.createElement('div');
|
31
|
try { div.style.setExpression('width','0+0'); }
|
32
|
catch(e) { return false; }
|
33
|
return true;
|
34
|
})();
|
35
|
|
36
|
function sz(el, p) {
|
37
|
return parseInt($.css(el,p))||0;
|
38
|
};
|
39
|
function hex2(s) {
|
40
|
var s = parseInt(s).toString(16);
|
41
|
return ( s.length < 2 ) ? '0'+s : s;
|
42
|
};
|
43
|
function gpc(node) {
|
44
|
for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode ) {
|
45
|
var v = $.css(node,'backgroundColor');
|
46
|
if ( v.indexOf('rgb') >= 0 ) {
|
47
|
if ($.browser.safari && v == 'rgba(0, 0, 0, 0)')
|
48
|
continue;
|
49
|
var rgb = v.match(/\d+/g);
|
50
|
return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
|
51
|
}
|
52
|
if ( v && v != 'transparent' )
|
53
|
return v;
|
54
|
}
|
55
|
return '#ffffff';
|
56
|
};
|
57
|
|
58
|
function getWidth(fx, i, width) {
|
59
|
switch(fx) {
|
60
|
case 'round': return Math.round(width*(1-Math.cos(Math.asin(i/width))));
|
61
|
case 'cool': return Math.round(width*(1+Math.cos(Math.asin(i/width))));
|
62
|
case 'sharp': return Math.round(width*(1-Math.cos(Math.acos(i/width))));
|
63
|
case 'bite': return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
|
64
|
case 'slide': return Math.round(width*(Math.atan2(i,width/i)));
|
65
|
case 'jut': return Math.round(width*(Math.atan2(width,(width-i-1))));
|
66
|
case 'curl': return Math.round(width*(Math.atan(i)));
|
67
|
case 'tear': return Math.round(width*(Math.cos(i)));
|
68
|
case 'wicked': return Math.round(width*(Math.tan(i)));
|
69
|
case 'long': return Math.round(width*(Math.sqrt(i)));
|
70
|
case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
|
71
|
case 'dog': return (i&1) ? (i+1) : width;
|
72
|
case 'dog2': return (i&2) ? (i+1) : width;
|
73
|
case 'dog3': return (i&3) ? (i+1) : width;
|
74
|
case 'fray': return (i%2)*width;
|
75
|
case 'notch': return width;
|
76
|
case 'bevel': return i+1;
|
77
|
}
|
78
|
};
|
79
|
|
80
|
$.fn.corner = function(o) {
|
81
|
// in 1.3+ we can fix mistakes with the ready state
|
82
|
if (this.length == 0) {
|
83
|
if (!$.isReady && this.selector) {
|
84
|
var s = this.selector, c = this.context;
|
85
|
$(function() {
|
86
|
$(s,c).corner(o);
|
87
|
});
|
88
|
}
|
89
|
return this;
|
90
|
}
|
91
|
|
92
|
o = (o||"").toLowerCase();
|
93
|
var keep = /keep/.test(o); // keep borders?
|
94
|
var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]); // corner color
|
95
|
var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]); // strip color
|
96
|
var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
|
97
|
var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
|
98
|
var fx = ((o.match(re)||['round'])[0]);
|
99
|
var edges = { T:0, B:1 };
|
100
|
var opts = {
|
101
|
TL: /top|tl/.test(o), TR: /top|tr/.test(o),
|
102
|
BL: /bottom|bl/.test(o), BR: /bottom|br/.test(o)
|
103
|
};
|
104
|
if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
|
105
|
opts = { TL:1, TR:1, BL:1, BR:1 };
|
106
|
var strip = document.createElement('div');
|
107
|
strip.style.overflow = 'hidden';
|
108
|
strip.style.height = '1px';
|
109
|
strip.style.backgroundColor = sc || 'transparent';
|
110
|
strip.style.borderStyle = 'solid';
|
111
|
return this.each(function(index){
|
112
|
var pad = {
|
113
|
T: parseInt($.css(this,'paddingTop'))||0, R: parseInt($.css(this,'paddingRight'))||0,
|
114
|
B: parseInt($.css(this,'paddingBottom'))||0, L: parseInt($.css(this,'paddingLeft'))||0
|
115
|
};
|
116
|
|
117
|
if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'hasLayout' in IE
|
118
|
if (!keep) this.style.border = 'none';
|
119
|
strip.style.borderColor = cc || gpc(this.parentNode);
|
120
|
var cssHeight = $.curCSS(this, 'height');
|
121
|
|
122
|
for (var j in edges) {
|
123
|
var bot = edges[j];
|
124
|
// only add stips if needed
|
125
|
if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
|
126
|
strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
|
127
|
var d = document.createElement('div');
|
128
|
$(d).addClass('jquery-corner');
|
129
|
var ds = d.style;
|
130
|
|
131
|
bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);
|
132
|
|
133
|
if (bot && cssHeight != 'auto') {
|
134
|
if ($.css(this,'position') == 'static')
|
135
|
this.style.position = 'relative';
|
136
|
ds.position = 'absolute';
|
137
|
ds.bottom = ds.left = ds.padding = ds.margin = '0';
|
138
|
if (expr)
|
139
|
ds.setExpression('width', 'this.parentNode.offsetWidth');
|
140
|
else
|
141
|
ds.width = '100%';
|
142
|
}
|
143
|
else if (!bot && $.browser.msie) {
|
144
|
if ($.css(this,'position') == 'static')
|
145
|
this.style.position = 'relative';
|
146
|
ds.position = 'absolute';
|
147
|
ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
|
148
|
|
149
|
// fix ie6 problem when blocked element has a border width
|
150
|
if (expr) {
|
151
|
var bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');
|
152
|
ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"');
|
153
|
}
|
154
|
else
|
155
|
ds.width = '100%';
|
156
|
}
|
157
|
else {
|
158
|
ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' :
|
159
|
(pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';
|
160
|
}
|
161
|
|
162
|
for (var i=0; i < width; i++) {
|
163
|
var w = Math.max(0,getWidth(fx,i, width));
|
164
|
var e = strip.cloneNode(false);
|
165
|
e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
|
166
|
bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
|
167
|
}
|
168
|
}
|
169
|
}
|
170
|
});
|
171
|
};
|
172
|
|
173
|
$.fn.uncorner = function() {
|
174
|
$('div.jquery-corner', this).remove();
|
175
|
return this;
|
176
|
};
|
177
|
|
178
|
})(jQuery);
|