@@ -194,8 +194,22 @@ export class GridStack {
194
194
/** grid options - public for classes to access, but use methods to modify! */
195
195
public opts : GridStackOptions ;
196
196
197
+ /** @internal create placeholder DIV as needed */
198
+ public get placeholder ( ) : HTMLElement {
199
+ if ( ! this . _placeholder ) {
200
+ let placeholderChild = document . createElement ( 'div' ) ; // child so padding match item-content
201
+ placeholderChild . className = 'placeholder-content' ;
202
+ if ( this . opts . placeholderText ) {
203
+ placeholderChild . innerHTML = this . opts . placeholderText ;
204
+ }
205
+ this . _placeholder = document . createElement ( 'div' ) ;
206
+ this . _placeholder . classList . add ( this . opts . placeholderClass , GridDefaults . itemClass , this . opts . itemClass ) ;
207
+ this . placeholder . appendChild ( placeholderChild ) ;
208
+ }
209
+ return this . _placeholder ;
210
+ }
197
211
/** @internal */
198
- public placeholder : HTMLElement ;
212
+ private _placeholder : HTMLElement ;
199
213
/** @internal */
200
214
private _oneColumnMode : boolean ;
201
215
/** @internal */
@@ -330,13 +344,6 @@ export class GridStack {
330
344
331
345
this . setAnimation ( this . opts . animate ) ;
332
346
333
- let placeholderChild = document . createElement ( 'div' ) ;
334
- placeholderChild . className = 'placeholder-content' ;
335
- placeholderChild . innerHTML = this . opts . placeholderText ;
336
- this . placeholder = document . createElement ( 'div' ) ;
337
- this . placeholder . classList . add ( this . opts . placeholderClass , defaults . itemClass , this . opts . itemClass ) ;
338
- this . placeholder . appendChild ( placeholderChild ) ;
339
-
340
347
this . _updateStyles ( ) ;
341
348
if ( this . opts . column != 12 ) {
342
349
this . el . classList . add ( 'grid-stack-' + this . opts . column ) ;
@@ -688,88 +695,17 @@ export class GridStack {
688
695
this . _removeStylesheet ( ) ;
689
696
delete this . opts . _isNested ;
690
697
delete this . opts ;
691
- delete this . placeholder ;
698
+ delete this . _placeholder ;
692
699
delete this . engine ;
693
700
delete this . el . gridstack ; // remove circular dependency that would prevent a freeing
694
701
delete this . el ;
695
702
return this ;
696
703
}
697
704
698
- /**
699
- * Temporarily disables widgets moving/resizing.
700
- * If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
701
- * Note: no-op for static grid
702
- * This is a shortcut for:
703
- * @example
704
- * grid.enableMove(false);
705
- * grid.enableResize(false);
706
- */
707
- public disable ( ) : GridStack {
708
- if ( this . opts . staticGrid ) return ;
709
- this . enableMove ( false ) ;
710
- this . enableResize ( false ) ;
711
- this . _triggerEvent ( 'disable' ) ;
712
- return this ;
713
- }
714
-
715
- /**
716
- * Re-enables widgets moving/resizing - see disable().
717
- * Note: no-op for static grid.
718
- * This is a shortcut for:
719
- * @example
720
- * grid.enableMove(true);
721
- * grid.enableResize(true);
722
- */
723
- public enable ( ) : GridStack {
724
- if ( this . opts . staticGrid ) return ;
725
- this . enableMove ( true ) ;
726
- this . enableResize ( true ) ;
727
- this . _triggerEvent ( 'enable' ) ;
728
- return this ;
729
- }
730
-
731
- /**
732
- * Enables/disables widget moving. No-op for static grids.
733
- *
734
- * @param doEnable
735
- * @param includeNewWidgets will force new widgets to be draggable as per
736
- * doEnable`s value by changing the disableDrag grid option (default: true).
737
- */
738
- public enableMove ( doEnable : boolean , includeNewWidgets = true ) : GridStack {
739
- if ( this . opts . staticGrid ) return this ; // can't move a static grid!
740
- this . getGridItems ( ) . forEach ( el => this . movable ( el , doEnable ) ) ;
741
- if ( includeNewWidgets ) {
742
- this . opts . disableDrag = ! doEnable ;
743
- }
744
- return this ;
745
- }
746
-
747
- /**
748
- * Enables/disables widget resizing. No-op for static grids.
749
- * @param doEnable
750
- * @param includeNewWidgets will force new widgets to be draggable as per
751
- * doEnable`s value by changing the disableResize grid option (default: true).
752
- */
753
- public enableResize ( doEnable : boolean , includeNewWidgets = true ) : GridStack {
754
- if ( this . opts . staticGrid ) return this ; // can't size a static grid!
755
- this . getGridItems ( ) . forEach ( el => this . resizable ( el , doEnable ) ) ;
756
- if ( includeNewWidgets ) {
757
- this . opts . disableResize = ! doEnable ;
758
- }
759
- return this ;
760
- }
761
-
762
705
/**
763
706
* enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
764
707
*/
765
708
public float ( val : boolean ) : GridStack {
766
- /*
767
- if (val === undefined) {
768
- // TODO: should we support and/or change signature ? figure this soon...
769
- console.warn('gridstack.ts: getter `float()` is deprecated in 2.x and has been replaced by `getFloat()`. It will be **completely** removed soon');
770
- return this.getFloat();
771
- }
772
- */
773
709
this . engine . float = val ;
774
710
this . _triggerChangeEvent ( ) ;
775
711
return this ;
@@ -1491,7 +1427,7 @@ export class GridStack {
1491
1427
* so we don't incur the load unless needed.
1492
1428
* NOTE: had to make those methods public in order to define them else as
1493
1429
* GridStack.prototype._setupAcceptWidget = function()
1494
- * maybe there is a better way....
1430
+ * maybe there is a better way ????
1495
1431
*/
1496
1432
/* eslint-disable @typescript-eslint/no-unused-vars */
1497
1433
@@ -1507,6 +1443,40 @@ export class GridStack {
1507
1443
* @param val if true widget will be resizable.
1508
1444
*/
1509
1445
public resizable ( els : GridStackElement , val : boolean ) : GridStack { return this }
1446
+ /**
1447
+ * Temporarily disables widgets moving/resizing.
1448
+ * If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
1449
+ * Note: no-op for static grid
1450
+ * This is a shortcut for:
1451
+ * @example
1452
+ * grid.enableMove(false);
1453
+ * grid.enableResize(false);
1454
+ */
1455
+ public disable ( ) : GridStack { return this }
1456
+ /**
1457
+ * Re-enables widgets moving/resizing - see disable().
1458
+ * Note: no-op for static grid.
1459
+ * This is a shortcut for:
1460
+ * @example
1461
+ * grid.enableMove(true);
1462
+ * grid.enableResize(true);
1463
+ */
1464
+ public enable ( ) : GridStack { return this }
1465
+ /**
1466
+ * Enables/disables widget moving. No-op for static grids.
1467
+ *
1468
+ * @param doEnable
1469
+ * @param includeNewWidgets will force new widgets to be draggable as per
1470
+ * doEnable`s value by changing the disableDrag grid option (default: true).
1471
+ */
1472
+ public enableMove ( doEnable : boolean , includeNewWidgets = true ) : GridStack { return this }
1473
+ /**
1474
+ * Enables/disables widget resizing. No-op for static grids.
1475
+ * @param doEnable
1476
+ * @param includeNewWidgets will force new widgets to be draggable as per
1477
+ * doEnable`s value by changing the disableResize grid option (default: true).
1478
+ */
1479
+ public enableResize ( doEnable : boolean , includeNewWidgets = true ) : GridStack { return this }
1510
1480
/** @internal called to add drag over support to support widgets */
1511
1481
public _setupAcceptWidget ( ) : GridStack { return this }
1512
1482
/** @internal called to setup a trash drop zone if the user specifies it */
@@ -1516,7 +1486,7 @@ export class GridStack {
1516
1486
/** @internal */
1517
1487
public _clearRemovingTimeout ( el : GridItemHTMLElement ) : GridStack { return this }
1518
1488
/** @internal call to setup dragging in from the outside (say toolbar), with options */
1519
- public _setupDragIn ( ) : GridStack { return this ; }
1489
+ public _setupDragIn ( ) : GridStack { return this }
1520
1490
/** @internal prepares the element for drag&drop **/
1521
1491
public _prepareDragDropByNode ( node : GridStackNode ) : GridStack { return this }
1522
1492
0 commit comments