1 | define( [
|
2 | "./core",
|
3 | "./core/access",
|
4 | "./core/camelCase",
|
5 | "./var/rcssNum",
|
6 | "./css/var/rnumnonpx",
|
7 | "./css/var/cssExpand",
|
8 | "./css/var/getStyles",
|
9 | "./css/var/swap",
|
10 | "./css/curCSS",
|
11 | "./css/adjustCSS",
|
12 | "./css/addGetHookIf",
|
13 | "./css/support",
|
14 | "./css/finalPropName",
|
15 |
|
16 | "./core/init",
|
17 | "./core/ready",
|
18 | "./selector"
|
19 | ], function( jQuery, access, camelCase, rcssNum, rnumnonpx, cssExpand,
|
20 | getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, finalPropName ) {
|
21 |
|
22 | "use strict";
|
23 |
|
24 | var
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | rdisplayswap = /^(none|table(?!-c[ea]).+)/,
|
30 | rcustomProp = /^--/,
|
31 | cssShow = { position: "absolute", visibility: "hidden", display: "block" },
|
32 | cssNormalTransform = {
|
33 | letterSpacing: "0",
|
34 | fontWeight: "400"
|
35 | };
|
36 |
|
37 | function setPositiveNumber( elem, value, subtract ) {
|
38 |
|
39 |
|
40 |
|
41 | var matches = rcssNum.exec( value );
|
42 | return matches ?
|
43 |
|
44 |
|
45 | Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) :
|
46 | value;
|
47 | }
|
48 |
|
49 | function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computedVal ) {
|
50 | var i = dimension === "width" ? 1 : 0,
|
51 | extra = 0,
|
52 | delta = 0;
|
53 |
|
54 |
|
55 | if ( box === ( isBorderBox ? "border" : "content" ) ) {
|
56 | return 0;
|
57 | }
|
58 |
|
59 | for ( ; i < 4; i += 2 ) {
|
60 |
|
61 |
|
62 | if ( box === "margin" ) {
|
63 | delta += jQuery.css( elem, box + cssExpand[ i ], true, styles );
|
64 | }
|
65 |
|
66 |
|
67 | if ( !isBorderBox ) {
|
68 |
|
69 |
|
70 | delta += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
71 |
|
72 |
|
73 | if ( box !== "padding" ) {
|
74 | delta += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
75 |
|
76 |
|
77 | } else {
|
78 | extra += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
79 | }
|
80 |
|
81 |
|
82 |
|
83 | } else {
|
84 |
|
85 |
|
86 | if ( box === "content" ) {
|
87 | delta -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
88 | }
|
89 |
|
90 |
|
91 | if ( box !== "margin" ) {
|
92 | delta -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
93 | }
|
94 | }
|
95 | }
|
96 |
|
97 |
|
98 | if ( !isBorderBox && computedVal >= 0 ) {
|
99 |
|
100 |
|
101 |
|
102 | delta += Math.max( 0, Math.ceil(
|
103 | elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -
|
104 | computedVal -
|
105 | delta -
|
106 | extra -
|
107 | 0.5
|
108 |
|
109 |
|
110 |
|
111 | ) ) || 0;
|
112 | }
|
113 |
|
114 | return delta;
|
115 | }
|
116 |
|
117 | function getWidthOrHeight( elem, dimension, extra ) {
|
118 |
|
119 |
|
120 | var styles = getStyles( elem ),
|
121 |
|
122 |
|
123 |
|
124 | boxSizingNeeded = !support.boxSizingReliable() || extra,
|
125 | isBorderBox = boxSizingNeeded &&
|
126 | jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
|
127 | valueIsBorderBox = isBorderBox,
|
128 |
|
129 | val = curCSS( elem, dimension, styles ),
|
130 | offsetProp = "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 );
|
131 |
|
132 |
|
133 |
|
134 | if ( rnumnonpx.test( val ) ) {
|
135 | if ( !extra ) {
|
136 | return val;
|
137 | }
|
138 | val = "auto";
|
139 | }
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | if ( ( !support.boxSizingReliable() && isBorderBox ||
|
151 | val === "auto" ||
|
152 | !parseFloat( val ) && jQuery.css( elem, "display", false, styles ) === "inline" ) &&
|
153 | elem.getClientRects().length ) {
|
154 |
|
155 | isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | valueIsBorderBox = offsetProp in elem;
|
161 | if ( valueIsBorderBox ) {
|
162 | val = elem[ offsetProp ];
|
163 | }
|
164 | }
|
165 |
|
166 |
|
167 | val = parseFloat( val ) || 0;
|
168 |
|
169 |
|
170 | return ( val +
|
171 | boxModelAdjustment(
|
172 | elem,
|
173 | dimension,
|
174 | extra || ( isBorderBox ? "border" : "content" ),
|
175 | valueIsBorderBox,
|
176 | styles,
|
177 |
|
178 |
|
179 | val
|
180 | )
|
181 | ) + "px";
|
182 | }
|
183 |
|
184 | jQuery.extend( {
|
185 |
|
186 |
|
187 |
|
188 | cssHooks: {
|
189 | opacity: {
|
190 | get: function( elem, computed ) {
|
191 | if ( computed ) {
|
192 |
|
193 |
|
194 | var ret = curCSS( elem, "opacity" );
|
195 | return ret === "" ? "1" : ret;
|
196 | }
|
197 | }
|
198 | }
|
199 | },
|
200 |
|
201 |
|
202 | cssNumber: {
|
203 | "animationIterationCount": true,
|
204 | "columnCount": true,
|
205 | "fillOpacity": true,
|
206 | "flexGrow": true,
|
207 | "flexShrink": true,
|
208 | "fontWeight": true,
|
209 | "gridArea": true,
|
210 | "gridColumn": true,
|
211 | "gridColumnEnd": true,
|
212 | "gridColumnStart": true,
|
213 | "gridRow": true,
|
214 | "gridRowEnd": true,
|
215 | "gridRowStart": true,
|
216 | "lineHeight": true,
|
217 | "opacity": true,
|
218 | "order": true,
|
219 | "orphans": true,
|
220 | "widows": true,
|
221 | "zIndex": true,
|
222 | "zoom": true
|
223 | },
|
224 |
|
225 |
|
226 |
|
227 | cssProps: {},
|
228 |
|
229 |
|
230 | style: function( elem, name, value, extra ) {
|
231 |
|
232 |
|
233 | if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
|
234 | return;
|
235 | }
|
236 |
|
237 |
|
238 | var ret, type, hooks,
|
239 | origName = camelCase( name ),
|
240 | isCustomProp = rcustomProp.test( name ),
|
241 | style = elem.style;
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | if ( !isCustomProp ) {
|
247 | name = finalPropName( origName );
|
248 | }
|
249 |
|
250 |
|
251 | hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
252 |
|
253 |
|
254 | if ( value !== undefined ) {
|
255 | type = typeof value;
|
256 |
|
257 |
|
258 | if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
|
259 | value = adjustCSS( elem, name, ret );
|
260 |
|
261 |
|
262 | type = "number";
|
263 | }
|
264 |
|
265 |
|
266 | if ( value == null || value !== value ) {
|
267 | return;
|
268 | }
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | if ( type === "number" && !isCustomProp ) {
|
274 | value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
|
275 | }
|
276 |
|
277 |
|
278 | if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
|
279 | style[ name ] = "inherit";
|
280 | }
|
281 |
|
282 |
|
283 | if ( !hooks || !( "set" in hooks ) ||
|
284 | ( value = hooks.set( elem, value, extra ) ) !== undefined ) {
|
285 |
|
286 | if ( isCustomProp ) {
|
287 | style.setProperty( name, value );
|
288 | } else {
|
289 | style[ name ] = value;
|
290 | }
|
291 | }
|
292 |
|
293 | } else {
|
294 |
|
295 |
|
296 | if ( hooks && "get" in hooks &&
|
297 | ( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
|
298 |
|
299 | return ret;
|
300 | }
|
301 |
|
302 |
|
303 | return style[ name ];
|
304 | }
|
305 | },
|
306 |
|
307 | css: function( elem, name, extra, styles ) {
|
308 | var val, num, hooks,
|
309 | origName = camelCase( name ),
|
310 | isCustomProp = rcustomProp.test( name );
|
311 |
|
312 |
|
313 |
|
314 |
|
315 | if ( !isCustomProp ) {
|
316 | name = finalPropName( origName );
|
317 | }
|
318 |
|
319 |
|
320 | hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
321 |
|
322 |
|
323 | if ( hooks && "get" in hooks ) {
|
324 | val = hooks.get( elem, true, extra );
|
325 | }
|
326 |
|
327 |
|
328 | if ( val === undefined ) {
|
329 | val = curCSS( elem, name, styles );
|
330 | }
|
331 |
|
332 |
|
333 | if ( val === "normal" && name in cssNormalTransform ) {
|
334 | val = cssNormalTransform[ name ];
|
335 | }
|
336 |
|
337 |
|
338 | if ( extra === "" || extra ) {
|
339 | num = parseFloat( val );
|
340 | return extra === true || isFinite( num ) ? num || 0 : val;
|
341 | }
|
342 |
|
343 | return val;
|
344 | }
|
345 | } );
|
346 |
|
347 | jQuery.each( [ "height", "width" ], function( i, dimension ) {
|
348 | jQuery.cssHooks[ dimension ] = {
|
349 | get: function( elem, computed, extra ) {
|
350 | if ( computed ) {
|
351 |
|
352 |
|
353 |
|
354 | return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 | ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
|
363 | swap( elem, cssShow, function() {
|
364 | return getWidthOrHeight( elem, dimension, extra );
|
365 | } ) :
|
366 | getWidthOrHeight( elem, dimension, extra );
|
367 | }
|
368 | },
|
369 |
|
370 | set: function( elem, value, extra ) {
|
371 | var matches,
|
372 | styles = getStyles( elem ),
|
373 |
|
374 |
|
375 |
|
376 | scrollboxSizeBuggy = !support.scrollboxSize() &&
|
377 | styles.position === "absolute",
|
378 |
|
379 |
|
380 | boxSizingNeeded = scrollboxSizeBuggy || extra,
|
381 | isBorderBox = boxSizingNeeded &&
|
382 | jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
|
383 | subtract = extra ?
|
384 | boxModelAdjustment(
|
385 | elem,
|
386 | dimension,
|
387 | extra,
|
388 | isBorderBox,
|
389 | styles
|
390 | ) :
|
391 | 0;
|
392 |
|
393 |
|
394 |
|
395 | if ( isBorderBox && scrollboxSizeBuggy ) {
|
396 | subtract -= Math.ceil(
|
397 | elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -
|
398 | parseFloat( styles[ dimension ] ) -
|
399 | boxModelAdjustment( elem, dimension, "border", false, styles ) -
|
400 | 0.5
|
401 | );
|
402 | }
|
403 |
|
404 |
|
405 | if ( subtract && ( matches = rcssNum.exec( value ) ) &&
|
406 | ( matches[ 3 ] || "px" ) !== "px" ) {
|
407 |
|
408 | elem.style[ dimension ] = value;
|
409 | value = jQuery.css( elem, dimension );
|
410 | }
|
411 |
|
412 | return setPositiveNumber( elem, value, subtract );
|
413 | }
|
414 | };
|
415 | } );
|
416 |
|
417 | jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
|
418 | function( elem, computed ) {
|
419 | if ( computed ) {
|
420 | return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
|
421 | elem.getBoundingClientRect().left -
|
422 | swap( elem, { marginLeft: 0 }, function() {
|
423 | return elem.getBoundingClientRect().left;
|
424 | } )
|
425 | ) + "px";
|
426 | }
|
427 | }
|
428 | );
|
429 |
|
430 |
|
431 | jQuery.each( {
|
432 | margin: "",
|
433 | padding: "",
|
434 | border: "Width"
|
435 | }, function( prefix, suffix ) {
|
436 | jQuery.cssHooks[ prefix + suffix ] = {
|
437 | expand: function( value ) {
|
438 | var i = 0,
|
439 | expanded = {},
|
440 |
|
441 |
|
442 | parts = typeof value === "string" ? value.split( " " ) : [ value ];
|
443 |
|
444 | for ( ; i < 4; i++ ) {
|
445 | expanded[ prefix + cssExpand[ i ] + suffix ] =
|
446 | parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
|
447 | }
|
448 |
|
449 | return expanded;
|
450 | }
|
451 | };
|
452 |
|
453 | if ( prefix !== "margin" ) {
|
454 | jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
|
455 | }
|
456 | } );
|
457 |
|
458 | jQuery.fn.extend( {
|
459 | css: function( name, value ) {
|
460 | return access( this, function( elem, name, value ) {
|
461 | var styles, len,
|
462 | map = {},
|
463 | i = 0;
|
464 |
|
465 | if ( Array.isArray( name ) ) {
|
466 | styles = getStyles( elem );
|
467 | len = name.length;
|
468 |
|
469 | for ( ; i < len; i++ ) {
|
470 | map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
|
471 | }
|
472 |
|
473 | return map;
|
474 | }
|
475 |
|
476 | return value !== undefined ?
|
477 | jQuery.style( elem, name, value ) :
|
478 | jQuery.css( elem, name );
|
479 | }, name, value, arguments.length > 1 );
|
480 | }
|
481 | } );
|
482 |
|
483 | return jQuery;
|
484 | } );
|