Skip to content

Commit cd9aa3a

Browse files
authored
Merge pull request #45 from rhanb/master
Fix number validation and native split behavior
2 parents 1abb08f + 052541e commit cd9aa3a

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

dist/granim.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,9 @@ function areDefinedInPixelsOrPercentage(array) {
888888
var unit, splittedValue;
889889
if (value.indexOf('px') !== -1) unit = 'px';
890890
if (value.indexOf('%') !== -1) unit = '%';
891-
splittedValue = value.split(unit);
891+
splittedValue = value.split(unit).filter(function(value) {
892+
return value.length > 0;
893+
});
892894
// Check if there is a unit ('px' or '%'),
893895
// a char before the unit,
894896
// no char after the unit,
@@ -898,7 +900,7 @@ function areDefinedInPixelsOrPercentage(array) {
898900
|| splittedValue.length > 2
899901
|| !splittedValue[0]
900902
|| splittedValue[1]
901-
|| !/^\d+$/.test(splittedValue[0])
903+
|| !/^-?\d+\.?\d*$/.test(splittedValue[0])
902904
) {
903905
definedInPixelsOrPercentage = false;
904906
}

dist/granim.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/js/vendor/granim.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/validateInput.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ function areDefinedInPixelsOrPercentage(array) {
5959
var unit, splittedValue;
6060
if (value.indexOf('px') !== -1) unit = 'px';
6161
if (value.indexOf('%') !== -1) unit = '%';
62-
splittedValue = value.split(unit);
62+
splittedValue = value.split(unit).filter(function(value) {
63+
return value.length > 0;
64+
});
6365
// Check if there is a unit ('px' or '%'),
6466
// a char before the unit,
6567
// no char after the unit,
@@ -69,7 +71,7 @@ function areDefinedInPixelsOrPercentage(array) {
6971
|| splittedValue.length > 2
7072
|| !splittedValue[0]
7173
|| splittedValue[1]
72-
|| !/^\d+$/.test(splittedValue[0])
74+
|| !/^-?\d+\.?\d*$/.test(splittedValue[0])
7375
) {
7476
definedInPixelsOrPercentage = false;
7577
}

0 commit comments

Comments
 (0)