Skip to content

Commit 7d362d8

Browse files
authored
Merge pull request #1170 from adumesny/develop
fix Resizing does not work as expected
2 parents 51b736b + c0e6297 commit 7d362d8

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Change log
3333

3434
## 1.0.0-dev (upcoming)
3535

36-
-- TBD
36+
-- fix [(1166)](https://github.com/gridstack/gridstack.js/issues/1166) resize not taking margin height into account
3737

3838
## v1.0.0 (2020-02-23)
3939

src/gridstack.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,19 +1209,14 @@
12091209
var self = this;
12101210

12111211
var cellWidth;
1212-
var cellHeight;
1212+
var cellFullHeight; // internal cellHeight + v-margin
12131213

12141214
var dragOrResize = function(event, ui) {
12151215
var x = Math.round(ui.position.left / cellWidth);
1216-
var y = Math.floor((ui.position.top + cellHeight / 2) / cellHeight);
1216+
var y = Math.floor((ui.position.top + cellFullHeight / 2) / cellFullHeight);
12171217
var width;
12181218
var height;
12191219

1220-
if (event.type !== 'drag') {
1221-
width = Math.round(ui.size.width / cellWidth);
1222-
height = Math.round(ui.size.height / cellHeight);
1223-
}
1224-
12251220
if (event.type === 'drag') {
12261221
var distance = ui.position.top - node._prevYPix;
12271222
node._prevYPix = ui.position.top;
@@ -1262,9 +1257,9 @@
12621257
}
12631258
}
12641259
} else if (event.type === 'resize') {
1265-
if (x < 0) {
1266-
return;
1267-
}
1260+
if (x < 0) return;
1261+
width = Math.round(ui.size.width / cellWidth);
1262+
height = Math.round((ui.size.height + self.verticalMargin()) / cellFullHeight);
12681263
}
12691264
// width and height are undefined if not resizing
12701265
var lastTriedWidth = width !== undefined ? width : node.lastTriedWidth;
@@ -1292,11 +1287,9 @@
12921287
self.engine.cleanNodes();
12931288
self.engine.beginUpdate(node);
12941289
cellWidth = self.cellWidth();
1295-
var strictCellHeight = self.cellHeight();
1296-
// TODO: cellHeight = cellHeight() causes issue (i.e. remove strictCellHeight above) otherwise
1297-
// when sizing up we jump almost right away to next size instead of half way there. Not sure
1298-
// why as we don't use ceil() in many places but round() instead.
1299-
cellHeight = (self.$el.height() + grid.verticalMargin()) / parseInt(self.$el.attr('data-gs-current-row'));
1290+
var strictCellHeight = self.cellHeight(); // heigh without v-margin
1291+
// compute height with v-margin (Note: we add 1 margin as last row is missing it)
1292+
cellFullHeight = (self.$el.height() + self.verticalMargin()) / parseInt(self.$el.attr('data-gs-current-row'));
13001293
self.placeholder
13011294
.attr('data-gs-x', o.attr('data-gs-x'))
13021295
.attr('data-gs-y', o.attr('data-gs-y'))

0 commit comments

Comments
 (0)