/*! * jquery corner plugin: simple corner rounding * examples and documentation at: http://jquery.malsup.com/corner/ * version 2.12 (23-may-2011) * requires jquery v1.3.2 or later * dual licensed under the mit and gpl licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * authors: dave methvin and mike alsup */ /** * corner() takes a single string argument: $('#mydiv').corner("effect corners width") * * effect: name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). * corners: one or more of: top, bottom, tr, tl, br, or bl. (default is all corners) * width: width of the effect; in the case of rounded corners this is the radius. * specify this value using the px suffix such as 10px (yes, it must be pixels). */ ;(function($) { var style = document.createelement('div').style, moz = style['mozborderradius'] !== undefined, webkit = style['webkitborderradius'] !== undefined, radius = style['borderradius'] !== undefined || style['borderradius'] !== undefined, mode = document.documentmode || 0, nobottomfold = $.browser.msie && (($.browser.version < 8 && !mode) || mode < 8), expr = $.browser.msie && (function() { var div = document.createelement('div'); try { div.style.setexpression('width','0+0'); div.style.removeexpression('width'); } catch(e) { return false; } return true; })(); $.support = $.support || {}; $.support.borderradius = moz || webkit || radius; // so you can do: if (!$.support.borderradius) $('#mydiv').corner(); function sz(el, p) { return parseint($.css(el,p))||0; }; function hex2(s) { s = parseint(s).tostring(16); return ( s.length < 2 ) ? '0'+s : s; }; function gpc(node) { while(node) { var v = $.css(node,'backgroundcolor'), rgb; if (v && v != 'transparent' && v != 'rgba(0, 0, 0, 0)') { if (v.indexof('rgb') >= 0) { rgb = v.match(/\d+/g); return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]); } return v; } if (node.nodename.tolowercase() == 'html') break; node = node.parentnode; // keep walking if transparent } return '#ffffff'; }; function getwidth(fx, i, width) { switch(fx) { case 'round': return math.round(width*(1-math.cos(math.asin(i/width)))); case 'cool': return math.round(width*(1+math.cos(math.asin(i/width)))); case 'sharp': return width-i; case 'bite': return math.round(width*(math.cos(math.asin((width-i-1)/width)))); case 'slide': return math.round(width*(math.atan2(i,width/i))); case 'jut': return math.round(width*(math.atan2(width,(width-i-1)))); case 'curl': return math.round(width*(math.atan(i))); case 'tear': return math.round(width*(math.cos(i))); case 'wicked': return math.round(width*(math.tan(i))); case 'long': return math.round(width*(math.sqrt(i))); case 'sculpt': return math.round(width*(math.log((width-i-1),width))); case 'dogfold': case 'dog': return (i&1) ? (i+1) : width; case 'dog2': return (i&2) ? (i+1) : width; case 'dog3': return (i&3) ? (i+1) : width; case 'fray': return (i%2)*width; case 'notch': return width; case 'bevelfold': case 'bevel': return i+1; case 'steep': return i/2 + 1; case 'invsteep':return (width-i)/2+1; } }; $.fn.corner = function(options) { // in 1.3+ we can fix mistakes with the ready state if (this.length == 0) { if (!$.isready && this.selector) { var s = this.selector, c = this.context; $(function() { $(s,c).corner(options); }); } return this; } return this.each(function(index){ var $this = $(this), // meta values override options o = [$this.attr($.fn.corner.defaults.metaattr) || '', options || ''].join(' ').tolowercase(), keep = /keep/.test(o), // keep borders? cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]), // corner color sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]), // strip color width = parseint((o.match(/(\d+)px/)||[])[1]) || 10, // corner width re = /round|bevelfold|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dogfold|dog|invsteep|steep/, fx = ((o.match(re)||['round'])[0]), fold = /dogfold|bevelfold/.test(o), edges = { t:0, b:1 }, opts = { tl: /top|tl|left/.test(o), tr: /top|tr|right/.test(o), bl: /bottom|bl|left/.test(o), br: /bottom|br|right/.test(o) }, // vars used in func later strip, pad, cssheight, j, bot, d, ds, bw, i, w, e, c, common, $horz; if ( !opts.tl && !opts.tr && !opts.bl && !opts.br ) opts = { tl:1, tr:1, bl:1, br:1 }; // support native rounding if ($.fn.corner.defaults.usenative && fx == 'round' && (radius || moz || webkit) && !cc && !sc) { if (opts.tl) $this.css(radius ? 'border-top-left-radius' : moz ? '-moz-border-radius-topleft' : '-webkit-border-top-left-radius', width + 'px'); if (opts.tr) $this.css(radius ? 'border-top-right-radius' : moz ? '-moz-border-radius-topright' : '-webkit-border-top-right-radius', width + 'px'); if (opts.bl) $this.css(radius ? 'border-bottom-left-radius' : moz ? '-moz-border-radius-bottomleft' : '-webkit-border-bottom-left-radius', width + 'px'); if (opts.br) $this.css(radius ? 'border-bottom-right-radius' : moz ? '-moz-border-radius-bottomright' : '-webkit-border-bottom-right-radius', width + 'px'); return; } strip = document.createelement('div'); $(strip).css({ overflow: 'hidden', height: '1px', minheight: '1px', fontsize: '1px', backgroundcolor: sc || 'transparent', borderstyle: 'solid' }); pad = { t: parseint($.css(this,'paddingtop'))||0, r: parseint($.css(this,'paddingright'))||0, b: parseint($.css(this,'paddingbottom'))||0, l: parseint($.css(this,'paddingleft'))||0 }; if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'haslayout' in ie if (!keep) this.style.border = 'none'; strip.style.bordercolor = cc || gpc(this.parentnode); cssheight = $(this).outerheight(); for (j in edges) { bot = edges[j]; // only add stips if needed if ((bot && (opts.bl || opts.br)) || (!bot && (opts.tl || opts.tr))) { strip.style.borderstyle = 'none '+(opts[j+'r']?'solid':'none')+' none '+(opts[j+'l']?'solid':'none'); d = document.createelement('div'); $(d).addclass('jquery-corner'); ds = d.style; bot ? this.appendchild(d) : this.insertbefore(d, this.firstchild); if (bot && cssheight != 'auto') { if ($.css(this,'position') == 'static') this.style.position = 'relative'; ds.position = 'absolute'; ds.bottom = ds.left = ds.padding = ds.margin = '0'; if (expr) ds.setexpression('width', 'this.parentnode.offsetwidth'); else ds.width = '100%'; } else if (!bot && $.browser.msie) { if ($.css(this,'position') == 'static') this.style.position = 'relative'; ds.position = 'absolute'; ds.top = ds.left = ds.right = ds.padding = ds.margin = '0'; // fix ie6 problem when blocked element has a border width if (expr) { bw = sz(this,'borderleftwidth') + sz(this,'borderrightwidth'); ds.setexpression('width', 'this.parentnode.offsetwidth - '+bw+'+ "px"'); } else ds.width = '100%'; } else { ds.position = 'relative'; ds.margin = !bot ? '-'+pad.t+'px -'+pad.r+'px '+(pad.t-width)+'px -'+pad.l+'px' : (pad.b-width)+'px -'+pad.r+'px -'+pad.b+'px -'+pad.l+'px'; } for (i=0; i < width; i++) { w = math.max(0,getwidth(fx,i, width)); e = strip.clonenode(false); e.style.borderwidth = '0 '+(opts[j+'r']?w:0)+'px 0 '+(opts[j+'l']?w:0)+'px'; bot ? d.appendchild(e) : d.insertbefore(e, d.firstchild); } if (fold && $.support.boxmodel) { if (bot && nobottomfold) continue; for (c in opts) { if (!opts[c]) continue; if (bot && (c == 'tl' || c == 'tr')) continue; if (!bot && (c == 'bl' || c == 'br')) continue; common = { position: 'absolute', border: 'none', margin: 0, padding: 0, overflow: 'hidden', backgroundcolor: strip.style.bordercolor }; $horz = $('
').css(common).css({ width: width + 'px', height: '1px' }); switch(c) { case 'tl': $horz.css({ bottom: 0, left: 0 }); break; case 'tr': $horz.css({ bottom: 0, right: 0 }); break; case 'bl': $horz.css({ top: 0, left: 0 }); break; case 'br': $horz.css({ top: 0, right: 0 }); break; } d.appendchild($horz[0]); var $vert = $('
').css(common).css({ top: 0, bottom: 0, width: '1px', height: width + 'px' }); switch(c) { case 'tl': $vert.css({ left: width }); break; case 'tr': $vert.css({ right: width }); break; case 'bl': $vert.css({ left: width }); break; case 'br': $vert.css({ right: width }); break; } d.appendchild($vert[0]); } } } } }); }; $.fn.uncorner = function() { if (radius || moz || webkit) this.css(radius ? 'border-radius' : moz ? '-moz-border-radius' : '-webkit-border-radius', 0); $('div.jquery-corner', this).remove(); return this; }; // expose options $.fn.corner.defaults = { usenative: true, // true if plugin should attempt to use native browser support for border radius rounding metaattr: 'data-corner' // name of meta attribute to use for options }; })(jquery);