Total Complexity | 62 |
Complexity/F | 2 |
Lines of Code | 134 |
Function Count | 31 |
Duplicated Lines | 134 |
Ratio | 100 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like tests/demo/site/js/jquery.easing.1.3.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | /* |
||
39 | View Code Duplication | jQuery.easing['jswing'] = jQuery.easing['swing']; |
|
|
|||
40 | |||
41 | jQuery.extend( jQuery.easing, |
||
42 | { |
||
43 | def: 'easeOutQuad', |
||
44 | swing: function (x, t, b, c, d) { |
||
45 | //alert(jQuery.easing.default); |
||
46 | return jQuery.easing[jQuery.easing.def](x, t, b, c, d); |
||
47 | }, |
||
48 | easeInQuad: function (x, t, b, c, d) { |
||
49 | return c*(t/=d)*t + b; |
||
50 | }, |
||
51 | easeOutQuad: function (x, t, b, c, d) { |
||
52 | return -c *(t/=d)*(t-2) + b; |
||
53 | }, |
||
54 | easeInOutQuad: function (x, t, b, c, d) { |
||
55 | if ((t/=d/2) < 1) return c/2*t*t + b; |
||
56 | return -c/2 * ((--t)*(t-2) - 1) + b; |
||
57 | }, |
||
58 | easeInCubic: function (x, t, b, c, d) { |
||
59 | return c*(t/=d)*t*t + b; |
||
60 | }, |
||
61 | easeOutCubic: function (x, t, b, c, d) { |
||
62 | return c*((t=t/d-1)*t*t + 1) + b; |
||
63 | }, |
||
64 | easeInOutCubic: function (x, t, b, c, d) { |
||
65 | if ((t/=d/2) < 1) return c/2*t*t*t + b; |
||
66 | return c/2*((t-=2)*t*t + 2) + b; |
||
67 | }, |
||
68 | easeInQuart: function (x, t, b, c, d) { |
||
69 | return c*(t/=d)*t*t*t + b; |
||
70 | }, |
||
71 | easeOutQuart: function (x, t, b, c, d) { |
||
72 | return -c * ((t=t/d-1)*t*t*t - 1) + b; |
||
73 | }, |
||
74 | easeInOutQuart: function (x, t, b, c, d) { |
||
75 | if ((t/=d/2) < 1) return c/2*t*t*t*t + b; |
||
76 | return -c/2 * ((t-=2)*t*t*t - 2) + b; |
||
77 | }, |
||
78 | easeInQuint: function (x, t, b, c, d) { |
||
79 | return c*(t/=d)*t*t*t*t + b; |
||
80 | }, |
||
81 | easeOutQuint: function (x, t, b, c, d) { |
||
82 | return c*((t=t/d-1)*t*t*t*t + 1) + b; |
||
83 | }, |
||
84 | easeInOutQuint: function (x, t, b, c, d) { |
||
85 | if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; |
||
86 | return c/2*((t-=2)*t*t*t*t + 2) + b; |
||
87 | }, |
||
88 | easeInSine: function (x, t, b, c, d) { |
||
89 | return -c * Math.cos(t/d * (Math.PI/2)) + c + b; |
||
90 | }, |
||
91 | easeOutSine: function (x, t, b, c, d) { |
||
92 | return c * Math.sin(t/d * (Math.PI/2)) + b; |
||
93 | }, |
||
94 | easeInOutSine: function (x, t, b, c, d) { |
||
95 | return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; |
||
96 | }, |
||
97 | easeInExpo: function (x, t, b, c, d) { |
||
98 | return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; |
||
99 | }, |
||
100 | easeOutExpo: function (x, t, b, c, d) { |
||
101 | return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; |
||
102 | }, |
||
103 | easeInOutExpo: function (x, t, b, c, d) { |
||
104 | if (t==0) return b; |
||
105 | if (t==d) return b+c; |
||
106 | if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; |
||
107 | return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; |
||
108 | }, |
||
109 | easeInCirc: function (x, t, b, c, d) { |
||
110 | return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; |
||
111 | }, |
||
112 | easeOutCirc: function (x, t, b, c, d) { |
||
113 | return c * Math.sqrt(1 - (t=t/d-1)*t) + b; |
||
114 | }, |
||
115 | easeInOutCirc: function (x, t, b, c, d) { |
||
116 | if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; |
||
117 | return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; |
||
118 | }, |
||
119 | easeInElastic: function (x, t, b, c, d) { |
||
120 | var s=1.70158;var p=0;var a=c; |
||
121 | if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; |
||
122 | if (a < Math.abs(c)) { a=c; var s=p/4; } |
||
123 | else var s = p/(2*Math.PI) * Math.asin (c/a); |
||
124 | return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; |
||
125 | }, |
||
126 | easeOutElastic: function (x, t, b, c, d) { |
||
127 | var s=1.70158;var p=0;var a=c; |
||
128 | if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; |
||
129 | if (a < Math.abs(c)) { a=c; var s=p/4; } |
||
130 | else var s = p/(2*Math.PI) * Math.asin (c/a); |
||
131 | return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; |
||
132 | }, |
||
133 | easeInOutElastic: function (x, t, b, c, d) { |
||
134 | var s=1.70158;var p=0;var a=c; |
||
135 | if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); |
||
136 | if (a < Math.abs(c)) { a=c; var s=p/4; } |
||
137 | else var s = p/(2*Math.PI) * Math.asin (c/a); |
||
138 | if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; |
||
139 | return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; |
||
140 | }, |
||
141 | easeInBack: function (x, t, b, c, d, s) { |
||
142 | if (s == undefined) s = 1.70158; |
||
143 | return c*(t/=d)*t*((s+1)*t - s) + b; |
||
144 | }, |
||
145 | easeOutBack: function (x, t, b, c, d, s) { |
||
146 | if (s == undefined) s = 1.70158; |
||
147 | return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; |
||
148 | }, |
||
149 | easeInOutBack: function (x, t, b, c, d, s) { |
||
150 | if (s == undefined) s = 1.70158; |
||
151 | if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; |
||
152 | return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; |
||
153 | }, |
||
154 | easeInBounce: function (x, t, b, c, d) { |
||
155 | return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b; |
||
156 | }, |
||
157 | easeOutBounce: function (x, t, b, c, d) { |
||
158 | if ((t/=d) < (1/2.75)) { |
||
159 | return c*(7.5625*t*t) + b; |
||
160 | } else if (t < (2/2.75)) { |
||
161 | return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; |
||
162 | } else if (t < (2.5/2.75)) { |
||
163 | return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; |
||
164 | } else { |
||
165 | return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; |
||
166 | } |
||
167 | }, |
||
168 | easeInOutBounce: function (x, t, b, c, d) { |
||
169 | if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b; |
||
170 | return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b; |
||
171 | } |
||
172 | }); |
||
173 | |||
205 | */ |