xonecas.io
286
Sf

simple-flask-coffee-sass-boilerplate / files

simple-flask-coffee-sass-boilerplate / bower_components / jquery / src / effects / Tween.js

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