11 "./css/var/getStyles",
15 "./css/defaultDisplay",
18 "./data/var/dataPriv",
22 "./selector" // contains
23 ], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand, isHidden,
24 getStyles, swap, curCSS, adjustCSS, defaultDisplay, addGetHookIf, support, dataPriv ) {
28 // Swappable if display is none or starts with table
29 // except "table", "table-cell", or "table-caption"
30 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
31 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
33 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
34 cssNormalTransform = {
39 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
40 emptyStyle = document.createElement( "div" ).style;
42 // Return a css property mapped to a potentially vendor prefixed property
43 function vendorPropName( name ) {
45 // Shortcut for names that are not vendor prefixed
46 if ( name in emptyStyle ) {
50 // Check for vendor prefixed names
51 var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
52 i = cssPrefixes.length;
55 name = cssPrefixes[ i ] + capName;
56 if ( name in emptyStyle ) {
62 function setPositiveNumber( elem, value, subtract ) {
64 // Any relative (+/-) values have already been
65 // normalized at this point
66 var matches = rcssNum.exec( value );
69 // Guard against undefined "subtract", e.g., when used as in cssHooks
70 Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) :
74 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
75 var i = extra === ( isBorderBox ? "border" : "content" ) ?
77 // If we already have the right measurement, avoid augmentation
80 // Otherwise initialize for horizontal or vertical properties
81 name === "width" ? 1 : 0,
85 for ( ; i < 4; i += 2 ) {
87 // Both box models exclude margin, so add it if we want it
88 if ( extra === "margin" ) {
89 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
94 // border-box includes padding, so remove it if we want content
95 if ( extra === "content" ) {
96 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
99 // At this point, extra isn't border nor margin, so remove border
100 if ( extra !== "margin" ) {
101 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
105 // At this point, extra isn't content, so add padding
106 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
108 // At this point, extra isn't content nor padding, so add border
109 if ( extra !== "padding" ) {
110 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
118 function getWidthOrHeight( elem, name, extra ) {
120 // Start with offset property, which is equivalent to the border-box value
121 var valueIsBorderBox = true,
122 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
123 styles = getStyles( elem ),
124 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
126 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
127 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
128 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
129 if ( val <= 0 || val == null ) {
131 // Fall back to computed then uncomputed css if necessary
132 val = curCSS( elem, name, styles );
133 if ( val < 0 || val == null ) {
134 val = elem.style[ name ];
137 // Computed unit is not pixels. Stop here and return.
138 if ( rnumnonpx.test( val ) ) {
142 // Check for style in case a browser which returns unreliable values
143 // for getComputedStyle silently falls back to the reliable elem.style
144 valueIsBorderBox = isBorderBox &&
145 ( support.boxSizingReliable() || val === elem.style[ name ] );
147 // Normalize "", auto, and prepare for extra
148 val = parseFloat( val ) || 0;
151 // Use the active box-sizing model to add/subtract irrelevant styles
153 augmentWidthOrHeight(
156 extra || ( isBorderBox ? "border" : "content" ),
163 function showHide( elements, show ) {
164 var display, elem, hidden,
167 length = elements.length;
169 for ( ; index < length; index++ ) {
170 elem = elements[ index ];
175 values[ index ] = dataPriv.get( elem, "olddisplay" );
176 display = elem.style.display;
179 // Reset the inline display of this element to learn if it is
180 // being hidden by cascaded rules or not
181 if ( !values[ index ] && display === "none" ) {
182 elem.style.display = "";
185 // Set elements which have been overridden with display: none
186 // in a stylesheet to whatever the default browser style is
187 // for such an element
188 if ( elem.style.display === "" && isHidden( elem ) ) {
189 values[ index ] = dataPriv.access(
192 defaultDisplay( elem.nodeName )
196 hidden = isHidden( elem );
198 if ( display !== "none" || !hidden ) {
202 hidden ? display : jQuery.css( elem, "display" )
208 // Set the display of most of the elements in a second loop
209 // to avoid the constant reflow
210 for ( index = 0; index < length; index++ ) {
211 elem = elements[ index ];
215 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
216 elem.style.display = show ? values[ index ] || "" : "none";
225 // Add in style property hooks for overriding the default
226 // behavior of getting and setting a style property
229 get: function( elem, computed ) {
232 // We should always get a number back from opacity
233 var ret = curCSS( elem, "opacity" );
234 return ret === "" ? "1" : ret;
240 // Don't automatically add "px" to these possibly-unitless properties
242 "animationIterationCount": true,
257 // Add in properties whose names you wish to fix before
258 // setting or getting the value
263 // Get and set the style property on a DOM Node
264 style: function( elem, name, value, extra ) {
266 // Don't set styles on text and comment nodes
267 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
271 // Make sure that we're working with the right name
272 var ret, type, hooks,
273 origName = jQuery.camelCase( name ),
276 name = jQuery.cssProps[ origName ] ||
277 ( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName );
279 // Gets hook for the prefixed version, then unprefixed version
280 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
282 // Check if we're setting a value
283 if ( value !== undefined ) {
286 // Convert "+=" or "-=" to relative numbers (#7345)
287 if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
288 value = adjustCSS( elem, name, ret );
294 // Make sure that null and NaN values aren't set (#7116)
295 if ( value == null || value !== value ) {
299 // If a number was passed in, add the unit (except for certain CSS properties)
300 if ( type === "number" ) {
301 value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
305 // background-* props affect original clone's values
306 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
307 style[ name ] = "inherit";
310 // If a hook was provided, use that value, otherwise just set the specified value
311 if ( !hooks || !( "set" in hooks ) ||
312 ( value = hooks.set( elem, value, extra ) ) !== undefined ) {
314 style[ name ] = value;
319 // If a hook was provided get the non-computed value from there
320 if ( hooks && "get" in hooks &&
321 ( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
326 // Otherwise just get the value from the style object
327 return style[ name ];
331 css: function( elem, name, extra, styles ) {
333 origName = jQuery.camelCase( name );
335 // Make sure that we're working with the right name
336 name = jQuery.cssProps[ origName ] ||
337 ( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName );
339 // Try prefixed name followed by the unprefixed name
340 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
342 // If a hook was provided get the computed value from there
343 if ( hooks && "get" in hooks ) {
344 val = hooks.get( elem, true, extra );
347 // Otherwise, if a way to get the computed value exists, use that
348 if ( val === undefined ) {
349 val = curCSS( elem, name, styles );
352 // Convert "normal" to computed value
353 if ( val === "normal" && name in cssNormalTransform ) {
354 val = cssNormalTransform[ name ];
357 // Make numeric if forced or a qualifier was provided and val looks numeric
358 if ( extra === "" || extra ) {
359 num = parseFloat( val );
360 return extra === true || isFinite( num ) ? num || 0 : val;
366 jQuery.each( [ "height", "width" ], function( i, name ) {
367 jQuery.cssHooks[ name ] = {
368 get: function( elem, computed, extra ) {
371 // Certain elements can have dimension info if we invisibly show them
372 // but it must have a current display style that would benefit
373 return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
374 elem.offsetWidth === 0 ?
375 swap( elem, cssShow, function() {
376 return getWidthOrHeight( elem, name, extra );
378 getWidthOrHeight( elem, name, extra );
382 set: function( elem, value, extra ) {
384 styles = extra && getStyles( elem ),
385 subtract = extra && augmentWidthOrHeight(
389 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
393 // Convert to pixels if value adjustment is needed
394 if ( subtract && ( matches = rcssNum.exec( value ) ) &&
395 ( matches[ 3 ] || "px" ) !== "px" ) {
397 elem.style[ name ] = value;
398 value = jQuery.css( elem, name );
401 return setPositiveNumber( elem, value, subtract );
406 jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
407 function( elem, computed ) {
409 return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
410 elem.getBoundingClientRect().left -
411 swap( elem, { marginLeft: 0 }, function() {
412 return elem.getBoundingClientRect().left;
419 // Support: Android 2.3
420 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
421 function( elem, computed ) {
423 return swap( elem, { "display": "inline-block" },
424 curCSS, [ elem, "marginRight" ] );
429 // These hooks are used by animate to expand properties
434 }, function( prefix, suffix ) {
435 jQuery.cssHooks[ prefix + suffix ] = {
436 expand: function( value ) {
440 // Assumes a single number if not a string
441 parts = typeof value === "string" ? value.split( " " ) : [ value ];
443 for ( ; i < 4; i++ ) {
444 expanded[ prefix + cssExpand[ i ] + suffix ] =
445 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
452 if ( !rmargin.test( prefix ) ) {
453 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
458 css: function( name, value ) {
459 return access( this, function( elem, name, value ) {
464 if ( jQuery.isArray( name ) ) {
465 styles = getStyles( elem );
468 for ( ; i < len; i++ ) {
469 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
475 return value !== undefined ?
476 jQuery.style( elem, name, value ) :
477 jQuery.css( elem, name );
478 }, name, value, arguments.length > 1 );
481 return showHide( this, true );
484 return showHide( this );
486 toggle: function( state ) {
487 if ( typeof state === "boolean" ) {
488 return state ? this.show() : this.hide();
491 return this.each( function() {
492 if ( isHidden( this ) ) {
493 jQuery( this ).show();
495 jQuery( this ).hide();