@@ -207,15 +207,9 @@ export class GridStack {
207
207
/** scoping so users can call new GridStack.Engine(12) for example */
208
208
public static Engine = GridStackEngine ;
209
209
210
- /** the HTML element tied to this grid after it's been initialized */
211
- public el : GridHTMLElement ;
212
-
213
210
/** engine used to implement non DOM grid functionality */
214
211
public engine : GridStackEngine ;
215
212
216
- /** grid options - public for classes to access, but use methods to modify! */
217
- public opts : GridStackOptions ;
218
-
219
213
/** point to a parent grid item if we're nested (inside a grid-item in between 2 Grids) */
220
214
public parentGridItem ?: GridStackNode ;
221
215
@@ -267,12 +261,11 @@ export class GridStack {
267
261
268
262
/**
269
263
* Construct a grid item from the given element and options
270
- * @param el
271
- * @param opts
264
+ * @param el the HTML element tied to this grid after it's been initialized
265
+ * @param opts grid options - public for classes to access, but use methods to modify!
272
266
*/
273
- public constructor ( el : GridHTMLElement , opts : GridStackOptions = { } ) {
267
+ public constructor ( public el : GridHTMLElement , public opts : GridStackOptions = { } ) {
274
268
el . gridstack = this ;
275
- this . el = el ; // exposed HTML element to the user
276
269
opts = opts || { } ; // handles null/undefined/0
277
270
278
271
if ( ! el . classList . contains ( 'grid-stack' ) ) {
@@ -344,18 +337,17 @@ export class GridStack {
344
337
defaults . animate = Utils . toBool ( el . getAttribute ( 'gs-animate' ) )
345
338
}
346
339
347
- this . opts = Utils . defaults ( opts , defaults ) ;
348
- opts = null ; // make sure we use this.opts instead
340
+ opts = Utils . defaults ( opts , defaults ) ;
349
341
this . _initMargin ( ) ; // part of settings defaults...
350
342
351
343
// Now check if we're loading into 1 column mode FIRST so we don't do un-necessary work (like cellHeight = width / 12 then go 1 column)
352
344
this . checkDynamicColumn ( ) ;
353
- this . el . classList . add ( 'gs-' + this . opts . column ) ;
345
+ this . el . classList . add ( 'gs-' + opts . column ) ;
354
346
355
- if ( this . opts . rtl === 'auto' ) {
356
- this . opts . rtl = ( el . style . direction === 'rtl' ) ;
347
+ if ( opts . rtl === 'auto' ) {
348
+ opts . rtl = ( el . style . direction === 'rtl' ) ;
357
349
}
358
- if ( this . opts . rtl ) {
350
+ if ( opts . rtl ) {
359
351
this . el . classList . add ( 'grid-stack-rtl' ) ;
360
352
}
361
353
@@ -369,34 +361,34 @@ export class GridStack {
369
361
parentGridItem . el . classList . add ( 'grid-stack-sub-grid' ) ;
370
362
}
371
363
372
- this . _isAutoCellHeight = ( this . opts . cellHeight === 'auto' ) ;
373
- if ( this . _isAutoCellHeight || this . opts . cellHeight === 'initial' ) {
364
+ this . _isAutoCellHeight = ( opts . cellHeight === 'auto' ) ;
365
+ if ( this . _isAutoCellHeight || opts . cellHeight === 'initial' ) {
374
366
// make the cell content square initially (will use resize/column event to keep it square)
375
367
this . cellHeight ( undefined , false ) ;
376
368
} else {
377
369
// append unit if any are set
378
- if ( typeof this . opts . cellHeight == 'number' && this . opts . cellHeightUnit && this . opts . cellHeightUnit !== gridDefaults . cellHeightUnit ) {
379
- this . opts . cellHeight = this . opts . cellHeight + this . opts . cellHeightUnit ;
380
- delete this . opts . cellHeightUnit ;
370
+ if ( typeof opts . cellHeight == 'number' && opts . cellHeightUnit && opts . cellHeightUnit !== gridDefaults . cellHeightUnit ) {
371
+ opts . cellHeight = opts . cellHeight + opts . cellHeightUnit ;
372
+ delete opts . cellHeightUnit ;
381
373
}
382
- this . cellHeight ( this . opts . cellHeight , false ) ;
374
+ this . cellHeight ( opts . cellHeight , false ) ;
383
375
}
384
376
385
377
// see if we need to adjust auto-hide
386
- if ( this . opts . alwaysShowResizeHandle === 'mobile' ) {
387
- this . opts . alwaysShowResizeHandle = isTouch ;
378
+ if ( opts . alwaysShowResizeHandle === 'mobile' ) {
379
+ opts . alwaysShowResizeHandle = isTouch ;
388
380
}
389
381
390
382
this . _styleSheetClass = 'gs-id-' + GridStackEngine . _idSeq ++ ;
391
383
this . el . classList . add ( this . _styleSheetClass ) ;
392
384
393
385
this . _setStaticClass ( ) ;
394
386
395
- let engineClass = this . opts . engineClass || GridStack . engineClass || GridStackEngine ;
387
+ let engineClass = opts . engineClass || GridStack . engineClass || GridStackEngine ;
396
388
this . engine = new engineClass ( {
397
389
column : this . getColumn ( ) ,
398
- float : this . opts . float ,
399
- maxRow : this . opts . maxRow ,
390
+ float : opts . float ,
391
+ maxRow : opts . maxRow ,
400
392
onChange : ( cbNodes ) => {
401
393
let maxH = 0 ;
402
394
this . engine . nodes . forEach ( n => { maxH = Math . max ( maxH , n . y + n . h ) } ) ;
@@ -417,25 +409,25 @@ export class GridStack {
417
409
// create initial global styles BEFORE loading children so resizeToContent margin can be calculated correctly
418
410
this . _updateStyles ( false , 0 ) ;
419
411
420
- if ( this . opts . auto ) {
412
+ if ( opts . auto ) {
421
413
this . batchUpdate ( ) ; // prevent in between re-layout #1535 TODO: this only set float=true, need to prevent collision check...
422
414
this . getGridItems ( ) . forEach ( el => this . _prepareElement ( el ) ) ;
423
415
this . batchUpdate ( false ) ;
424
416
}
425
417
426
418
// load any passed in children as well, which overrides any DOM layout done above
427
- if ( this . opts . children ) {
428
- let children = this . opts . children ;
429
- delete this . opts . children ;
419
+ if ( opts . children ) {
420
+ let children = opts . children ;
421
+ delete opts . children ;
430
422
if ( children . length ) this . load ( children ) ; // don't load empty
431
423
}
432
424
433
425
// if (this.engine.nodes.length) this._updateStyles(); // update based on # of children. done in engine onChange CB
434
- this . setAnimation ( this . opts . animate ) ;
426
+ this . setAnimation ( opts . animate ) ;
435
427
436
428
// dynamic grids require pausing during drag to detect over to nest vs push
437
- if ( this . opts . subGridDynamic && ! DDManager . pauseDrag ) DDManager . pauseDrag = true ;
438
- if ( this . opts . draggable ?. pause !== undefined ) DDManager . pauseDrag = this . opts . draggable . pause ;
429
+ if ( opts . subGridDynamic && ! DDManager . pauseDrag ) DDManager . pauseDrag = true ;
430
+ if ( opts . draggable ?. pause !== undefined ) DDManager . pauseDrag = opts . draggable . pause ;
439
431
440
432
this . _setupRemoveDrop ( ) ;
441
433
this . _setupAcceptWidget ( ) ;
0 commit comments