Skip to content

Commit 4a80e41

Browse files
author
Derek Moore
committed
fix ordering of draggable and resizable event callbacks
1 parent 5bbd8d5 commit 4a80e41

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/gridstack.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,22 @@
627627

628628
var cell_width, cell_height;
629629

630+
var drag_or_resize = function(event, ui) {
631+
var x = Math.round(ui.position.left / cell_width),
632+
y = Math.floor((ui.position.top + cell_height / 2) / cell_height),
633+
width, height;
634+
if (event.type != "drag") {
635+
width = Math.round(ui.size.width / cell_width);
636+
height = Math.round(ui.size.height / cell_height);
637+
}
638+
639+
if (!self.grid.can_move_node(node, x, y, width, height)) {
640+
return;
641+
}
642+
self.grid.move_node(node, x, y, width, height);
643+
self._update_container_height();
644+
};
645+
630646
var on_start_moving = function(event, ui) {
631647
self.container.append(self.placeholder);
632648
var o = $(this);
@@ -663,34 +679,17 @@
663679
self.grid.end_update();
664680
};
665681

666-
el.draggable(_.extend(this.opts.draggable, {
667-
start: on_start_moving,
668-
stop: on_end_moving,
669-
drag: function(event, ui) {
670-
var x = Math.round(ui.position.left / cell_width),
671-
y = Math.floor((ui.position.top + cell_height / 2) / cell_height);
672-
if (!self.grid.can_move_node(node, x, y, node.width, node.height)) {
673-
return;
674-
}
675-
self.grid.move_node(node, x, y);
676-
self._update_container_height();
677-
},
682+
el
683+
.draggable(_.extend(this.opts.draggable, {
678684
containment: this.opts.is_nested ? this.container.parent() : null
679-
})).resizable(_.extend(this.opts.resizable, {
680-
start: on_start_moving,
681-
stop: on_end_moving,
682-
resize: function(event, ui) {
683-
var x = Math.round(ui.position.left / cell_width),
684-
y = Math.floor((ui.position.top + cell_height / 2) / cell_height),
685-
width = Math.round(ui.size.width / cell_width),
686-
height = Math.round(ui.size.height / cell_height);
687-
if (!self.grid.can_move_node(node, x, y, width, height)) {
688-
return;
689-
}
690-
self.grid.move_node(node, x, y, width, height);
691-
self._update_container_height();
692-
}
693-
}));
685+
}))
686+
.on("dragstart", on_start_moving)
687+
.on("dragstop", on_end_moving)
688+
.on("drag", drag_or_resize)
689+
.resizable(_.extend(this.opts.resizable, {}))
690+
.on("resizestart", on_start_moving)
691+
.on("resizestop", on_end_moving)
692+
.on("resize", drag_or_resize);
694693

695694
if (node.no_move || this._is_one_column_mode()) {
696695
el.draggable('disable');

0 commit comments

Comments
 (0)