Skip to content

Commit 96ce9c0

Browse files
committed
TS: more drag&drop fix
* fixed typo, and converted adavnce.html TODO: toolbar item is removed when inserted (even though we clone).
1 parent c85575b commit 96ce9c0

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

demo/advance.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ <h1>Advanced Demo</h1>
111111
},
112112
removable: '#trash',
113113
removeTimeout: 100,
114-
// dragIn: '.newWidget',
115-
// dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' },
114+
dragIn: '.newWidget',
115+
dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' },
116116
acceptWidgets: '.newWidget'
117117
});
118118

@@ -121,13 +121,6 @@ <h1>Advanced Demo</h1>
121121
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
122122
console.log(e.type + ' ' + items.length + ' items:' + str );
123123
});
124-
// TODO: switch jquery-ui out
125-
$('.newWidget').draggable({
126-
revert: 'invalid',
127-
scroll: false,
128-
appendTo: 'body',
129-
helper: 'clone'
130-
});
131124
</script>
132125
</body>
133126

src/gridstack-dragdrop-plugin.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
/* eslint-disable @typescript-eslint/no-unused-vars */
99

1010
import { GridStack, GridStackElement } from './gridstack';
11-
import { GridItemHTMLElement } from './types';
12-
import { DDDragInOpt } from '../dist/types';
11+
import { GridItemHTMLElement, DDDragInOpt } from './types';
1312

1413
/** Drag&Drop drop options */
1514
export type DDDropOpt = {
@@ -33,10 +32,16 @@ export class GridStackDragDropPlugin {
3332
protected grid: GridStack;
3433
static registeredPlugins: typeof GridStackDragDropPlugin[] = [];
3534

35+
/** call this method to register your plugin instead of the default no-op one */
3636
static registerPlugin(pluginClass: typeof GridStackDragDropPlugin) {
3737
GridStackDragDropPlugin.registeredPlugins.push(pluginClass);
3838
}
3939

40+
/** get the current registered plugin to use */
41+
static get(): typeof GridStackDragDropPlugin {
42+
return GridStackDragDropPlugin.registeredPlugins[0] || GridStackDragDropPlugin;
43+
}
44+
4045
public constructor(grid: GridStack) {
4146
this.grid = grid;
4247
}

src/gridstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class GridStack {
213213
if (this.opts.ddPlugin === false) {
214214
this.opts.ddPlugin = GridStackDragDropPlugin;
215215
} else if (this.opts.ddPlugin === undefined) {
216-
this.opts.ddPlugin = GridStackDragDropPlugin.registeredPlugins[0] || GridStackDragDropPlugin;
216+
this.opts.ddPlugin = GridStackDragDropPlugin.get();
217217
}
218218
this.dd = new (this.opts.ddPlugin as typeof GridStackDragDropPlugin)(this);
219219

0 commit comments

Comments
 (0)