Blame view
app/bower_components/jquery/src/css.js
11.2 KB
87c93a029
|
1 |
define( [ |
f986e111b
|
2 3 4 5 |
"./core", "./var/pnum", "./core/access", "./css/var/rmargin", |
87c93a029
|
6 7 |
"./var/document", "./var/rcssNum", |
f986e111b
|
8 9 |
"./css/var/rnumnonpx", "./css/var/cssExpand", |
87c93a029
|
10 11 |
"./css/var/getStyles", "./css/var/swap", |
f986e111b
|
12 |
"./css/curCSS", |
87c93a029
|
13 |
"./css/adjustCSS", |
f986e111b
|
14 15 16 17 |
"./css/addGetHookIf", "./css/support", "./core/init", |
f986e111b
|
18 19 |
"./core/ready", "./selector" // contains |
87c93a029
|
20 21 22 23 |
], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand, getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) { "use strict"; |
f986e111b
|
24 25 |
var |
f986e111b
|
26 |
|
87c93a029
|
27 28 29 |
// Swappable if display is none or starts with table // except "table", "table-cell", or "table-caption" // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display |
f986e111b
|
30 |
rdisplayswap = /^(none|table(?!-c[ea]).+)/, |
f986e111b
|
31 32 33 34 35 |
cssShow = { position: "absolute", visibility: "hidden", display: "block" }, cssNormalTransform = { letterSpacing: "0", fontWeight: "400" }, |
87c93a029
|
36 37 |
cssPrefixes = [ "Webkit", "Moz", "ms" ], emptyStyle = document.createElement( "div" ).style; |
f986e111b
|
38 |
|
87c93a029
|
39 40 |
// Return a css property mapped to a potentially vendor prefixed property function vendorPropName( name ) { |
f986e111b
|
41 |
|
87c93a029
|
42 43 |
// Shortcut for names that are not vendor prefixed if ( name in emptyStyle ) { |
f986e111b
|
44 45 |
return name; } |
87c93a029
|
46 47 |
// Check for vendor prefixed names var capName = name[ 0 ].toUpperCase() + name.slice( 1 ), |
f986e111b
|
48 49 50 51 |
i = cssPrefixes.length; while ( i-- ) { name = cssPrefixes[ i ] + capName; |
87c93a029
|
52 |
if ( name in emptyStyle ) { |
f986e111b
|
53 54 55 |
return name; } } |
f986e111b
|
56 57 58 |
} function setPositiveNumber( elem, value, subtract ) { |
87c93a029
|
59 60 61 62 |
// Any relative (+/-) values have already been // normalized at this point var matches = rcssNum.exec( value ); |
f986e111b
|
63 |
return matches ? |
87c93a029
|
64 |
|
f986e111b
|
65 |
// Guard against undefined "subtract", e.g., when used as in cssHooks |
87c93a029
|
66 |
Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) : |
f986e111b
|
67 68 69 70 |
value; } function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) { |
87c93a029
|
71 |
var i, |
f986e111b
|
72 |
val = 0; |
87c93a029
|
73 74 75 76 77 78 79 80 |
// If we already have the right measurement, avoid augmentation if ( extra === ( isBorderBox ? "border" : "content" ) ) { i = 4; // Otherwise initialize for horizontal or vertical properties } else { i = name === "width" ? 1 : 0; } |
f986e111b
|
81 |
for ( ; i < 4; i += 2 ) { |
87c93a029
|
82 83 |
// Both box models exclude margin, so add it if we want it |
f986e111b
|
84 85 86 87 88 |
if ( extra === "margin" ) { val += jQuery.css( elem, extra + cssExpand[ i ], true, styles ); } if ( isBorderBox ) { |
87c93a029
|
89 |
|
f986e111b
|
90 91 92 93 |
// border-box includes padding, so remove it if we want content if ( extra === "content" ) { val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); } |
87c93a029
|
94 |
// At this point, extra isn't border nor margin, so remove border |
f986e111b
|
95 96 97 98 |
if ( extra !== "margin" ) { val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); } } else { |
87c93a029
|
99 100 |
// At this point, extra isn't content, so add padding |
f986e111b
|
101 |
val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); |
87c93a029
|
102 |
// At this point, extra isn't content nor padding, so add border |
f986e111b
|
103 104 105 106 107 108 109 110 111 112 113 114 |
if ( extra !== "padding" ) { val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); } } } return val; } function getWidthOrHeight( elem, name, extra ) { // Start with offset property, which is equivalent to the border-box value |
87c93a029
|
115 116 |
var val, valueIsBorderBox = true, |
f986e111b
|
117 |
styles = getStyles( elem ), |
87c93a029
|
118 |
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box"; |
f986e111b
|
119 |
|
87c93a029
|
120 121 122 123 124 125 126 127 |
// Support: IE <=11 only // Running getBoundingClientRect on a disconnected node // in IE throws an error. if ( elem.getClientRects().length ) { val = elem.getBoundingClientRect()[ name ]; } // Some non-html elements return undefined for offsetWidth, so check for null/undefined |
f986e111b
|
128 129 130 |
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668 if ( val <= 0 || val == null ) { |
87c93a029
|
131 |
|
f986e111b
|
132 133 134 135 136 137 138 |
// Fall back to computed then uncomputed css if necessary val = curCSS( elem, name, styles ); if ( val < 0 || val == null ) { val = elem.style[ name ]; } // Computed unit is not pixels. Stop here and return. |
87c93a029
|
139 |
if ( rnumnonpx.test( val ) ) { |
f986e111b
|
140 141 |
return val; } |
87c93a029
|
142 |
// Check for style in case a browser which returns unreliable values |
f986e111b
|
143 |
// for getComputedStyle silently falls back to the reliable elem.style |
87c93a029
|
144 145 |
valueIsBorderBox = isBorderBox && ( support.boxSizingReliable() || val === elem.style[ name ] ); |
f986e111b
|
146 147 148 149 |
// Normalize "", auto, and prepare for extra val = parseFloat( val ) || 0; } |
87c93a029
|
150 |
// Use the active box-sizing model to add/subtract irrelevant styles |
f986e111b
|
151 152 153 154 155 156 157 158 159 160 |
return ( val + augmentWidthOrHeight( elem, name, extra || ( isBorderBox ? "border" : "content" ), valueIsBorderBox, styles ) ) + "px"; } |
87c93a029
|
161 |
jQuery.extend( { |
f986e111b
|
162 163 164 165 166 167 |
// Add in style property hooks for overriding the default // behavior of getting and setting a style property cssHooks: { opacity: { get: function( elem, computed ) { if ( computed ) { |
87c93a029
|
168 |
|
f986e111b
|
169 170 171 172 173 174 175 176 177 178 |
// We should always get a number back from opacity var ret = curCSS( elem, "opacity" ); return ret === "" ? "1" : ret; } } } }, // Don't automatically add "px" to these possibly-unitless properties cssNumber: { |
87c93a029
|
179 |
"animationIterationCount": true, |
f986e111b
|
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
"columnCount": true, "fillOpacity": true, "flexGrow": true, "flexShrink": true, "fontWeight": true, "lineHeight": true, "opacity": true, "order": true, "orphans": true, "widows": true, "zIndex": true, "zoom": true }, // Add in properties whose names you wish to fix before // setting or getting the value cssProps: { |
87c93a029
|
197 |
"float": "cssFloat" |
f986e111b
|
198 199 200 201 |
}, // Get and set the style property on a DOM Node style: function( elem, name, value, extra ) { |
87c93a029
|
202 |
|
f986e111b
|
203 204 205 206 207 208 209 210 211 |
// Don't set styles on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { return; } // Make sure that we're working with the right name var ret, type, hooks, origName = jQuery.camelCase( name ), style = elem.style; |
87c93a029
|
212 213 |
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName ); |
f986e111b
|
214 |
|
87c93a029
|
215 |
// Gets hook for the prefixed version, then unprefixed version |
f986e111b
|
216 217 218 219 220 |
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; // Check if we're setting a value if ( value !== undefined ) { type = typeof value; |
87c93a029
|
221 222 223 |
// Convert "+=" or "-=" to relative numbers (#7345) if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) { value = adjustCSS( elem, name, ret ); |
f986e111b
|
224 225 226 |
// Fixes bug #9237 type = "number"; } |
87c93a029
|
227 |
// Make sure that null and NaN values aren't set (#7116) |
f986e111b
|
228 229 230 |
if ( value == null || value !== value ) { return; } |
87c93a029
|
231 232 233 |
// If a number was passed in, add the unit (except for certain CSS properties) if ( type === "number" ) { value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" ); |
f986e111b
|
234 |
} |
87c93a029
|
235 236 |
// background-* props affect original clone's values if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) { |
f986e111b
|
237 238 239 240 |
style[ name ] = "inherit"; } // If a hook was provided, use that value, otherwise just set the specified value |
87c93a029
|
241 242 |
if ( !hooks || !( "set" in hooks ) || ( value = hooks.set( elem, value, extra ) ) !== undefined ) { |
f986e111b
|
243 |
|
87c93a029
|
244 |
style[ name ] = value; |
f986e111b
|
245 246 247 |
} } else { |
87c93a029
|
248 |
|
f986e111b
|
249 |
// If a hook was provided get the non-computed value from there |
87c93a029
|
250 251 |
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, false, extra ) ) !== undefined ) { |
f986e111b
|
252 253 254 255 256 257 258 259 260 |
return ret; } // Otherwise just get the value from the style object return style[ name ]; } }, css: function( elem, name, extra, styles ) { |
87c93a029
|
261 |
var val, num, hooks, |
f986e111b
|
262 263 264 |
origName = jQuery.camelCase( name ); // Make sure that we're working with the right name |
87c93a029
|
265 266 |
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName ); |
f986e111b
|
267 |
|
87c93a029
|
268 |
// Try prefixed name followed by the unprefixed name |
f986e111b
|
269 270 271 272 273 274 275 276 277 278 279 |
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; // If a hook was provided get the computed value from there if ( hooks && "get" in hooks ) { val = hooks.get( elem, true, extra ); } // Otherwise, if a way to get the computed value exists, use that if ( val === undefined ) { val = curCSS( elem, name, styles ); } |
87c93a029
|
280 |
// Convert "normal" to computed value |
f986e111b
|
281 282 283 |
if ( val === "normal" && name in cssNormalTransform ) { val = cssNormalTransform[ name ]; } |
87c93a029
|
284 |
// Make numeric if forced or a qualifier was provided and val looks numeric |
f986e111b
|
285 286 |
if ( extra === "" || extra ) { num = parseFloat( val ); |
87c93a029
|
287 |
return extra === true || isFinite( num ) ? num || 0 : val; |
f986e111b
|
288 289 290 |
} return val; } |
87c93a029
|
291 |
} ); |
f986e111b
|
292 |
|
87c93a029
|
293 |
jQuery.each( [ "height", "width" ], function( i, name ) { |
f986e111b
|
294 295 296 |
jQuery.cssHooks[ name ] = { get: function( elem, computed, extra ) { if ( computed ) { |
87c93a029
|
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
// Certain elements can have dimension info if we invisibly show them // but it must have a current display style that would benefit return rdisplayswap.test( jQuery.css( elem, "display" ) ) && // Support: Safari 8+ // Table columns in Safari have non-zero offsetWidth & zero // getBoundingClientRect().width unless display is changed. // Support: IE <=11 only // Running getBoundingClientRect on a disconnected node // in IE throws an error. ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ? swap( elem, cssShow, function() { return getWidthOrHeight( elem, name, extra ); } ) : getWidthOrHeight( elem, name, extra ); |
f986e111b
|
313 314 315 316 |
} }, set: function( elem, value, extra ) { |
87c93a029
|
317 318 319 |
var matches, styles = extra && getStyles( elem ), subtract = extra && augmentWidthOrHeight( |
f986e111b
|
320 321 322 |
elem, name, extra, |
87c93a029
|
323 |
jQuery.css( elem, "boxSizing", false, styles ) === "border-box", |
f986e111b
|
324 |
styles |
87c93a029
|
325 |
); |
f986e111b
|
326 |
|
87c93a029
|
327 328 329 330 331 332 |
// Convert to pixels if value adjustment is needed if ( subtract && ( matches = rcssNum.exec( value ) ) && ( matches[ 3 ] || "px" ) !== "px" ) { elem.style[ name ] = value; value = jQuery.css( elem, name ); |
f986e111b
|
333 |
} |
87c93a029
|
334 |
return setPositiveNumber( elem, value, subtract ); |
f986e111b
|
335 336 |
} }; |
87c93a029
|
337 |
} ); |
f986e111b
|
338 |
|
87c93a029
|
339 |
jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft, |
f986e111b
|
340 341 |
function( elem, computed ) { if ( computed ) { |
87c93a029
|
342 343 344 345 346 347 |
return ( parseFloat( curCSS( elem, "marginLeft" ) ) || elem.getBoundingClientRect().left - swap( elem, { marginLeft: 0 }, function() { return elem.getBoundingClientRect().left; } ) ) + "px"; |
f986e111b
|
348 349 350 351 352 |
} } ); // These hooks are used by animate to expand properties |
87c93a029
|
353 |
jQuery.each( { |
f986e111b
|
354 355 356 357 358 359 360 361 |
margin: "", padding: "", border: "Width" }, function( prefix, suffix ) { jQuery.cssHooks[ prefix + suffix ] = { expand: function( value ) { var i = 0, expanded = {}, |
87c93a029
|
362 363 |
// Assumes a single number if not a string parts = typeof value === "string" ? value.split( " " ) : [ value ]; |
f986e111b
|
364 365 366 367 368 369 370 371 372 373 374 375 376 |
for ( ; i < 4; i++ ) { expanded[ prefix + cssExpand[ i ] + suffix ] = parts[ i ] || parts[ i - 2 ] || parts[ 0 ]; } return expanded; } }; if ( !rmargin.test( prefix ) ) { jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber; } |
87c93a029
|
377 |
} ); |
f986e111b
|
378 |
|
87c93a029
|
379 |
jQuery.fn.extend( { |
f986e111b
|
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
css: function( name, value ) { return access( this, function( elem, name, value ) { var styles, len, map = {}, i = 0; if ( jQuery.isArray( name ) ) { styles = getStyles( elem ); len = name.length; for ( ; i < len; i++ ) { map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles ); } return map; } return value !== undefined ? jQuery.style( elem, name, value ) : jQuery.css( elem, name ); }, name, value, arguments.length > 1 ); |
f986e111b
|
401 |
} |
87c93a029
|
402 |
} ); |
f986e111b
|
403 404 |
return jQuery; |
87c93a029
|
405 |
} ); |