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

Skip to content

Commit dfc99b1

Browse files
committed
add move/resize API methods
1 parent 91ead4e commit dfc99b1

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/gridstack.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,50 @@
472472
return this;
473473
};
474474

475+
GridStack.prototype._update_element = function (el, callback) {
476+
el = $(el).first();
477+
var node = el.data('_gridstack_node');
478+
if (typeof node == 'undefined') {
479+
return;
480+
}
481+
482+
var self = this;
483+
484+
self.grid.clean_nodes();
485+
self.grid.begin_update(node);
486+
487+
callback.call(this, el, node);
488+
489+
self._update_container_height();
490+
self.container.trigger('change', [self.grid.get_dirty_nodes()]);
491+
492+
self.grid.end_update();
493+
494+
self.grid._sort_nodes();
495+
_.each(self.grid.nodes, function (node) {
496+
node.el.detach();
497+
self.container.append(node.el);
498+
});
499+
};
500+
501+
GridStack.prototype.resize = function (el, width, height) {
502+
this._update_element(el, function (el, node) {
503+
width = (width != null && typeof width != 'undefined') ? width : node.width;
504+
height = (height != null && typeof height != 'undefined') ? height : node.height;
505+
506+
this.grid.move_node(node, node.x, node.y, width, height);
507+
});
508+
};
509+
510+
GridStack.prototype.move = function (el, x, y) {
511+
this._update_element(el, function (el, node) {
512+
x = (x != null && typeof x != 'undefined') ? x : node.x;
513+
y = (y != null && typeof y != 'undefined') ? y : node.y;
514+
515+
this.grid.move_node(node, x, y, node.width, node.height);
516+
});
517+
};
518+
475519
scope.GridStackUI = GridStack;
476520

477521
$.fn.gridstack = function (opts) {

0 commit comments

Comments
 (0)