|
3 | 3 | var Utils = {
|
4 | 4 | is_intercepted: function (a, b) {
|
5 | 5 | 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); }); |
6 | 12 | }
|
7 | 13 | };
|
8 | 14 |
|
|
32 | 38 | };
|
33 | 39 |
|
34 | 40 | 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); |
37 | 42 | };
|
38 | 43 |
|
39 | 44 | GridStackEngine.prototype._pack_nodes = function () {
|
|
321 | 326 | var self = this;
|
322 | 327 | el = $(el);
|
323 | 328 |
|
| 329 | + el.addClass(this.opts.item_class); |
| 330 | + |
324 | 331 | var node = self.grid.add_node({
|
325 | 332 | x: el.attr('data-gs-x'),
|
326 | 333 | y: el.attr('data-gs-y'),
|
|
432 | 439 | this._update_container_height();
|
433 | 440 | };
|
434 | 441 |
|
| 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 | + |
435 | 450 | GridStack.prototype.resizable = function (el, val) {
|
436 | 451 | el = $(el);
|
437 | 452 | el.each(function (index, el) {
|
|
518 | 533 |
|
519 | 534 | scope.GridStackUI = GridStack;
|
520 | 535 |
|
| 536 | + scope.GridStackUI.Utils = Utils; |
| 537 | + |
521 | 538 | $.fn.gridstack = function (opts) {
|
522 | 539 | return this.each(function () {
|
523 | 540 | if (!$(this).data('gridstack')) {
|
|
0 commit comments