Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96d90ff

Browse files
committed
prepareDragDrop(el, force)
* added option to force re-creation of the drag&drop event binding
1 parent 90a014d commit 96d90ff

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

doc/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [11.4.0-dev (TBD)](#1140-dev-tbd)
89
- [11.4.0 (2025-02-27)](#1140-2025-02-27)
910
- [11.3.0 (2025-01-26)](#1130-2025-01-26)
1011
- [11.2.0 (2024-12-29)](#1120-2024-12-29)
@@ -121,6 +122,9 @@ Change log
121122

122123
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
123124

125+
## 11.4.0-dev (TBD)
126+
* feat: [#2960](https://github.com/gridstack/gridstack.js/pull/2960) `prepareDragDrop(el, force)` option to force re-creation of the drag&drop event binding
127+
124128
## 11.4.0 (2025-02-27)
125129
* fix: [#2921](https://github.com/gridstack/gridstack.js/pull/2921) replace initMouseEvent with MouseEvent constructor and added composed: true
126130
* fix: [#2939](https://github.com/gridstack/gridstack.js/issues/2939) custom drag handle not working with LazyLoad

doc/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ gridstack.js API
2525
- [resizestart(event, el)](#resizestartevent-el)
2626
- [resize(event, el)](#resizeevent-el)
2727
- [resizestop(event, el)](#resizestopevent-el)
28+
- [prepareDragDrop(el: GridItemHTMLElement, force = false) : GridStack](#preparedragdropel-griditemhtmlelement-force--false--gridstack)
2829
- [API Global (static)](#api-global-static)
2930
- [`init(options: GridStackOptions = {}, elOrString: GridStackElement = '.grid-stack'): GridStack`](#initoptions-gridstackoptions---elorstring-gridstackelement--grid-stack-gridstack)
3031
- [`initAll(options: GridStackOptions = {}, selector = '.grid-stack'): GridStack[]`](#initalloptions-gridstackoptions---selector--grid-stack-gridstack)
@@ -307,6 +308,11 @@ grid.on('resizestop', function(event: Event, el: GridItemHTMLElement) {
307308
});
308309
```
309310

311+
### prepareDragDrop(el: GridItemHTMLElement, force = false) : GridStack
312+
prepares the element for drag&drop - this is normally called by makeWiget() unless are are delay loading
313+
* @param el GridItemHTMLElement of the widget
314+
* @param [force=false]
315+
310316

311317
## API Global (static)
312318

src/gridstack.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,20 +2409,25 @@ export class GridStack {
24092409
return this;
24102410
}
24112411

2412-
/** prepares the element for drag&drop - this is normally called by makeWiget() unless are are delay loading */
2413-
public prepareDragDrop(el: GridItemHTMLElement): GridStack {
2412+
/**
2413+
* prepares the element for drag&drop - this is normally called by makeWiget() unless are are delay loading
2414+
* @param el GridItemHTMLElement of the widget
2415+
* @param [force=false]
2416+
* */
2417+
public prepareDragDrop(el: GridItemHTMLElement, force = false): GridStack {
24142418
const node = el.gridstackNode;
24152419
const noMove = node.noMove || this.opts.disableDrag;
24162420
const noResize = node.noResize || this.opts.disableResize;
24172421

24182422
// check for disabled grid first
2419-
if (this.opts.staticGrid || (noMove && noResize)) {
2423+
const disable = this.opts.staticGrid || (noMove && noResize);
2424+
if (force || disable) {
24202425
if (node._initDD) {
24212426
this._removeDD(el); // nukes everything instead of just disable, will add some styles back next
24222427
delete node._initDD;
24232428
}
2424-
el.classList.add('ui-draggable-disabled', 'ui-resizable-disabled'); // add styles one might depend on #1435
2425-
return this;
2429+
if (disable) el.classList.add('ui-draggable-disabled', 'ui-resizable-disabled'); // add styles one might depend on #1435
2430+
if (!force) return this;
24262431
}
24272432

24282433
if (!node._initDD) {

0 commit comments

Comments
 (0)