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

Skip to content

Commit 137ea91

Browse files
committed
add data-gs-no-move attribute
1 parent e1c7b2b commit 137ea91

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Usage
7171
- `data-gs-width`, `data-gs-height` - element size
7272
- `data-gs-max-width`, `data-gs-min-width`, `data-gs-max-height`, `data-gs-min-height` - element constraints
7373
- `data-gs-no-resize` - disable element resizing
74+
- `data-gs-no-move` - disable element moving
7475
- `data-gs-auto-position` - tells to ignore `data-gs-x` and `data-gs-y` attributes and to place element to the first
7576
available position
7677

dist/gridstack.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gridstack.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
node.width = parseInt('' + node.width);
9191
node.height = parseInt('' + node.height);
9292
node.auto_position = node.auto_position || false;
93+
node.no_resize = node.no_resize || false;
94+
node.no_move = node.no_move || false;
9395

9496
if (node.width > this.width) {
9597
node.width = this.width;
@@ -278,8 +280,10 @@
278280
one_column_mode = true;
279281

280282
_.each(self.grid.nodes, function (node) {
281-
node.el.draggable('disable');
282-
if (!node.el.attr('data-gs-no-resize')) {
283+
if (!node.no_move) {
284+
node.el.draggable('disable');
285+
}
286+
if (!node.no_resize) {
283287
node.el.resizable('disable');
284288
}
285289
});
@@ -291,8 +295,10 @@
291295
one_column_mode = false;
292296

293297
_.each(self.grid.nodes, function (node) {
294-
node.el.draggable('enable');
295-
if (!node.el.attr('data-gs-no-resize')) {
298+
if (!node.no_move) {
299+
node.el.draggable('enable');
300+
}
301+
if (!node.no_resize) {
296302
node.el.resizable('enable');
297303
}
298304
});
@@ -325,6 +331,8 @@
325331
max_height: el.attr('data-gs-max-height'),
326332
min_height: el.attr('data-gs-min-height'),
327333
auto_position: el.attr('data-gs-auto-position'),
334+
no_resize: el.attr('data-gs-no-resize'),
335+
no_move: el.attr('data-gs-no-move'),
328336
el: el
329337
});
330338
el.data('_gridstack_node', node);
@@ -367,26 +375,28 @@
367375
});
368376
};
369377

370-
el.draggable({
371-
handle: this.opts.handle,
372-
scroll: true,
373-
appendTo: 'body',
374-
375-
start: on_start_moving,
376-
stop: on_end_moving,
377-
drag: function (event, ui) {
378-
var x = Math.round(ui.position.left / cell_width),
379-
y = Math.floor(ui.position.top / cell_height);
380-
self.grid.move_node(node, x, y);
381-
self._update_container_height();
382-
}
383-
});
378+
if (!node.no_move) {
379+
el.draggable({
380+
handle: this.opts.handle,
381+
scroll: true,
382+
appendTo: 'body',
383+
384+
start: on_start_moving,
385+
stop: on_end_moving,
386+
drag: function (event, ui) {
387+
var x = Math.round(ui.position.left / cell_width),
388+
y = Math.floor(ui.position.top / cell_height);
389+
self.grid.move_node(node, x, y);
390+
self._update_container_height();
391+
}
392+
});
384393

385-
if (this._is_one_column_mode()) {
386-
el.draggable('disable');
394+
if (this._is_one_column_mode()) {
395+
el.draggable('disable');
396+
}
387397
}
388398

389-
if (!el.attr('data-gs-no-resize')) {
399+
if (!node.no_resize) {
390400
el.resizable({
391401
autoHide: true,
392402
handles: 'se',

0 commit comments

Comments
 (0)