Skip to content

Commit

Permalink
Merge pull request #34 from ricpelo/patch-1
Browse files Browse the repository at this point in the history
Update jquery.maskMonkey.js with upstream fix
  • Loading branch information
kartik-v committed Jan 30, 2018
2 parents 91fdedd + af9dcb3 commit 4fe6a01
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CHANGE.md
@@ -1,6 +1,10 @@
Change Log: `yii2-money`
========================

## Development version

- (bug #33): Fix regression with empty prefix (changes from upstream).

## Version 1.2.2

**Date:** 23-May-2017
Expand Down Expand Up @@ -41,4 +45,4 @@ Change Log: `yii2-money`
**Date**: 01-Jun-2014

- PSR4 alias change
- Initial release
- Initial release
18 changes: 8 additions & 10 deletions assets/js/jquery.maskMoney.js
Expand Up @@ -517,16 +517,7 @@
return maskValueStandard(value, settings);
}

/**
* Modified by Kartik Visweswaran 23-May-2017
* for correct decimals and precision handling
*/
function maskValueStandard(value, settings) {
var v = parseFloat(value);
if (!isNaN(v)) {
value = v.toFixed(settings.precision) + '';
}

var negative = (value.indexOf("-") > -1 && settings.allowNegative) ? "-" : "",
onlyNumbers = value.replace(/[^0-9]/g, ""),
integerPart = onlyNumbers.slice(0, onlyNumbers.length - settings.precision),
Expand All @@ -535,6 +526,13 @@
newValue = buildIntegerPart(integerPart, negative, settings);

if (settings.precision > 0) {
if(!isNaN(value) && value.indexOf(".")){
var precision = value.substr(value.indexOf(".") + 1);
onlyNumbers += new Array((settings.precision + 1) - precision.length).join(0);
integerPart = onlyNumbers.slice(0, onlyNumbers.length - settings.precision);
newValue = buildIntegerPart(integerPart, negative, settings);
}

decimalPart = onlyNumbers.slice(onlyNumbers.length - settings.precision);
leadingZeros = new Array((settings.precision + 1) - decimalPart.length).join(0);
newValue += settings.decimal + leadingZeros + decimalPart;
Expand Down Expand Up @@ -589,4 +587,4 @@
$.error("Method " + method + " does not exist on jQuery.maskMoney");
}
};
})(window.jQuery || window.Zepto);
})(window.jQuery || window.Zepto);
2 changes: 1 addition & 1 deletion assets/js/jquery.maskMoney.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fe6a01

Please sign in to comment.