@@ -10,6 +10,7 @@ export class GridsterOptions {
1010 heightToFontSizeRatio : number ;
1111 responsiveView : boolean ;
1212 responsiveSizes : boolean ;
13+ responsiveToParent : boolean ;
1314 dragAndDrop : boolean ;
1415 resizable : boolean ;
1516 shrink : boolean ;
@@ -23,6 +24,7 @@ export class GridsterOptions {
2324 shrink : false ,
2425 responsiveView : true ,
2526 responsiveSizes : false ,
27+ responsiveToParent : false ,
2628 dragAndDrop : true ,
2729 resizable : false ,
2830 useCSSTransforms : false ,
@@ -42,16 +44,17 @@ export class GridsterOptions {
4244 xl : 1200 // Extra large
4345 } ;
4446
45- constructor ( config : IGridsterOptions ) {
46- this . basicOptions = config ;
47+ constructor ( config : IGridsterOptions , gridsterElement : HTMLElement ) {
48+ const responsiveContainer = config . responsiveToParent ? gridsterElement : window ;
4749
50+ this . basicOptions = config ;
4851 this . responsiveOptions = this . extendResponsiveOptions ( config . responsiveOptions || [ ] ) ;
4952
5053 this . change = merge (
51- of ( this . getOptionsByWidth ( document . documentElement . clientWidth ) ) ,
54+ of ( this . getOptionsByWidth ( this . getElementWidth ( responsiveContainer ) ) ) ,
5255 fromEvent ( window , 'resize' ) . pipe (
5356 debounceTime ( config . responsiveDebounce || 0 ) ,
54- map ( ( event : Event ) => this . getOptionsByWidth ( document . documentElement . clientWidth ) )
57+ map ( ( event : Event ) => this . getOptionsByWidth ( this . getElementWidth ( responsiveContainer ) ) )
5558 )
5659 ) . pipe ( distinctUntilChanged ( null , ( options : any ) => options . minWidth ) ) ;
5760 }
@@ -83,4 +86,12 @@ export class GridsterOptions {
8386 . sort ( ( curr , next ) => curr . minWidth - next . minWidth )
8487 . map ( ( options ) => < IGridsterOptions > Object . assign ( { } , this . defaults , this . basicOptions , options ) ) ;
8588 }
89+
90+ private getElementWidth ( $element : any ) {
91+ if ( $element === window ) {
92+ return window . innerWidth || document . documentElement . clientWidth || document . body . clientWidth ;
93+ }
94+
95+ return $element . clientWidth ;
96+ }
8697}
0 commit comments