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

Skip to content

Commit 14d7299

Browse files
committed
update gridstack.js
1 parent 8103c55 commit 14d7299

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

gridstack.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
var Utils = {
44
is_intercepted: function (a, b) {
55
return !(a.x + a.width <= b.x || b.x + b.width <= a.x || a.y + a.height <= b.y || b.y + b.height <= a.y);
6+
},
7+
8+
sort: function (nodes, dir, width) {
9+
width = width || _.chain(nodes).map(function (node) { return node.x + node.width; }).max().value();
10+
dir = dir != -1 ? 1 : -1;
11+
return _.sortBy(nodes, function (n) { return dir * (n.x + n.y * width); });
612
}
713
};
814

@@ -32,8 +38,7 @@
3238
};
3339

3440
GridStackEngine.prototype._sort_nodes = function (dir) {
35-
dir = dir != -1 ? 1 : -1;
36-
this.nodes = _.sortBy(this.nodes, function (n) { return dir * (n.x + n.y * this.width); }, this);
41+
this.nodes = Utils.sort(this.nodes, dir, this.width);
3742
};
3843

3944
GridStackEngine.prototype._pack_nodes = function () {
@@ -321,6 +326,8 @@
321326
var self = this;
322327
el = $(el);
323328

329+
el.addClass(this.opts.item_class);
330+
324331
var node = self.grid.add_node({
325332
x: el.attr('data-gs-x'),
326333
y: el.attr('data-gs-y'),
@@ -432,6 +439,14 @@
432439
this._update_container_height();
433440
};
434441

442+
GridStack.prototype.remove_all = function () {
443+
_.each(this.grid.nodes, function (node) {
444+
node.el.remove();
445+
});
446+
this.grid.nodes = [];
447+
this._update_container_height();
448+
};
449+
435450
GridStack.prototype.resizable = function (el, val) {
436451
el = $(el);
437452
el.each(function (index, el) {
@@ -518,6 +533,8 @@
518533

519534
scope.GridStackUI = GridStack;
520535

536+
scope.GridStackUI.Utils = Utils;
537+
521538
$.fn.gridstack = function (opts) {
522539
return this.each(function () {
523540
if (!$(this).data('gridstack')) {

0 commit comments

Comments
 (0)