Skip to content

Commit 44e1190

Browse files
committed
Using parseFloat() to calculate percentage to yield more precise result.
1 parent ef1b600 commit 44e1190

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Diff for: js/angular/directive/collectionRepeat.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,15 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
338338

339339
// If it's a constant, it's either a percent or just a constant pixel number.
340340
if (isConstant) {
341-
var intValue = parseInt(parsedValue());
342-
343341
// For percents, store the percent getter on .getValue()
344342
if (attrValue.indexOf('%') > -1) {
345-
var decimalValue = intValue / 100;
343+
var decimalValue = parseFloat(parsedValue()) / 100;
346344
dimensionData.getValue = dimensionData === heightData ?
347345
function() { return Math.floor(decimalValue * scrollView.__clientHeight); } :
348346
function() { return Math.floor(decimalValue * scrollView.__clientWidth); };
349347
} else {
350348
// For static constants, just store the static constant.
351-
dimensionData.value = intValue;
349+
dimensionData.value = parseInt(parsedValue());
352350
}
353351

354352
} else {
@@ -357,14 +355,14 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
357355
function heightGetter(scope, locals) {
358356
var result = parsedValue(scope, locals);
359357
if (result.charAt && result.charAt(result.length - 1) === '%') {
360-
return Math.floor(parseInt(result) / 100 * scrollView.__clientHeight);
358+
return Math.floor(parseFloat(result) / 100 * scrollView.__clientHeight);
361359
}
362360
return parseInt(result);
363361
} :
364362
function widthGetter(scope, locals) {
365363
var result = parsedValue(scope, locals);
366364
if (result.charAt && result.charAt(result.length - 1) === '%') {
367-
return Math.floor(parseInt(result) / 100 * scrollView.__clientWidth);
365+
return Math.floor(parseFloat(result) / 100 * scrollView.__clientWidth);
368366
}
369367
return parseInt(result);
370368
};

0 commit comments

Comments
 (0)