PageSourceSearch

https://www.wacoal.jp/common_wacoal_jp/js/lib/jquery.corner.js

js wacoal.jp collected 2026-10-01 09:11:10 UTC 11,234 bytes, 251 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.