From 08161636932102edf8618511813a4ba9c06fcbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kremser?= Date: Sun, 28 Feb 2016 11:26:17 -0800 Subject: [PATCH 1/4] Allow negative numbers to be passed to parseHeight function --- src/gridstack.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gridstack.js b/src/gridstack.js index 6e618877c..55742ae87 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -99,7 +99,7 @@ var height = val; var heightUnit = 'px'; if (height && _.isString(height)) { - var match = height.match(/^([0-9]*\.[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/); + var match = height.match(/^((-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+)?|-?[0-9]+)(px|em|rem|vh|vw)?$/); if (!match) { throw new Error('Invalid height'); } From d20f6703c6ffb52cf23a0dcbcaa0c95f37671d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kremser?= Date: Sun, 28 Feb 2016 15:55:45 -0800 Subject: [PATCH 2/4] Allow negative numbers to be passed to parseHeight function fix --- src/gridstack.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gridstack.js b/src/gridstack.js index 55742ae87..f537d1073 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -99,7 +99,7 @@ var height = val; var heightUnit = 'px'; if (height && _.isString(height)) { - var match = height.match(/^((-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+)?|-?[0-9]+)(px|em|rem|vh|vw)?$/); + var match = height.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/); if (!match) { throw new Error('Invalid height'); } From 3ecc1caab95ed32712ed7f93e0d7d7d252555f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Kremser?= Date: Mon, 29 Feb 2016 23:53:59 -0800 Subject: [PATCH 3/4] Allow negative numbers to be passed to parseHeight function test case --- dist/gridstack.js | 2 +- spec/utils-spec.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dist/gridstack.js b/dist/gridstack.js index 6e618877c..f537d1073 100644 --- a/dist/gridstack.js +++ b/dist/gridstack.js @@ -99,7 +99,7 @@ var height = val; var heightUnit = 'px'; if (height && _.isString(height)) { - var match = height.match(/^([0-9]*\.[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/); + var match = height.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/); if (!match) { throw new Error('Invalid height'); } diff --git a/spec/utils-spec.js b/spec/utils-spec.js index d383e771b..3b2b73b48 100644 --- a/spec/utils-spec.js +++ b/spec/utils-spec.js @@ -90,8 +90,18 @@ describe('gridstack utils', function() { expect(utils.parseHeight('12.3vh')).toEqual(jasmine.objectContaining({height: 12.3, unit: 'vh'})); expect(utils.parseHeight('12.3vw')).toEqual(jasmine.objectContaining({height: 12.3, unit: 'vw'})); expect(utils.parseHeight('12.5')).toEqual(jasmine.objectContaining({height: 12.5, unit: 'px'})); - expect(function() { utils.parseHeight('12.5 df'); }).toThrowError('Invalid height'); }); + it('should parse negative height value', function() { + expect(utils.parseHeight(-12)).toEqual(jasmine.objectContaining({height: -12, unit: 'px'})); + expect(utils.parseHeight('-12px')).toEqual(jasmine.objectContaining({height: -12, unit: 'px'})); + expect(utils.parseHeight('-12.3px')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'px'})); + expect(utils.parseHeight('-12.3em')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'em'})); + expect(utils.parseHeight('-12.3rem')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'rem'})); + expect(utils.parseHeight('-12.3vh')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'vh'})); + expect(utils.parseHeight('-12.3vw')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'vw'})); + expect(utils.parseHeight('-12.5')).toEqual(jasmine.objectContaining({height: -12.5, unit: 'px'})); + expect(function() { utils.parseHeight('-12.5 df'); }).toThrowError('Invalid height'); + }); }); }); From ff0c00bc34fa67d6f36d8cdc66e767ae3aba689b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Kremser?= Date: Mon, 29 Feb 2016 23:56:17 -0800 Subject: [PATCH 4/4] Allow negative numbers to be passed to parseHeight function test case fix --- spec/utils-spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/utils-spec.js b/spec/utils-spec.js index 3b2b73b48..099276767 100644 --- a/spec/utils-spec.js +++ b/spec/utils-spec.js @@ -90,6 +90,8 @@ describe('gridstack utils', function() { expect(utils.parseHeight('12.3vh')).toEqual(jasmine.objectContaining({height: 12.3, unit: 'vh'})); expect(utils.parseHeight('12.3vw')).toEqual(jasmine.objectContaining({height: 12.3, unit: 'vw'})); expect(utils.parseHeight('12.5')).toEqual(jasmine.objectContaining({height: 12.5, unit: 'px'})); + expect(function() { utils.parseHeight('12.5 df'); }).toThrowError('Invalid height'); + }); it('should parse negative height value', function() {