Skip to content

Commit e19628f

Browse files
authored
Merge pull request #2147 from adumesny/master
resizestop example showing correct px values
2 parents 0457a85 + d1ab89e commit e19628f

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

demo/events.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,27 @@ function addEvents(grid, id) {
4848
});
4949

5050
grid.on('resizestart', function(event, el) {
51-
let node = el.gridstackNode;
52-
let w = el.getAttribute('gs-w'); // verify node (easiest) and attr are the same
53-
let h = el.getAttribute('gs-h');
54-
console.log(g + 'resizestart ' + el.textContent + ' size: (' + node.w + 'x' + node.h + ') = (' + w + 'x' + h + ')');
51+
let n = el.gridstackNode;
52+
let w = parseInt(el.getAttribute('gs-w')); // verify node (easiest) and attr are the same
53+
let h = parseInt(el.getAttribute('gs-h'));
54+
if (w !== n.w || h !== n.h) alert('resizestart missmatch');
55+
let rec = el.getBoundingClientRect();
56+
console.log(`${g} resizestart ${el.textContent} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
57+
5558
});
5659

5760
grid.on('resize', function(event, el) {
58-
let node = el.gridstackNode;
59-
let w = el.getAttribute('gs-w'); // verify node (easiest) and attr are the same
60-
let h = el.getAttribute('gs-h');
61-
// console.log(g + 'resize ' + el.textContent + ' size: (' + node.w + 'x' + node.h + ') = (' + w + 'x' + h + ')');
61+
let n = el.gridstackNode;
62+
let rec = el.getBoundingClientRect();
63+
console.log(`${g} resize ${el.textContent} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
6264
});
6365

6466
grid.on('resizestop', function(event, el) {
65-
let node = el.gridstackNode;
66-
let w = el.getAttribute('gs-w'); // verify node (easiest) and attr are the same
67-
let h = el.getAttribute('gs-h');
68-
console.log(g + 'resizestop ' + el.textContent + ' size: (' + node.w + 'x' + node.h + ') = (' + w + 'x' + h + ')');
67+
let n = el.gridstackNode;
68+
let w = parseInt(el.getAttribute('gs-w')); // verify node (easiest) and attr are the same
69+
let h = parseInt(el.getAttribute('gs-h'));
70+
if (w !== n.w || h !== n.h) alert('resizestop missmatch');
71+
let rec = el.getBoundingClientRect();
72+
console.log(`${g} resizestop ${el.textContent} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
6973
});
7074
}

src/dd-draggable.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,14 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
303303
this.helper.classList.remove('ui-draggable-dragging');
304304
let node = (this.helper as GridItemHTMLElement)?.gridstackNode;
305305
// don't bother restoring styles if we're gonna remove anyway...
306-
if (this.dragElementOriginStyle && (!node || !node._isAboutToRemove)) {
306+
if (!node?._isAboutToRemove && this.dragElementOriginStyle) {
307307
let helper = this.helper;
308-
// don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'
308+
// don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'.
309+
// TODO: this also removes resizing animation which doesn't have this issue, but others.
310+
// Ideally both would animate ('move' would immediately restore 'absolute' and adjust coordinate to match, then trigger a delay (repaint) to restore to final dest with animate)
311+
// but then we need to make sure 'resizestop' is called AFTER 'transitionend' event is received (see https://github.com/gridstack/gridstack.js/issues/2033)
309312
let transition = this.dragElementOriginStyle['transition'] || null;
310-
helper.style.transition = this.dragElementOriginStyle['transition'] = 'none';
313+
helper.style.transition = this.dragElementOriginStyle['transition'] = 'none'; // can't be NULL #1973
311314
DDDraggable.originStyleProp.forEach(prop => helper.style[prop] = this.dragElementOriginStyle[prop] || null);
312315
setTimeout(() => helper.style.transition = transition, 50); // recover animation from saved vars after a pause (0 isn't enough #1973)
313316
}

src/gridstack.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ $animation_speed: .3s !default;
114114
&.grid-stack-animate .grid-stack-item.grid-stack-placeholder{
115115
@include vendor(transition, left 0s, top 0s, height 0s, width 0s);
116116
}
117-
118-
// without this, the html5 drag will flicker between no-drop and drop when dragging over second grid
119-
// Update: removed that as it causes nested grids to no receive dragenter events when parent drags and sets this for #992. not seeing cursor flicker (chrome).
120-
// &.ui-droppable.ui-droppable-over > *:not(.ui-droppable) {
121-
// pointer-events: none;
122-
// }
123117
}
124118

125119
.ui-draggable-dragging,

0 commit comments

Comments
 (0)