Skip to content

Commit 78058d9

Browse files
committed
Merge commit 'c02c2a36d18333a20081235aeba7b38ae91a3b39'
2 parents 43c400d + c02c2a3 commit 78058d9

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ Changes
454454
- add `removable`/`removeTimeout`
455455
- add `detachGrid` parameter to `destroy` method ([#216](https://github.com/troolee/gridstack.js/issues/216))
456456
- add `useOffset` parameter to `getCellFromPixel` method ([#237](https://github.com/troolee/gridstack.js/issues/237))
457+
- add `minWidth`, `maxWidth`, `minHeight`, `maxHeight`, `id` parameters to `addWidget` ([#188](https://github.com/troolee/gridstack.js/issues/188))
457458

458459
#### v0.2.4 (2016-02-15)
459460

dist/gridstack.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
createStylesheet: function(id) {
5151
var style = document.createElement('style');
5252
style.setAttribute('type', 'text/css');
53-
style.setAttribute('data-gs-id', id);
53+
style.setAttribute('data-gs-style-id', id);
5454
if (style.styleSheet) {
5555
style.styleSheet.cssText = '';
5656
} else {
@@ -61,7 +61,7 @@
6161
},
6262

6363
removeStylesheet: function(id) {
64-
$('STYLE[data-gs-id=' + id + ']').remove();
64+
$('STYLE[data-gs-style-id=' + id + ']').remove();
6565
},
6666

6767
insertCSSRule: function(sheet, selector, rules, index) {
@@ -681,7 +681,7 @@
681681

682682
GridStack.prototype._initStyles = function() {
683683
if (this._stylesId) {
684-
$('[data-gs-id="' + this._stylesId + '"]').remove();
684+
Utils.removeStylesheet(this._stylesId);
685685
}
686686
this._stylesId = 'gridstack-style-' + (Math.random() * 100000).toFixed();
687687
this._styles = Utils.createStylesheet(this._stylesId);
@@ -801,7 +801,8 @@
801801
noResize: Utils.toBool(el.attr('data-gs-no-resize')),
802802
noMove: Utils.toBool(el.attr('data-gs-no-move')),
803803
locked: Utils.toBool(el.attr('data-gs-locked')),
804-
el: el
804+
el: el,
805+
id: el.attr('data-gs-id')
805806
});
806807
el.data('_gridstack_node', node);
807808

@@ -985,13 +986,19 @@
985986
}
986987
};
987988

988-
GridStack.prototype.addWidget = function(el, x, y, width, height, autoPosition) {
989+
GridStack.prototype.addWidget = function(el, x, y, width, height, autoPosition, minWidth, maxWidth,
990+
minHeight, maxHeight, id) {
989991
el = $(el);
990992
if (typeof x != 'undefined') { el.attr('data-gs-x', x); }
991993
if (typeof y != 'undefined') { el.attr('data-gs-y', y); }
992994
if (typeof width != 'undefined') { el.attr('data-gs-width', width); }
993995
if (typeof height != 'undefined') { el.attr('data-gs-height', height); }
994996
if (typeof autoPosition != 'undefined') { el.attr('data-gs-auto-position', autoPosition ? 'yes' : null); }
997+
if (typeof minWidth != 'undefined') { el.attr('data-gs-min-width', minWidth); }
998+
if (typeof maxWidth != 'undefined') { el.attr('data-gs-max-width', maxWidth); }
999+
if (typeof minHeight != 'undefined') { el.attr('data-gs-min-height', minHeight); }
1000+
if (typeof maxHeight != 'undefined') { el.attr('data-gs-max-height', maxHeight); }
1001+
if (typeof id != 'undefined') { el.attr('data-gs-id', id); }
9951002
this.container.append(el);
9961003
this._prepareElement(el);
9971004
this._updateContainerHeight();

dist/gridstack.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gridstack.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gridstack.js API
1717
- [disable(event)](#disableevent)
1818
- [enable(event)](#enableevent)
1919
- [API](#api)
20-
- [addWidget(el, x, y, width, height, autoPosition)](#addwidgetel-x-y-width-height-autoposition)
20+
- [addWidget(el[, x, y, width, height, autoPosition, minWidth, maxWidth, minHeight, maxHeight, id])](#addwidgetel-x-y-width-height-autoposition-minwidth-maxwidth-minheight-maxheight-id)
2121
- [batchUpdate()](#batchupdate)
2222
- [cellHeight()](#cellheight)
2323
- [cellHeight(val)](#cellheightval)
@@ -174,16 +174,21 @@ $('.grid-stack').on('enable', function(event) {
174174

175175
## API
176176

177-
### addWidget(el, x, y, width, height, autoPosition)
177+
### addWidget(el[, x, y, width, height, autoPosition, minWidth, maxWidth, minHeight, maxHeight, id])
178178

179179
Creates new widget and returns it.
180180

181181
Parameters:
182182

183183
- `el` - widget to add
184-
- `x`, `y`, `width`, `height` - widget position/dimensions (Optional)
184+
- `x`, `y`, `width`, `height` - widget position/dimensions (optional)
185185
- `autoPosition` - if `true` then `x`, `y` parameters will be ignored and widget will be places on the first available
186-
position
186+
position (optional)
187+
- `minWidth` minimum width allowed during resize/creation (optional)
188+
- `maxWidth` maximum width allowed during resize/creation (optional)
189+
- `minHeight` minimum height allowed during resize/creation (optional)
190+
- `maxHeight` maximum height allowed during resize/creation (optional)
191+
- `id` value for `data-gs-id` (optional)
187192

188193
Widget will be always placed even if result height is more than actual grid height. You need to use `willItFit` method
189194
before calling `addWidget` for additional check.

src/gridstack.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
createStylesheet: function(id) {
5151
var style = document.createElement('style');
5252
style.setAttribute('type', 'text/css');
53-
style.setAttribute('data-gs-id', id);
53+
style.setAttribute('data-gs-style-id', id);
5454
if (style.styleSheet) {
5555
style.styleSheet.cssText = '';
5656
} else {
@@ -61,7 +61,7 @@
6161
},
6262

6363
removeStylesheet: function(id) {
64-
$('STYLE[data-gs-id=' + id + ']').remove();
64+
$('STYLE[data-gs-style-id=' + id + ']').remove();
6565
},
6666

6767
insertCSSRule: function(sheet, selector, rules, index) {
@@ -681,7 +681,7 @@
681681

682682
GridStack.prototype._initStyles = function() {
683683
if (this._stylesId) {
684-
$('[data-gs-id="' + this._stylesId + '"]').remove();
684+
Utils.removeStylesheet(this._stylesId);
685685
}
686686
this._stylesId = 'gridstack-style-' + (Math.random() * 100000).toFixed();
687687
this._styles = Utils.createStylesheet(this._stylesId);
@@ -801,7 +801,8 @@
801801
noResize: Utils.toBool(el.attr('data-gs-no-resize')),
802802
noMove: Utils.toBool(el.attr('data-gs-no-move')),
803803
locked: Utils.toBool(el.attr('data-gs-locked')),
804-
el: el
804+
el: el,
805+
id: el.attr('data-gs-id')
805806
});
806807
el.data('_gridstack_node', node);
807808

@@ -985,13 +986,19 @@
985986
}
986987
};
987988

988-
GridStack.prototype.addWidget = function(el, x, y, width, height, autoPosition) {
989+
GridStack.prototype.addWidget = function(el, x, y, width, height, autoPosition, minWidth, maxWidth,
990+
minHeight, maxHeight, id) {
989991
el = $(el);
990992
if (typeof x != 'undefined') { el.attr('data-gs-x', x); }
991993
if (typeof y != 'undefined') { el.attr('data-gs-y', y); }
992994
if (typeof width != 'undefined') { el.attr('data-gs-width', width); }
993995
if (typeof height != 'undefined') { el.attr('data-gs-height', height); }
994996
if (typeof autoPosition != 'undefined') { el.attr('data-gs-auto-position', autoPosition ? 'yes' : null); }
997+
if (typeof minWidth != 'undefined') { el.attr('data-gs-min-width', minWidth); }
998+
if (typeof maxWidth != 'undefined') { el.attr('data-gs-max-width', maxWidth); }
999+
if (typeof minHeight != 'undefined') { el.attr('data-gs-min-height', minHeight); }
1000+
if (typeof maxHeight != 'undefined') { el.attr('data-gs-max-height', maxHeight); }
1001+
if (typeof id != 'undefined') { el.attr('data-gs-id', id); }
9951002
this.container.append(el);
9961003
this._prepareElement(el);
9971004
this._updateContainerHeight();

0 commit comments

Comments
 (0)