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

Skip to content

Commit 509bc2d

Browse files
minimize/expand wip
1 parent f5d4f33 commit 509bc2d

File tree

1 file changed

+102
-21
lines changed

1 file changed

+102
-21
lines changed

src/gridstack.js

Lines changed: 102 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@
191191
GridStackEngine.prototype._prepare_node = function(node, resizing) {
192192
node = _.defaults(node || {}, {width: 1, height: 1, x: 0, y: 0 });
193193

194-
node.x = parseInt('' + node.x);
195-
node.y = parseInt('' + node.y);
196-
node.width = parseInt('' + node.width);
197-
node.height = parseInt('' + node.height);
194+
node.x = parseInt('' + node.x, 10);
195+
node.y = parseInt('' + node.y, 10);
196+
node.width = parseInt('' + node.width, 10);
197+
node.height = parseInt('' + node.height, 10);
198198
node.auto_position = node.auto_position || false;
199199
node.no_resize = node.no_resize || false;
200200
node.no_move = node.no_move || false;
@@ -337,7 +337,7 @@
337337
if (typeof node.max_width != 'undefined') width = Math.min(width, node.max_width);
338338
if (typeof node.max_height != 'undefined') height = Math.min(height, node.max_height);
339339
if (typeof node.min_width != 'undefined') width = Math.max(width, node.min_width);
340-
if (typeof node.min_height != 'undefined') height = Math.max(height, node.min_height);
340+
if (typeof node.min_height != 'undefined') height = (node.minimized ? height : Math.max(height, node.min_height));
341341

342342
if (node.x == x && node.y == y && node.width == width && node.height == height) {
343343
return false;
@@ -384,6 +384,20 @@
384384
return columns;
385385
};
386386

387+
GridStackEngine.prototype.get_column_by_x = function(x) {
388+
var columns = this.get_nodes_by_column();
389+
return columns[x];
390+
};
391+
392+
GridStackEngine.prototype.get_node_by_coords = function(x, y) {
393+
var selected_column = this.get_column_by_x(x);
394+
if (selected_column) {
395+
var target_node = selected_column
396+
.find(function(node) { return node.y == y; });
397+
return target_node;
398+
}
399+
};
400+
387401
GridStackEngine.prototype.column_overflows = function(column) {
388402
var column_height = _(column).map(function(node) {
389403
return node.y + node.height;
@@ -412,7 +426,7 @@
412426
node.x,
413427
node.y,
414428
node.width,
415-
node.height-3)
429+
node.height-3);
416430
});
417431
}
418432
});
@@ -423,6 +437,65 @@
423437
return everything_fits;
424438
};
425439

440+
GridStackEngine.prototype.focus_on_node_at = function(x, y, minimize_others) {
441+
var target_node = this.get_node_by_coords(x, y);
442+
443+
if (minimize_others) {
444+
445+
}
446+
447+
this.expand_node(target_node);
448+
// var self = this;
449+
// var selected_column = this.get_column_by_x(x);
450+
// if (selected_column) {
451+
// var target_node = this.get_node_by_coords(x, y);
452+
//
453+
// if (target_node) {
454+
// if (minimize_others) {
455+
// selected_column
456+
// .filter(function(node) { return node.y != y; })
457+
// .forEach(function(node) {
458+
// self.minimize_node(node);
459+
// });
460+
// }
461+
//
462+
// this.move_node(target_node, x, y, target_node.width, self.height * 10, true);
463+
// }
464+
// }
465+
};
466+
467+
GridStackEngine.prototype.minimize_node_at = function(x, y) {
468+
var target_node = this.get_node_by_coords(x, y);
469+
this.minimize_node(target_node);
470+
};
471+
472+
GridStackEngine.prototype.minimize_node = function(node) {
473+
node.minimized = true;
474+
475+
node.expanded_height = node.height;
476+
node.expanded_min_height = node.min_height;
477+
478+
node.el.attr('data-gs-min-height', 5);
479+
node.min_height = 5;
480+
481+
this.move_node(node, node.x, node.y, node.width, node.min_height);
482+
};
483+
484+
GridStackEngine.prototype.expand_node = function(node) {
485+
if (node.minimized) {
486+
delete node.minimized;
487+
488+
var restore_height = node.expanded_height;
489+
delete node.expanded_height;
490+
491+
node.min_height = node.expanded_min_height;
492+
delete node.expanded_min_height;
493+
node.el.attr('data-gs-min-height', node.min_height);
494+
495+
this.move_node(node, node.x, node.y, node.width, restore_height);
496+
}
497+
};
498+
426499
GridStackEngine.prototype.begin_update = function(node) {
427500
_.each(this.nodes, function(n) {
428501
n._orig_y = n.y;
@@ -922,21 +995,21 @@
922995
};
923996

924997
GridStack.prototype.min_height = function (el, val) {
925-
el = $(el);
926-
el.each(function (index, el) {
927-
el = $(el);
928-
var node = el.data('_gridstack_node');
929-
if (typeof node == 'undefined' || node == null) {
930-
return;
931-
}
998+
el = $(el);
999+
el.each(function (index, el) {
1000+
el = $(el);
1001+
var node = el.data('_gridstack_node');
1002+
if (typeof node == 'undefined' || node == null) {
1003+
return;
1004+
}
9321005

933-
if(!isNaN(val)){
934-
node.min_height = (val || false);
935-
el.attr('data-gs-min-height', val);
936-
}
937-
});
938-
return this;
939-
};
1006+
if(!isNaN(val)){
1007+
node.min_height = (val || false);
1008+
el.attr('data-gs-min-height', val);
1009+
}
1010+
});
1011+
return this;
1012+
};
9401013

9411014
GridStack.prototype.min_width = function (el, val) {
9421015
el = $(el);
@@ -952,7 +1025,7 @@
9521025
el.attr('data-gs-min-width', val);
9531026
}
9541027
});
955-
return this;
1028+
return this;
9561029
};
9571030

9581031
GridStack.prototype._update_element = function(el, callback) {
@@ -1080,6 +1153,14 @@
10801153
return false;
10811154
};
10821155

1156+
GridStack.prototype.focus_on_node_at = function(x, y, minimize_others) {
1157+
this.grid.focus_on_node_at(x, y, minimize_others);
1158+
};
1159+
1160+
GridStack.prototype.minimize_node_at = function(x, y) {
1161+
this.grid.minimize_node_at(x, y);
1162+
};
1163+
10831164
GridStack.prototype.set_static = function(static_value) {
10841165
this.opts.static_grid = (static_value === true);
10851166
this._set_static_class();

0 commit comments

Comments
 (0)