Skip to content

Commit

Permalink
Using parseFloat() to calculate percentage to yield more precise result.
Browse files Browse the repository at this point in the history
  • Loading branch information
5amfung committed Sep 5, 2015
1 parent ef1b600 commit 44e1190
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions js/angular/directive/collectionRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,15 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r

// If it's a constant, it's either a percent or just a constant pixel number.
if (isConstant) {
var intValue = parseInt(parsedValue());

// For percents, store the percent getter on .getValue()
if (attrValue.indexOf('%') > -1) {
var decimalValue = intValue / 100;
var decimalValue = parseFloat(parsedValue()) / 100;
dimensionData.getValue = dimensionData === heightData ?
function() { return Math.floor(decimalValue * scrollView.__clientHeight); } :
function() { return Math.floor(decimalValue * scrollView.__clientWidth); };
} else {
// For static constants, just store the static constant.
dimensionData.value = intValue;
dimensionData.value = parseInt(parsedValue());
}

} else {
Expand All @@ -357,14 +355,14 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
function heightGetter(scope, locals) {
var result = parsedValue(scope, locals);
if (result.charAt && result.charAt(result.length - 1) === '%') {
return Math.floor(parseInt(result) / 100 * scrollView.__clientHeight);
return Math.floor(parseFloat(result) / 100 * scrollView.__clientHeight);
}
return parseInt(result);
} :
function widthGetter(scope, locals) {
var result = parsedValue(scope, locals);
if (result.charAt && result.charAt(result.length - 1) === '%') {
return Math.floor(parseInt(result) / 100 * scrollView.__clientWidth);
return Math.floor(parseFloat(result) / 100 * scrollView.__clientWidth);
}
return parseInt(result);
};
Expand Down

0 comments on commit 44e1190

Please sign in to comment.