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 9999 var height = val ;
100100 var heightUnit = 'px' ;
101101 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 ) ? $ / ) ;
103103 if ( ! match ) {
104104 throw new Error ( 'Invalid height' ) ;
105105 }
Original file line number Diff line number Diff line change @@ -91,7 +91,19 @@ describe('gridstack utils', function() {
9191 expect ( utils . parseHeight ( '12.3vw' ) ) . toEqual ( jasmine . objectContaining ( { height : 12.3 , unit : 'vw' } ) ) ;
9292 expect ( utils . parseHeight ( '12.5' ) ) . toEqual ( jasmine . objectContaining ( { height : 12.5 , unit : 'px' } ) ) ;
9393 expect ( function ( ) { utils . parseHeight ( '12.5 df' ) ; } ) . toThrowError ( 'Invalid height' ) ;
94+
9495 } ) ;
9596
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+ } ) ;
96108 } ) ;
97109} ) ;
Original file line number Diff line number Diff line change 9999 var height = val ;
100100 var heightUnit = 'px' ;
101101 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 ) ? $ / ) ;
103103 if ( ! match ) {
104104 throw new Error ( 'Invalid height' ) ;
105105 }
You can’t perform that action at this time.
0 commit comments