scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 58 Rev 125
1 define( [ 1 define([
2 "../core", 2 "../core",
3 "../css" 3 "../css"
4 ], function( jQuery ) { 4 ], function( jQuery ) {
5   -  
6 "use strict"; -  
7   5  
8 function Tween( elem, options, prop, end, easing ) { 6 function Tween( elem, options, prop, end, easing ) {
9 return new Tween.prototype.init( elem, options, prop, end, easing ); 7 return new Tween.prototype.init( elem, options, prop, end, easing );
10 } 8 }
11 jQuery.Tween = Tween; 9 jQuery.Tween = Tween;
12   10  
13 Tween.prototype = { 11 Tween.prototype = {
14 constructor: Tween, 12 constructor: Tween,
15 init: function( elem, options, prop, end, easing, unit ) { 13 init: function( elem, options, prop, end, easing, unit ) {
16 this.elem = elem; 14 this.elem = elem;
17 this.prop = prop; 15 this.prop = prop;
18 this.easing = easing || jQuery.easing._default; 16 this.easing = easing || "swing";
19 this.options = options; 17 this.options = options;
20 this.start = this.now = this.cur(); 18 this.start = this.now = this.cur();
21 this.end = end; 19 this.end = end;
22 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" ); 20 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
23 }, 21 },
24 cur: function() { 22 cur: function() {
25 var hooks = Tween.propHooks[ this.prop ]; 23 var hooks = Tween.propHooks[ this.prop ];
26   24  
27 return hooks && hooks.get ? 25 return hooks && hooks.get ?
28 hooks.get( this ) : 26 hooks.get( this ) :
29 Tween.propHooks._default.get( this ); 27 Tween.propHooks._default.get( this );
30 }, 28 },
31 run: function( percent ) { 29 run: function( percent ) {
32 var eased, 30 var eased,
33 hooks = Tween.propHooks[ this.prop ]; 31 hooks = Tween.propHooks[ this.prop ];
34   32  
35 if ( this.options.duration ) { 33 if ( this.options.duration ) {
36 this.pos = eased = jQuery.easing[ this.easing ]( 34 this.pos = eased = jQuery.easing[ this.easing ](
37 percent, this.options.duration * percent, 0, 1, this.options.duration 35 percent, this.options.duration * percent, 0, 1, this.options.duration
38 ); 36 );
39 } else { 37 } else {
40 this.pos = eased = percent; 38 this.pos = eased = percent;
41 } 39 }
42 this.now = ( this.end - this.start ) * eased + this.start; 40 this.now = ( this.end - this.start ) * eased + this.start;
43   41  
44 if ( this.options.step ) { 42 if ( this.options.step ) {
45 this.options.step.call( this.elem, this.now, this ); 43 this.options.step.call( this.elem, this.now, this );
46 } 44 }
47   45  
48 if ( hooks && hooks.set ) { 46 if ( hooks && hooks.set ) {
49 hooks.set( this ); 47 hooks.set( this );
50 } else { 48 } else {
51 Tween.propHooks._default.set( this ); 49 Tween.propHooks._default.set( this );
52 } 50 }
53 return this; 51 return this;
54 } 52 }
55 }; 53 };
56   54  
57 Tween.prototype.init.prototype = Tween.prototype; 55 Tween.prototype.init.prototype = Tween.prototype;
58   56  
59 Tween.propHooks = { 57 Tween.propHooks = {
60 _default: { 58 _default: {
61 get: function( tween ) { 59 get: function( tween ) {
62 var result; 60 var result;
63   -  
64 // Use a property on the element directly when it is not a DOM element, -  
65 // or when there is no matching style property that exists. 61  
66 if ( tween.elem.nodeType !== 1 || 62 if ( tween.elem[ tween.prop ] != null &&
67 tween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) { 63 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
68 return tween.elem[ tween.prop ]; 64 return tween.elem[ tween.prop ];
69 } 65 }
70   66  
71 // Passing an empty string as a 3rd parameter to .css will automatically 67 // Passing an empty string as a 3rd parameter to .css will automatically
72 // attempt a parseFloat and fallback to a string if the parse fails. 68 // attempt a parseFloat and fallback to a string if the parse fails.
73 // Simple values such as "10px" are parsed to Float; 69 // Simple values such as "10px" are parsed to Float;
74 // complex values such as "rotate(1rad)" are returned as-is. 70 // complex values such as "rotate(1rad)" are returned as-is.
75 result = jQuery.css( tween.elem, tween.prop, "" ); 71 result = jQuery.css( tween.elem, tween.prop, "" );
76   -  
77 // Empty strings, null, undefined and "auto" are converted to 0. 72 // Empty strings, null, undefined and "auto" are converted to 0.
78 return !result || result === "auto" ? 0 : result; 73 return !result || result === "auto" ? 0 : result;
79 }, 74 },
80 set: function( tween ) { 75 set: function( tween ) {
81   -  
82 // Use step hook for back compat. 76 // Use step hook for back compat.
83 // Use cssHook if its there. 77 // Use cssHook if its there.
84 // Use .style if available and use plain properties where available. 78 // Use .style if available and use plain properties where available.
85 if ( jQuery.fx.step[ tween.prop ] ) { 79 if ( jQuery.fx.step[ tween.prop ] ) {
86 jQuery.fx.step[ tween.prop ]( tween ); 80 jQuery.fx.step[ tween.prop ]( tween );
87 } else if ( tween.elem.nodeType === 1 && -  
88 ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || 81 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
89 jQuery.cssHooks[ tween.prop ] ) ) { -  
90 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit ); 82 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
91 } else { 83 } else {
92 tween.elem[ tween.prop ] = tween.now; 84 tween.elem[ tween.prop ] = tween.now;
93 } 85 }
94 } 86 }
95 } 87 }
96 }; 88 };
97   89  
98 // Support: IE <=9 only 90 // Support: IE9
99 // Panic based approach to setting things on disconnected nodes 91 // Panic based approach to setting things on disconnected nodes
100 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = { 92 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
101 set: function( tween ) { 93 set: function( tween ) {
102 if ( tween.elem.nodeType && tween.elem.parentNode ) { 94 if ( tween.elem.nodeType && tween.elem.parentNode ) {
103 tween.elem[ tween.prop ] = tween.now; 95 tween.elem[ tween.prop ] = tween.now;
104 } 96 }
105 } 97 }
106 }; 98 };
107   99  
108 jQuery.easing = { 100 jQuery.easing = {
109 linear: function( p ) { 101 linear: function( p ) {
110 return p; 102 return p;
111 }, 103 },
112 swing: function( p ) { 104 swing: function( p ) {
113 return 0.5 - Math.cos( p * Math.PI ) / 2; 105 return 0.5 - Math.cos( p * Math.PI ) / 2;
114 }, 106 }
115 _default: "swing" -  
116 }; 107 };
117   108  
118 jQuery.fx = Tween.prototype.init; 109 jQuery.fx = Tween.prototype.init;
119   110  
120 // Back compat <1.8 extension point 111 // Back Compat <1.8 extension point
121   112  
122   113  
123   114  
124   115  
125   116  
126   117  
127   118  
128   119  
129   120