Changeset 4585
- Timestamp:
- 08/21/10 14:24:37 (18 months ago)
- Location:
- vendors/js-jquery-corner
- Files:
-
- 2 added
- 1 deleted
- 1 edited
-
1.99 (deleted)
-
2.11 (added)
-
2.11/jquery.corner.js (added)
-
current/jquery.corner.js (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendors/js-jquery-corner/current/jquery.corner.js
r3293 r4585 2 2 * jQuery corner plugin: simple corner rounding 3 3 * Examples and documentation at: http://jquery.malsup.com/corner/ 4 * version 1.99 (28-JUL-2009) 4 * version 2.11 (15-JUN-2010) 5 * Requires jQuery v1.3.2 or later 5 6 * Dual licensed under the MIT and GPL licenses: 6 7 * http://www.opensource.org/licenses/mit-license.php 7 8 * http://www.gnu.org/licenses/gpl.html 9 * Authors: Dave Methvin and Mike Alsup 8 10 */ 9 11 … … 12 14 * 13 15 * 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 * corners: one or more of: top, bottom, tr, tl, br, or bl. (default is all corners) 16 17 * 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/) 18 * specify this value using the px suffix such as 10px (yes, it must be pixels). 26 19 */ 27 20 ;(function($) { 28 21 29 var expr = (function() { 30 if (! $.browser.msie) return false; 31 var div = document.createElement('div'); 32 try { div.style.setExpression('width','0+0'); } 33 catch(e) { return false; } 34 return true; 35 })(); 36 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), 28 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; } 33 return true; 34 })(); 35 36 $.support = $.support || {}; 37 $.support.borderRadius = moz || webkit || radius; // so you can do: if (!$.support.borderRadius) $('#myDiv').corner(); 38 37 39 function sz(el, p) { 38 40 return parseInt($.css(el,p))||0; … … 43 45 }; 44 46 function gpc(node) { 45 for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode ) { 46 var v = $.css(node,'backgroundColor'); 47 if (v == 'rgba(0, 0, 0, 0)') 48 continue; // webkit 49 if (v.indexOf('rgb') >= 0) { 50 var rgb = v.match(/\d+/g); 51 return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]); 52 } 53 if ( v && v != 'transparent' ) 47 while(node) { 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]); 53 } 54 54 return v; 55 } 56 if (node.nodeName.toLowerCase() == 'html') 57 break; 58 node = node.parentNode; // keep walking if transparent 55 59 } 56 60 return '#ffffff'; … … 70 74 case 'long': return Math.round(width*(Math.sqrt(i))); 71 75 case 'sculpt': return Math.round(width*(Math.log((width-i-1),width))); 76 case 'dogfold': 72 77 case 'dog': return (i&1) ? (i+1) : width; 73 78 case 'dog2': return (i&2) ? (i+1) : width; … … 75 80 case 'fray': return (i%2)*width; 76 81 case 'notch': return width; 82 case 'bevelfold': 77 83 case 'bevel': return i+1; 78 84 } 79 85 }; 80 86 81 $.fn.corner = function(o ) {87 $.fn.corner = function(options) { 82 88 // in 1.3+ we can fix mistakes with the ready state 83 if (this.length == 0) {89 if (this.length == 0) { 84 90 if (!$.isReady && this.selector) { 85 91 var s = this.selector, c = this.context; 86 92 $(function() { 87 $(s,c).corner(o );93 $(s,c).corner(options); 88 94 }); 89 95 } 90 96 return this; 91 } 92 93 o = (o||"").toLowerCase(); 94 var keep = /keep/.test(o); // keep borders? 95 var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]); // corner color 96 var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]); // strip color 97 var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width 98 var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/; 99 var fx = ((o.match(re)||['round'])[0]); 100 var edges = { T:0, B:1 }; 101 var opts = { 102 TL: /top|tl/.test(o), TR: /top|tr/.test(o), 103 BL: /bottom|bl/.test(o), BR: /bottom|br/.test(o) 104 }; 105 if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR ) 106 opts = { TL:1, TR:1, BL:1, BR:1 }; 107 var strip = document.createElement('div'); 108 strip.style.overflow = 'hidden'; 109 strip.style.height = '1px'; 110 strip.style.backgroundColor = sc || 'transparent'; 111 strip.style.borderStyle = 'solid'; 97 } 98 112 99 return this.each(function(index){ 113 var pad = { 100 var $this = $(this), 101 // meta values override options 102 o = [$this.attr($.fn.corner.defaults.metaAttr) || '', options || ''].join(' ').toLowerCase(), 103 keep = /keep/.test(o), // keep borders? 104 cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]), // corner color 105 sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]), // strip color 106 width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10, // corner width 107 re = /round|bevelfold|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dogfold|dog/, 108 fx = ((o.match(re)||['round'])[0]), 109 fold = /dogfold|bevelfold/.test(o), 110 edges = { T:0, B:1 }, 111 opts = { 112 TL: /top|tl|left/.test(o), TR: /top|tr|right/.test(o), 113 BL: /bottom|bl|left/.test(o), BR: /bottom|br|right/.test(o) 114 }, 115 // vars used in func later 116 strip, pad, cssHeight, j, bot, d, ds, bw, i, w, e, c, common, $horz; 117 118 if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR ) 119 opts = { TL:1, TR:1, BL:1, BR:1 }; 120 121 // support native rounding 122 if ($.fn.corner.defaults.useNative && fx == 'round' && (radius || moz || webkit) && !cc && !sc) { 123 if (opts.TL) 124 $this.css(radius ? 'border-top-left-radius' : moz ? '-moz-border-radius-topleft' : '-webkit-border-top-left-radius', width + 'px'); 125 if (opts.TR) 126 $this.css(radius ? 'border-top-right-radius' : moz ? '-moz-border-radius-topright' : '-webkit-border-top-right-radius', width + 'px'); 127 if (opts.BL) 128 $this.css(radius ? 'border-bottom-left-radius' : moz ? '-moz-border-radius-bottomleft' : '-webkit-border-bottom-left-radius', width + 'px'); 129 if (opts.BR) 130 $this.css(radius ? 'border-bottom-right-radius' : moz ? '-moz-border-radius-bottomright' : '-webkit-border-bottom-right-radius', width + 'px'); 131 return; 132 } 133 134 strip = document.createElement('div'); 135 $(strip).css({ 136 overflow: 'hidden', 137 height: '1px', 138 minHeight: '1px', 139 fontSize: '1px', 140 backgroundColor: sc || 'transparent', 141 borderStyle: 'solid' 142 }); 143 144 pad = { 114 145 T: parseInt($.css(this,'paddingTop'))||0, R: parseInt($.css(this,'paddingRight'))||0, 115 146 B: parseInt($.css(this,'paddingBottom'))||0, L: parseInt($.css(this,'paddingLeft'))||0 … … 119 150 if (!keep) this.style.border = 'none'; 120 151 strip.style.borderColor = cc || gpc(this.parentNode); 121 var cssHeight = $.curCSS(this, 'height');122 123 for ( varj in edges) {124 varbot = edges[j];152 cssHeight = $(this).outerHeight(); 153 154 for (j in edges) { 155 bot = edges[j]; 125 156 // only add stips if needed 126 157 if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) { 127 158 strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none'); 128 vard = document.createElement('div');159 d = document.createElement('div'); 129 160 $(d).addClass('jquery-corner'); 130 vards = d.style;161 ds = d.style; 131 162 132 163 bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild); … … 150 181 // fix ie6 problem when blocked element has a border width 151 182 if (expr) { 152 varbw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');183 bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth'); 153 184 ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"'); 154 185 } … … 157 188 } 158 189 else { 159 ds.position = 'relative';190 ds.position = 'relative'; 160 191 ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 161 192 (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px'; 162 193 } 163 194 164 for ( vari=0; i < width; i++) {165 varw = Math.max(0,getWidth(fx,i, width));166 vare = strip.cloneNode(false);195 for (i=0; i < width; i++) { 196 w = Math.max(0,getWidth(fx,i, width)); 197 e = strip.cloneNode(false); 167 198 e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px'; 168 199 bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild); 169 200 } 201 202 if (fold && $.support.boxModel) { 203 if (bot && noBottomFold) continue; 204 for (c in opts) { 205 if (!opts[c]) continue; 206 if (bot && (c == 'TL' || c == 'TR')) continue; 207 if (!bot && (c == 'BL' || c == 'BR')) continue; 208 209 common = { position: 'absolute', border: 'none', margin: 0, padding: 0, overflow: 'hidden', backgroundColor: strip.style.borderColor }; 210 $horz = $('<div/>').css(common).css({ width: width + 'px', height: '1px' }); 211 switch(c) { 212 case 'TL': $horz.css({ bottom: 0, left: 0 }); break; 213 case 'TR': $horz.css({ bottom: 0, right: 0 }); break; 214 case 'BL': $horz.css({ top: 0, left: 0 }); break; 215 case 'BR': $horz.css({ top: 0, right: 0 }); break; 216 } 217 d.appendChild($horz[0]); 218 219 var $vert = $('<div/>').css(common).css({ top: 0, bottom: 0, width: '1px', height: width + 'px' }); 220 switch(c) { 221 case 'TL': $vert.css({ left: width }); break; 222 case 'TR': $vert.css({ right: width }); break; 223 case 'BL': $vert.css({ left: width }); break; 224 case 'BR': $vert.css({ right: width }); break; 225 } 226 d.appendChild($vert[0]); 227 } 228 } 170 229 } 171 230 } … … 174 233 175 234 $.fn.uncorner = function() { 176 $('div.jquery-corner', this).remove(); 177 return this; 235 if (radius || moz || webkit) 236 this.css(radius ? 'border-radius' : moz ? '-moz-border-radius' : '-webkit-border-radius', 0); 237 $('div.jquery-corner', this).remove(); 238 return this; 239 }; 240 241 // expose options 242 $.fn.corner.defaults = { 243 useNative: true, // true if plugin should attempt to use native browser support for border radius rounding 244 metaAttr: 'data-corner' // name of meta attribute to use for options 178 245 }; 179 246
Note: See TracChangeset
for help on using the changeset viewer.
