| 1 |
define( [ |
| 2 |
"../core", |
| 3 |
"../var/rcssNum" |
| 4 |
], function( jQuery, rcssNum ) { |
| 5 |
|
| 6 |
"use strict"; |
| 7 |
|
| 8 |
function adjustCSS( elem, prop, valueParts, tween ) { |
| 9 |
var adjusted, scale, |
| 10 |
maxIterations = 20, |
| 11 |
currentValue = tween ? |
| 12 |
function() { |
| 13 |
return tween.cur(); |
| 14 |
} : |
| 15 |
function() { |
| 16 |
return jQuery.css( elem, prop, "" ); |
| 17 |
}, |
| 18 |
initial = currentValue(), |
| 19 |
unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ), |
| 20 |
|
| 21 |
// Starting value computation is required for potential unit mismatches |
| 22 |
initialInUnit = elem.nodeType && |
| 23 |
( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) && |
| 24 |
rcssNum.exec( jQuery.css( elem, prop ) ); |
| 25 |
|
| 26 |
if ( initialInUnit && initialInUnit[ 3 ] !== unit ) { |
| 27 |
|
| 28 |
// Support: Firefox <=54 |
| 29 |
// Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144) |
| 30 |
initial = initial / 2; |
| 31 |
|
| 32 |
// Trust units reported by jQuery.css |
| 33 |
unit = unit || initialInUnit[ 3 ]; |
| 34 |
|
| 35 |
// Iteratively approximate from a nonzero starting point |
| 36 |
initialInUnit = +initial || 1; |
| 37 |
|
| 38 |
while ( maxIterations-- ) { |
| 39 |
|
| 40 |
// Evaluate and update our best guess (doubling guesses that zero out). |
| 41 |
// Finish if the scale equals or crosses 1 (making the old*new product non-positive). |
| 42 |
jQuery.style( elem, prop, initialInUnit + unit ); |
| 43 |
if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) { |
| 44 |
maxIterations = 0; |
| 45 |
} |
| 46 |
initialInUnit = initialInUnit / scale; |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
initialInUnit = initialInUnit * 2; |
| 51 |
jQuery.style( elem, prop, initialInUnit + unit ); |
| 52 |
|
| 53 |
// Make sure we update the tween properties later on |
| 54 |
valueParts = valueParts || []; |
| 55 |
} |
| 56 |
|
| 57 |
if ( valueParts ) { |
| 58 |
initialInUnit = +initialInUnit || +initial || 0; |
| 59 |
|
| 60 |
// Apply relative offset (+=/-=) if specified |
| 61 |
adjusted = valueParts[ 1 ] ? |
| 62 |
initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] : |
| 63 |
+valueParts[ 2 ]; |
| 64 |
if ( tween ) { |
| 65 |
tween.unit = unit; |
| 66 |
tween.start = initialInUnit; |
| 67 |
tween.end = adjusted; |
| 68 |
} |
| 69 |
} |
| 70 |
return adjusted; |
| 71 |
} |
| 72 |
|
| 73 |
return adjustCSS; |
| 74 |
} ); |