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

Skip to content

Commit 94b4889

Browse files
committed
add is_area_empty API method
1 parent 6eb623c commit 94b4889

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Inspired by [gridster.js](http://gridster.net). Built with love.
3434
- [disable()](#disable)
3535
- [enable()](#enable)
3636
- [get_cell_from_pixel(position)](#get_cell_from_pixelposition)
37+
- [is_area_empty(x, y, width, height)](#is_area_emptyx-y-width-height)
3738
- [locked(el, val)](#lockedel-val)
3839
- [remove_widget(el)](#remove_widgetel)
3940
- [remove_all()](#remove_all)
@@ -274,6 +275,10 @@ Parameters :
274275

275276
Returns an object with properties `x` and `y` i.e. the column and row in the grid.
276277

278+
### is_area_empty(x, y, width, height)
279+
280+
Checks if specified area is empty.
281+
277282
### locked(el, val)
278283

279284
Locks/unlocks widget.
@@ -634,6 +639,7 @@ Changes
634639

635640
#### v0.2.3 (development version)
636641

642+
- add `is_area_empty` method
637643
- nested grids
638644
- add `batch_update`/`commit` methods
639645
- add `update` method

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.

dist/gridstack.min.map

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@
107107
}
108108
};
109109

110+
GridStackEngine.prototype.is_area_empty = function (x, y, width, height) {
111+
var nn = {x: x || 0, y: y || 0, width: width || 1, height: height || 1};
112+
var collision_node = _.find(this.nodes, function (n) {
113+
return Utils.is_intercepted(n, nn);
114+
}, this);
115+
return collision_node == null;
116+
};
117+
110118
GridStackEngine.prototype._sort_nodes = function (dir) {
111119
this.nodes = Utils.sort(this.nodes, dir, this.width);
112120
};
@@ -831,6 +839,10 @@
831839
this._update_container_height()
832840
};
833841

842+
GridStack.prototype.is_area_empty = function (x, y, width, height) {
843+
return this.grid.is_area_empty(x, y, width, height);
844+
};
845+
834846
scope.GridStackUI = GridStack;
835847

836848
scope.GridStackUI.Utils = Utils;

0 commit comments

Comments
 (0)