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