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

Skip to content

Commit ba208c2

Browse files
committed
move sort function to Utils
1 parent 7b90af2 commit ba208c2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/gridstack.js

Lines changed: 7 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 () {

0 commit comments

Comments
 (0)