From 8747785ba06dad1510d3b870da27696e64607a9c Mon Sep 17 00:00:00 2001 From: Pavel Reznikov Date: Thu, 5 Mar 2015 23:46:59 -0800 Subject: [PATCH] add update method --- README.md | 12 ++++++++++++ src/gridstack.js | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index f7a894d..7de85dd 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Inspired by [gridster.js](http://gridster.net). Built with love. - [move(el, x, y)](#moveel-x-y) - [resizable(el, val)](#resizableel-val) - [movable(el, val)](#movableel-val) + - [update(el, x, y, width, height)](#updateel-x-y-width-height) - [will_it_fit(x, y, width, height, auto_position)](#will_it_fitx-y-width-height-auto_position) - [Utils](#utils) - [GridStackUI.Utils.sort(nodes, dir, width)](#gridstackuiutilssortnodes-dir-width) @@ -313,6 +314,16 @@ Enables/Disables moving. - `el` - widget to modify - `val` - if `true` widget will be draggable. +### update(el, x, y, width, height) + +Parameters: + +- `el` - widget to move +- `x`, `y` - new position. If value is `null` or `undefined` it will be ignored. +- `width`, `height` - new dimensions. If value is `null` or `undefined` it will be ignored. + +Updates widget position/size. + ### will_it_fit(x, y, width, height, auto_position) Returns `true` if the `height` of the grid will be less the vertical constraint. Always returns `true` if grid doesn't @@ -605,6 +616,7 @@ Changes #### v0.2.3 (development version) +- add `update` method - allow to override `resizable`/`draggable` options - add `disable`/`enable` methods - add `get_cell_from_pixel` (thanks to @juchi) diff --git a/src/gridstack.js b/src/gridstack.js index dc3624b..cae85dc 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -751,6 +751,17 @@ }); }; + GridStack.prototype.update = function (el, x, y, width, height) { + this._update_element(el, function (el, node) { + x = (x != null && typeof x != 'undefined') ? x : node.x; + y = (y != null && typeof y != 'undefined') ? y : node.y; + width = (width != null && typeof width != 'undefined') ? width : node.width; + height = (height != null && typeof height != 'undefined') ? height : node.height; + + this.grid.move_node(node, x, y, width, height); + }); + }; + GridStack.prototype.cell_height = function (val) { if (typeof val == 'undefined') { return this.opts.cell_height;