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

Skip to content

Commit f7e0415

Browse files
committed
Merge pull request gridstack#191 from boreal-is/master
Add a set_static method for the grid + add a static class to the container
2 parents d26a079 + c35042d commit f7e0415

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

README.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
3939
- [locked(el, val)](#lockedel-val)
4040
- [min_width(el, val)](#min_widthel-val)
4141
- [min_height(el, val)](#min_heightel-val)
42+
- [movable(el, val)](#movableel-val)
43+
- [move(el, x, y)](#moveel-x-y)
4244
- [remove_widget(el, detach_node)](#remove_widgetel-detach_node)
4345
- [remove_all()](#remove_all)
4446
- [resize(el, width, height)](#resizeel-width-height)
45-
- [move(el, x, y)](#moveel-x-y)
4647
- [resizable(el, val)](#resizableel-val)
47-
- [movable(el, val)](#movableel-val)
48+
- [set_static(val)](#set_staticstatic_value)
4849
- [update(el, x, y, width, height)](#updateel-x-y-width-height)
4950
- [will_it_fit(x, y, width, height, auto_position)](#will_it_fitx-y-width-height-auto_position)
5051
- [Utils](#utils)
@@ -132,7 +133,7 @@ $(function () {
132133
- `min_width` - minimal width. If window width is less, grid will be shown in one-column mode (default: `768`)
133134
- `placeholder_class` - class for placeholder (default: `'grid-stack-placeholder'`)
134135
- `resizable` - allows to override jQuery UI resizable options. (default: `{autoHide: true, handles: 'se'}`)
135-
- `static_grid` - makes grid static (default `false`). If true widgets are not movable/resizable. You don't even need jQueryUI draggable/resizable.
136+
- `static_grid` - makes grid static (default `false`). If true widgets are not movable/resizable. You don't even need jQueryUI draggable/resizable. A CSS class `grid-stack-static` is also added to the container.
136137
- `vertical_margin` - vertical gap size (default: `20`)
137138
- `width` - amount of columns (default: `12`)
138139

@@ -313,6 +314,22 @@ Set the minHeight for a widget.
313314
- `el` - widget to modify.
314315
- `val` - A numeric value of the number of rows
315316

317+
### movable(el, val)
318+
319+
Enables/Disables moving.
320+
321+
- `el` - widget to modify
322+
- `val` - if `true` widget will be draggable.
323+
324+
### move(el, x, y)
325+
326+
Changes widget position
327+
328+
Parameters:
329+
330+
- `el` - widget to move
331+
- `x`, `y` - new position. If value is `null` or `undefined` it will be ignored.
332+
316333
### remove_widget(el, detach_node)
317334

318335
Removes widget from the grid.
@@ -335,28 +352,18 @@ Parameters:
335352
- `el` - widget to resize
336353
- `width`, `height` - new dimensions. If value is `null` or `undefined` it will be ignored.
337354

338-
### move(el, x, y)
339-
340-
Changes widget position
341-
342-
Parameters:
343-
344-
- `el` - widget to move
345-
- `x`, `y` - new position. If value is `null` or `undefined` it will be ignored.
346-
347355
### resizable(el, val)
348356

349357
Enables/Disables resizing.
350358

351359
- `el` - widget to modify
352360
- `val` - if `true` widget will be resizable.
353361

354-
### movable(el, val)
362+
### set_static(static_value)
355363

356-
Enables/Disables moving.
364+
Toggle the grid static state. Also toggle the `grid-stack-static` class.
357365

358-
- `el` - widget to modify
359-
- `val` - if `true` widget will be draggable.
366+
- `static_value` - if `true` the grid become static.
360367

361368
### update(el, x, y, width, height)
362369

src/gridstack.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@
416416
this.opts.is_nested = is_nested;
417417

418418
this.container.addClass(this.opts._class);
419+
420+
this._set_static_class();
421+
419422
if (is_nested) {
420423
this.container.addClass('grid-stack-nested');
421424
}
@@ -946,6 +949,21 @@
946949
return this.grid.is_area_empty(x, y, width, height);
947950
};
948951

952+
GridStack.prototype.set_static = function(static_value) {
953+
this.opts.static_grid = (static_value === true);
954+
this._set_static_class();
955+
};
956+
957+
GridStack.prototype._set_static_class = function() {
958+
var static_class_name = 'grid-stack-static';
959+
960+
if (this.opts.static_grid === true) {
961+
this.container.addClass(static_class_name);
962+
} else {
963+
this.container.removeClass(static_class_name);
964+
}
965+
};
966+
949967
scope.GridStackUI = GridStack;
950968

951969
scope.GridStackUI.Utils = Utils;

0 commit comments

Comments
 (0)