Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9d32cd

Browse files
committed
allow to override resizable/draggable options
1 parent 409e401 commit e9d32cd

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/gridstack.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,16 @@
354354
float: false,
355355
_class: 'grid-stack-' + (Math.random() * 10000).toFixed(0),
356356
animate: Boolean(this.container.attr('data-gs-animate')) || false,
357-
always_show_resize_handle: opts.always_show_resize_handle || false
357+
always_show_resize_handle: opts.always_show_resize_handle || false,
358+
resizable: _.defaults(opts.resizable || {}, {
359+
autoHide: !(opts.always_show_resize_handle || false),
360+
handles: 'se'
361+
}),
362+
draggable: _.defaults(opts.draggable || {}, {
363+
handle: '.grid-stack-item-content',
364+
scroll: true,
365+
appendTo: 'body',
366+
})
358367
});
359368

360369
this.container.addClass(this.opts._class);
@@ -551,11 +560,7 @@
551560
self.grid.end_update();
552561
};
553562

554-
el.draggable({
555-
handle: this.opts.handle,
556-
scroll: true,
557-
appendTo: 'body',
558-
563+
el.draggable(_.extend(this.opts.draggable, {
559564
start: on_start_moving,
560565
stop: on_end_moving,
561566
drag: function (event, ui) {
@@ -567,24 +572,23 @@
567572
self.grid.move_node(node, x, y);
568573
self._update_container_height();
569574
}
570-
}).resizable({
571-
autoHide: !this.opts.always_show_resize_handle,
572-
handles: 'se',
575+
})).resizable(_.extend(this.opts.resizable, {
573576
minHeight: this.opts.cell_height - 10,
574-
minWidth: 70,
575577

576578
start: on_start_moving,
577579
stop: on_end_moving,
578580
resize: function (event, ui) {
579-
var width = Math.round(ui.size.width / cell_width),
581+
var x = Math.round(ui.position.left / cell_width),
582+
y = Math.floor((ui.position.top + cell_height/2) / cell_height),
583+
width = Math.round(ui.size.width / cell_width),
580584
height = Math.round(ui.size.height / cell_height);
581-
if (!self.grid.can_move_node(node, node.x, node.y, width, height)) {
585+
if (!self.grid.can_move_node(node, x, y, width, height)) {
582586
return;
583587
}
584-
self.grid.move_node(node, node.x, node.y, width, height);
588+
self.grid.move_node(node, x, y, width, height);
585589
self._update_container_height();
586590
}
587-
});
591+
}));
588592

589593
if (node.no_move || this._is_one_column_mode()) {
590594
el.draggable('disable');

0 commit comments

Comments
 (0)