Skip to content

Commit 4933987

Browse files
committed
h5: prevent no-drop cursor when moving items
* to support html5 D&D we now allow ourself to e a drop target when moving item around, otherwise we get a 'no drop' cursor the entire move * we ignore the 'dropover' & 'drop' event so regular 'dragend' will do the right thing. * tested html5 and JQ version - no apparent side effect * Note: we still get a very quick flicker to 'no-drop' initially (until accept routine is called ? not sure how to prevent that.
1 parent e53b226 commit 4933987

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/gridstack-dd.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
110110
accept: (el: GridItemHTMLElement) => {
111111
let node: GridStackNode = el.gridstackNode;
112112
if (node && node.grid === this) {
113-
return false;
113+
return true; // set accept drop to true on ourself (which we ignore) so we don't get "can't drop" icon in HTML5 mode while moving
114114
}
115115
if (typeof this.opts.acceptWidgets === 'function') {
116116
return this.opts.acceptWidgets(el);
@@ -120,9 +120,11 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
120120
}
121121
})
122122
.on(this.el, 'dropover', (event, el: GridItemHTMLElement) => {
123+
// ignore dropping on ourself, and prevent parent from receiving event
124+
let node = el.gridstackNode || {};
125+
if (node.grid === this) { return false; }
123126

124127
// see if we already have a node with widget/height and check for attributes
125-
let node = el.gridstackNode || {};
126128
if (el.getAttribute && (!node.width || !node.height)) {
127129
let w = parseInt(el.getAttribute('data-gs-width'));
128130
if (w > 0) { node.width = w; }
@@ -166,6 +168,10 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
166168
return false; // prevent parent from receiving msg (which may be grid as well)
167169
})
168170
.on(this.el, 'drop', (event, el: GridItemHTMLElement, helper: GridItemHTMLElement) => {
171+
let node = el.gridstackNode;
172+
// ignore drop on ourself from ourself - dragend will handle the simple move instead
173+
if (node && node.grid === this) { return false; }
174+
169175
this.placeholder.remove();
170176

171177
// notify previous grid of removal
@@ -179,7 +185,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
179185
oGrid._triggerRemoveEvent();
180186
}
181187

182-
let node = el.gridstackNode; // use existing placeholder node as it's already in our list with drop location
188+
// use existing placeholder node as it's already in our list with drop location
183189
if (!node) { return false; }
184190
const _id = node._id;
185191
this.engine.cleanupNode(node); // removes all internal _xyz values (including the _id so add that back)

0 commit comments

Comments
 (0)