@@ -147,18 +147,11 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
147147
148148 // set CountUp options
149149 // you don't need to do this - you can use the default options
150- var demo , code , data , stars , easingFunctions ,
150+ var demo , options , code , data , stars , easingFunctions ,
151151 useOnComplete = false ,
152152 useEasing = true ,
153153 easingFn = null ,
154- useGrouping = true ,
155- options = {
156- useEasing : useEasing , // toggle easing
157- easingFn : easingFn , // defaults to easeOutExpo, but you can specify your own
158- useGrouping : useGrouping , // 1,000,000 vs 1000000
159- separator : ',' , // character to use as a separator
160- decimal : '.' , // character to use as a decimal
161- } ;
154+ useGrouping = true ;
162155
163156 window . onload = function ( ) {
164157 // in case we're testing angular
@@ -233,10 +226,10 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
233226 easingFn : typeof easingFn === 'undefined' ? null : easingFn ,
234227 useGrouping : useGrouping ,
235228 separator : document . getElementById ( "separator" ) . value ,
236- decimal : document . getElementById ( "decimal" ) . value ,
237- prefix : prefix ,
238- suffix : suffix
229+ decimal : document . getElementById ( "decimal" ) . value
239230 } ;
231+ if ( prefix . length ) options . prefix = prefix ;
232+ if ( suffix . length ) options . suffix = suffix ;
240233
241234 // you don't have to create a new instance of CountUp every time you start an animation,
242235 // you can just change the properties individually. But I do here in case user changes values in demo.
@@ -308,17 +301,15 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
308301 startVal = Number ( startVal . replace ( ',' , '' ) . replace ( ' ' , '' ) ) ;
309302 var endVal = document . getElementById ( "endVal" ) . value ;
310303 endVal = Number ( endVal . replace ( ',' , '' ) . replace ( ' ' , '' ) ) ;
311- var decimals = document . getElementById ( "decimals" ) . value ;
312- var duration = document . getElementById ( "duration" ) . value ;
313- var separator = document . getElementById ( "separator" ) . value ;
314- var decimal = document . getElementById ( "decimal" ) . value ;
315- var prefix = document . getElementById ( "prefix" ) . value ;
316- var suffix = document . getElementById ( "suffix" ) . value ;
317-
318- var easingFn = getEasingFn ( ) ;
319- var easingFnBody = getEasingFnBody ( easingFn ) ;
320-
321- var code = '' ;
304+ var decimals = document . getElementById ( "decimals" ) . value ,
305+ duration = document . getElementById ( "duration" ) . value ,
306+ separator = document . getElementById ( "separator" ) . value ,
307+ decimal = document . getElementById ( "decimal" ) . value ,
308+ prefix = document . getElementById ( "prefix" ) . value ,
309+ suffix = document . getElementById ( "suffix" ) . value ,
310+ easingFn = getEasingFn ( ) ,
311+ easingFnBody = getEasingFnBody ( easingFn ) ,
312+ code = '' ;
322313
323314 if ( useEasing && easingFn ) {
324315 code += 'var easingFn = ' ;
@@ -335,8 +326,8 @@ <h4 class="inlineLeft noMargin weight300">Custom easing:</h4>
335326 code += ( useGrouping ) ? '  useGrouping : true, <br>' : '  useGrouping : false, <br>' ;
336327 code += '  separator : \'' + separator + '\', <br>' ;
337328 code += '  decimal : \'' + decimal + '\', <br>' ;
338- code += '  prefix : \'' + prefix + '\', <br>' ;
339- code += '  suffix : \'' + suffix + '\' <br>' ;
329+ if ( prefix . length ) code += '  prefix : \'' + prefix + '\', <br>' ;
330+ if ( suffix . length ) code += '  suffix : \'' + suffix + '\' <br>' ;
340331 code += '};<br>' ;
341332 code += 'var demo = new CountUp("myTargetElement", ' + startVal + ', ' + endVal + ', ' + decimals + ', ' + duration + ', options);<br>' ;
342333 if ( useOnComplete ) {
0 commit comments