diff --git a/demo/advance.html b/demo/advance.html index f8c157aed..9f33960f9 100644 --- a/demo/advance.html +++ b/demo/advance.html @@ -111,8 +111,8 @@

Advanced Demo

}, removable: '#trash', removeTimeout: 100, - // dragIn: '.newWidget', - // dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' }, + dragIn: '.newWidget', + dragInOptions: { revert: 'invalid', scroll: false, appendTo: 'body', helper: 'clone' }, acceptWidgets: '.newWidget' }); @@ -121,13 +121,6 @@

Advanced Demo

items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; }); console.log(e.type + ' ' + items.length + ' items:' + str ); }); - // TODO: switch jquery-ui out - $('.newWidget').draggable({ - revert: 'invalid', - scroll: false, - appendTo: 'body', - helper: 'clone' - }); diff --git a/src/gridstack-dragdrop-plugin.ts b/src/gridstack-dragdrop-plugin.ts index 33e4ef412..622ab9a0e 100644 --- a/src/gridstack-dragdrop-plugin.ts +++ b/src/gridstack-dragdrop-plugin.ts @@ -8,8 +8,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { GridStack, GridStackElement } from './gridstack'; -import { GridItemHTMLElement } from './types'; -import { DDDragInOpt } from '../dist/types'; +import { GridItemHTMLElement, DDDragInOpt } from './types'; /** Drag&Drop drop options */ export type DDDropOpt = { @@ -33,10 +32,16 @@ export class GridStackDragDropPlugin { protected grid: GridStack; static registeredPlugins: typeof GridStackDragDropPlugin[] = []; + /** call this method to register your plugin instead of the default no-op one */ static registerPlugin(pluginClass: typeof GridStackDragDropPlugin) { GridStackDragDropPlugin.registeredPlugins.push(pluginClass); } + /** get the current registered plugin to use */ + static get(): typeof GridStackDragDropPlugin { + return GridStackDragDropPlugin.registeredPlugins[0] || GridStackDragDropPlugin; + } + public constructor(grid: GridStack) { this.grid = grid; } diff --git a/src/gridstack.ts b/src/gridstack.ts index cc55e8be8..897202c58 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -213,7 +213,7 @@ export class GridStack { if (this.opts.ddPlugin === false) { this.opts.ddPlugin = GridStackDragDropPlugin; } else if (this.opts.ddPlugin === undefined) { - this.opts.ddPlugin = GridStackDragDropPlugin.registeredPlugins[0] || GridStackDragDropPlugin; + this.opts.ddPlugin = GridStackDragDropPlugin.get(); } this.dd = new (this.opts.ddPlugin as typeof GridStackDragDropPlugin)(this);