File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 99
99
var height = val ;
100
100
var heightUnit = 'px' ;
101
101
if ( height && _ . isString ( height ) ) {
102
- var match = height . match ( / ^ ( [ 0 - 9 ] * \. [ 0 - 9 ] + | [ 0 - 9 ] + ) ( p x | e m | r e m | v h | v w ) ? $ / ) ;
102
+ var match = height . match ( / ^ ( - [ 0 - 9 ] + \. [ 0 - 9 ] + | [ 0 - 9 ] * \. [ 0 - 9 ] + | - [ 0 - 9 ] + | [ 0 - 9 ] + ) ( p x | e m | r e m | v h | v w ) ? $ / ) ;
103
103
if ( ! match ) {
104
104
throw new Error ( 'Invalid height' ) ;
105
105
}
Original file line number Diff line number Diff line change @@ -91,7 +91,19 @@ describe('gridstack utils', function() {
91
91
expect ( utils . parseHeight ( '12.3vw' ) ) . toEqual ( jasmine . objectContaining ( { height : 12.3 , unit : 'vw' } ) ) ;
92
92
expect ( utils . parseHeight ( '12.5' ) ) . toEqual ( jasmine . objectContaining ( { height : 12.5 , unit : 'px' } ) ) ;
93
93
expect ( function ( ) { utils . parseHeight ( '12.5 df' ) ; } ) . toThrowError ( 'Invalid height' ) ;
94
+
94
95
} ) ;
95
96
97
+ it ( 'should parse negative height value' , function ( ) {
98
+ expect ( utils . parseHeight ( - 12 ) ) . toEqual ( jasmine . objectContaining ( { height : - 12 , unit : 'px' } ) ) ;
99
+ expect ( utils . parseHeight ( '-12px' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12 , unit : 'px' } ) ) ;
100
+ expect ( utils . parseHeight ( '-12.3px' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'px' } ) ) ;
101
+ expect ( utils . parseHeight ( '-12.3em' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'em' } ) ) ;
102
+ expect ( utils . parseHeight ( '-12.3rem' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'rem' } ) ) ;
103
+ expect ( utils . parseHeight ( '-12.3vh' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'vh' } ) ) ;
104
+ expect ( utils . parseHeight ( '-12.3vw' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'vw' } ) ) ;
105
+ expect ( utils . parseHeight ( '-12.5' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.5 , unit : 'px' } ) ) ;
106
+ expect ( function ( ) { utils . parseHeight ( '-12.5 df' ) ; } ) . toThrowError ( 'Invalid height' ) ;
107
+ } ) ;
96
108
} ) ;
97
109
} ) ;
Original file line number Diff line number Diff line change 99
99
var height = val ;
100
100
var heightUnit = 'px' ;
101
101
if ( height && _ . isString ( height ) ) {
102
- var match = height . match ( / ^ ( [ 0 - 9 ] * \. [ 0 - 9 ] + | [ 0 - 9 ] + ) ( p x | e m | r e m | v h | v w ) ? $ / ) ;
102
+ var match = height . match ( / ^ ( - [ 0 - 9 ] + \. [ 0 - 9 ] + | [ 0 - 9 ] * \. [ 0 - 9 ] + | - [ 0 - 9 ] + | [ 0 - 9 ] + ) ( p x | e m | r e m | v h | v w ) ? $ / ) ;
103
103
if ( ! match ) {
104
104
throw new Error ( 'Invalid height' ) ;
105
105
}
You can’t perform that action at this time.
0 commit comments