From 5b73939bc4a10a51c132ccb7fa78b761df53272a Mon Sep 17 00:00:00 2001 From: cvillemure Date: Mon, 20 Jul 2015 13:46:51 -0400 Subject: [PATCH] Add a API to set minWidth and minHeight to a node --- README.md | 16 ++++++++++++++++ src/gridstack.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/README.md b/README.md index 85daba2..7135ae4 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ Inspired by [gridster.js](http://gridster.net). Built with love. - [get_cell_from_pixel(position)](#get_cell_from_pixelposition) - [is_area_empty(x, y, width, height)](#is_area_emptyx-y-width-height) - [locked(el, val)](#lockedel-val) + - [min_width(el, val)](#min_widthel-val) + - [min_height(el, val)](#min_heightel-val) - [remove_widget(el, detach_node)](#remove_widgetel-detach_node) - [remove_all()](#remove_all) - [resize(el, width, height)](#resizeel-width-height) @@ -292,6 +294,20 @@ Locks/unlocks widget. - `el` - widget to modify. - `val` - if `true` widget will be locked. +### min_width(el, val) + +Set the minWidth for a widget. + +- `el` - widget to modify. +- `val` - A numeric value of the number of columns + +### min_height(el, val) + +Set the minHeight for a widget. + +- `el` - widget to modify. +- `val` - A numeric value of the number of rows + ### remove_widget(el, detach_node) Removes widget from the grid. diff --git a/src/gridstack.js b/src/gridstack.js index ab214fa..68326ed 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -797,6 +797,40 @@ return this; }; + GridStack.prototype.min_height = function (el, val) { + el = $(el); + el.each(function (index, el) { + el = $(el); + var node = el.data('_gridstack_node'); + if (typeof node == 'undefined' || node == null) { + return; + } + + if(!isNaN(val)){ + node.min_height = (val || false); + el.attr('data-gs-min-height', val); + } + }); + return this; + }; + + GridStack.prototype.min_width = function (el, val) { + el = $(el); + el.each(function (index, el) { + el = $(el); + var node = el.data('_gridstack_node'); + if (typeof node == 'undefined' || node == null) { + return; + } + + if(!isNaN(val)){ + node.min_width = (val || false); + el.attr('data-gs-min-width', val); + } + }); + return this; + }; + GridStack.prototype._update_element = function(el, callback) { el = $(el).first(); var node = el.data('_gridstack_node');