Project

General

Profile

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,
10
		scale = 1,
11
		maxIterations = 20,
12
		currentValue = tween ?
13
			function() {
14
				return tween.cur();
15
			} :
16
			function() {
17
				return jQuery.css( elem, prop, "" );
18
			},
19
		initial = currentValue(),
20
		unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
21

    
22
		// Starting value computation is required for potential unit mismatches
23
		initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
24
			rcssNum.exec( jQuery.css( elem, prop ) );
25

    
26
	if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
27

    
28
		// Trust units reported by jQuery.css
29
		unit = unit || initialInUnit[ 3 ];
30

    
31
		// Make sure we update the tween properties later on
32
		valueParts = valueParts || [];
33

    
34
		// Iteratively approximate from a nonzero starting point
35
		initialInUnit = +initial || 1;
36

    
37
		do {
38

    
39
			// If previous iteration zeroed out, double until we get *something*.
40
			// Use string for doubling so we don't accidentally see scale as unchanged below
41
			scale = scale || ".5";
42

    
43
			// Adjust and apply
44
			initialInUnit = initialInUnit / scale;
45
			jQuery.style( elem, prop, initialInUnit + unit );
46

    
47
		// Update scale, tolerating zero or NaN from tween.cur()
48
		// Break the loop if scale is unchanged or perfect, or if we've just had enough.
49
		} while (
50
			scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations
51
		);
52
	}
53

    
54
	if ( valueParts ) {
55
		initialInUnit = +initialInUnit || +initial || 0;
56

    
57
		// Apply relative offset (+=/-=) if specified
58
		adjusted = valueParts[ 1 ] ?
59
			initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
60
			+valueParts[ 2 ];
61
		if ( tween ) {
62
			tween.unit = unit;
63
			tween.start = initialInUnit;
64
			tween.end = adjusted;
65
		}
66
	}
67
	return adjusted;
68
}
69

    
70
return adjustCSS;
71
} );
(2-2/6)