Skip to content

Commit fffdfaf

Browse files
author
Alain Dumesny
committed
change grid prop to 'column' & 'maxRow' (singular)
1 parent a4e62e2 commit fffdfaf

File tree

9 files changed

+61
-61
lines changed

9 files changed

+61
-61
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ If you're still experiencing issues on touch devices please check [#444](https:/
177177

178178
GridStack makes it very easy if you need [1-12] columns out of the box (default is 12), but you always need **2 things** if you need to customize this:
179179

180-
1) Change the `columns` grid option when creating a grid to your number N
180+
1) Change the `column` grid option when creating a grid to your number N
181181
```js
182-
$('.grid-stack').gridstack( {columns: N} );
182+
$('.grid-stack').gridstack( {column: N} );
183183
```
184184

185185
2) and change your HTML accordingly if **N < 12** (else custom CSS section next). Without this, things will not render/work correctly.

demo/two.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h1>Two grids demo</h1>
106106
<script type="text/javascript">
107107
$(function () {
108108
var options = {
109-
columns: 6,
109+
column: 6,
110110
float: false,
111111
removable: '.trash',
112112
removeTimeout: 100,

doc/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Change log
2424

2525
## v0.5.2-dev (upcoming changes)
2626

27-
- grid options `width` is now `columns`, and `height` is now `maxRows` which match what they are. Old names are still supported for now (with console warnings). Also various fixes for custom # of columns and re-wrote entire doc section ([#1053](https://github.com/gridstack/gridstack.js/issues/1053)).
27+
- grid options `width` is now `column`, and `height` is now `maxRow` which match what they are. Old names are still supported for now (with console warnings). Also various fixes for custom # of column and re-wrote entire doc section ([#1053](https://github.com/gridstack/gridstack.js/issues/1053)).
2828
- fix widgets not animating when animate: true is used. on every move, styles were recreated-fix should slightly improve gridstack.js speed ([#937](https://github.com/gridstack/gridstack.js/issues/937)).
2929
- fix moving widgets when having multiple grids. jquery-ui workaround ([#1043](https://github.com/gridstack/gridstack.js/issues/1043)).
3030
- switch to eslint ([#763](https://github.com/gridstack/gridstack.js/issues/763)).

doc/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ gridstack.js API
7777
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: false, appendTo: 'body'}`)
7878
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
7979
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
80-
- `columns` - amount of columns (default: `12`)
81-
- `maxRows` - maximum rows amount. Default is `0` which means no maximum rows
80+
- `column` - amount of columns (default: `12`)
81+
- `maxRow` - maximum rows amount. Default is `0` which means no maximum rows
8282
- `float` - enable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
8383
- `itemClass` - widget class (default: `'grid-stack-item'`)
8484
- `minWidth` - minimal width. If window width is less than or equal to, grid will be shown in one-column mode (default: `768`)
@@ -98,8 +98,8 @@ gridstack.js API
9898
## Grid attributes
9999

100100
- `data-gs-animate` - turns animation on
101-
- `data-gs-columns` - amount of columns. Setting non-default value must be supported by equivalent change in CSS, [see docs here](https://github.com/gridstack/gridstack.js#change-grid-columns).
102-
- `data-gs-maxRows` - maximum rows amount. Default is `0` which means no maximum rows.
101+
- `data-gs-column` - amount of columns. Setting non-default value must be supported by equivalent change in CSS, [see docs here](https://github.com/gridstack/gridstack.js#change-grid-columns).
102+
- `data-gs-max-row` - maximum rows amount. Default is `0` which means no maximum rows.
103103
- `data-gs-current-height` - current rows amount. Set by the library only. Can be used by the CSS rules.
104104

105105
## Item attributes

spec/e2e/html/810-many-columns.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h1>Many Columns demo</h1>
4949
const COLUMNS = 30; // # of columns, also need to update CSS
5050
var count = 0;
5151
var options = {
52-
columns: COLUMNS,
52+
column: COLUMNS,
5353
cellHeight: 'auto',
5454
float: false
5555
};

spec/gridstack-engine-spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('gridstack engine', function() {
1717
});
1818

1919
it('should be setup properly', function() {
20-
expect(engine.columns).toEqual(12);
20+
expect(engine.column).toEqual(12);
2121
expect(engine.float).toEqual(false);
22-
expect(engine.maxRows).toEqual(0);
22+
expect(engine.maxRow).toEqual(0);
2323
expect(engine.nodes).toEqual([]);
2424
});
2525
});

spec/gridstack-spec.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ describe('gridstack', function() {
3131

3232
it('should set default params correctly.', function() {
3333
e.call(w);
34-
expect(w.columns).toBeUndefined();
34+
expect(w.column).toBeUndefined();
3535
expect(w.float).toBe(false);
36-
expect(w.maxRows).toEqual(0);
36+
expect(w.maxRow).toEqual(0);
3737
expect(w.nodes).toEqual([]);
3838
expect(typeof w.onchange).toBe('function');
3939
expect(w._updateCounter).toEqual(0);
@@ -45,9 +45,9 @@ describe('gridstack', function() {
4545
var arr = [1,2,3];
4646

4747
e.call(w, 1, fkt, true, 2, arr);
48-
expect(w.columns).toEqual(1);
48+
expect(w.column).toEqual(1);
4949
expect(w.float).toBe(true);
50-
expect(w.maxRows).toEqual(2);
50+
expect(w.maxRow).toEqual(2);
5151
expect(w.nodes).toEqual(arr);
5252
expect(w.onchange).toEqual(fkt);
5353
expect(w._updateCounter).toEqual(0);
@@ -84,14 +84,14 @@ describe('gridstack', function() {
8484
});
8585

8686
it('should sort ascending without columns.', function() {
87-
w.columns = undefined;
87+
w.column = undefined;
8888
w.nodes = [{x: 7, y: 0, width: 1}, {x: 4, y: 4, width: 1}, {x: 9, y: 0, width: 1}, {x: 0, y: 1, width: 1}];
8989
e.prototype._sortNodes.call(w, 1);
9090
expect(w.nodes).toEqual([{x: 7, y: 0, width: 1}, {x: 9, y: 0, width: 1}, {x: 0, y: 1, width: 1}, {x: 4, y: 4, width: 1}]);
9191
});
9292

9393
it('should sort descending without columns.', function() {
94-
w.columns = undefined;
94+
w.column = undefined;
9595
w.nodes = [{x: 7, y: 0, width: 1}, {x: 4, y: 4, width: 1}, {x: 9, y: 0, width: 1}, {x: 0, y: 1, width: 1}];
9696
e.prototype._sortNodes.call(w, -1);
9797
expect(w.nodes).toEqual([{x: 4, y: 4, width: 1}, {x: 0, y: 1, width: 1}, {x: 9, y: 0, width: 1}, {x: 7, y: 0, width: 1}]);
@@ -220,7 +220,7 @@ describe('gridstack', function() {
220220
var options = {
221221
cellHeight: 80,
222222
verticalMargin: 10,
223-
columns: 12
223+
column: 12
224224
};
225225
$('.grid-stack').gridstack(options);
226226
var grid = $('.grid-stack').data('gridstack');
@@ -231,7 +231,7 @@ describe('gridstack', function() {
231231
var options = {
232232
cellHeight: 80,
233233
verticalMargin: 10,
234-
columns: 10
234+
column: 10
235235
};
236236
$('.grid-stack').gridstack(options);
237237
var grid = $('.grid-stack').data('gridstack');
@@ -251,7 +251,7 @@ describe('gridstack', function() {
251251
var options = {
252252
cellHeight: 80,
253253
verticalMargin: 10,
254-
columns: 12
254+
column: 12
255255
};
256256
$('.grid-stack').gridstack(options);
257257
var grid = $('.grid-stack').data('gridstack');
@@ -262,7 +262,7 @@ describe('gridstack', function() {
262262
var options = {
263263
cellHeight: 80,
264264
verticalMargin: 10,
265-
columns: 10
265+
column: 10
266266
};
267267
$('.grid-stack').gridstack(options);
268268
var grid = $('.grid-stack').data('gridstack');

src/gridstack.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,14 @@ interface GridstackOptions {
437437
handleClass?: string;
438438

439439
/**
440-
* number of columns (default?: 12). Note: IF you change this, CSS also have to change. See https://github.com/gridstack/gridstack.js#change-grid-columns
440+
* number of columns (default?: 12). Note: IF you change this, CSS also have to change. See https://github.com/gridstack/gridstack.js#change-grid-columns
441441
*/
442-
columns?: number;
442+
column?: number;
443443

444444
/**
445445
* maximum rows amount. Default? is 0 which means no maximum rows
446446
*/
447-
maxRows?: number;
447+
maxRow?: number;
448448

449449
/**
450450
* enable floating widgets (default?: false) See example (http://gridstack.github.io/gridstack.js/demo/float.html)

src/gridstack.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@
295295

296296
var idSeq = 0;
297297

298-
var GridStackEngine = function(columns, onchange, floatMode, maxRows, items) {
299-
this.columns = columns;
298+
var GridStackEngine = function(column, onchange, floatMode, maxRow, items) {
299+
this.column = column;
300300
this.float = floatMode || false;
301-
this.maxRows = maxRows || 0;
301+
this.maxRow = maxRow || 0;
302302

303303
this.nodes = items || [];
304304
this.onchange = onchange || function() {};
@@ -336,7 +336,7 @@
336336
var nn = node;
337337
var hasLocked = Boolean(this.nodes.find(function(n) { return n.locked; }));
338338
if (!this.float && !hasLocked) {
339-
nn = {x: 0, y: node.y, width: this.columns, height: node.height};
339+
nn = {x: 0, y: node.y, width: this.column, height: node.height};
340340
}
341341
while (true) {
342342
var collisionNode = this.nodes.find(Utils._collisionNodeCheck, {node: node, nn: nn});
@@ -355,7 +355,7 @@
355355
};
356356

357357
GridStackEngine.prototype._sortNodes = function(dir) {
358-
this.nodes = Utils.sort(this.nodes, dir, this.columns);
358+
this.nodes = Utils.sort(this.nodes, dir, this.column);
359359
};
360360

361361
GridStackEngine.prototype._packNodes = function() {
@@ -432,8 +432,8 @@
432432
if (Number.isNaN(node.width)) { node.width = defaults.width; }
433433
if (Number.isNaN(node.height)) { node.height = defaults.height; }
434434

435-
if (node.width > this.columns) {
436-
node.width = this.columns;
435+
if (node.width > this.column) {
436+
node.width = this.column;
437437
} else if (node.width < 1) {
438438
node.width = 1;
439439
}
@@ -446,11 +446,11 @@
446446
node.x = 0;
447447
}
448448

449-
if (node.x + node.width > this.columns) {
449+
if (node.x + node.width > this.column) {
450450
if (resizing) {
451-
node.width = this.columns - node.x;
451+
node.width = this.column - node.x;
452452
} else {
453-
node.x = this.columns - node.width;
453+
node.x = this.column - node.width;
454454
}
455455
}
456456

@@ -498,9 +498,9 @@
498498
this._sortNodes();
499499

500500
for (var i = 0;; ++i) {
501-
var x = i % this.columns;
502-
var y = Math.floor(i / this.columns);
503-
if (x + node.width > this.columns) {
501+
var x = i % this.column;
502+
var y = Math.floor(i / this.column);
503+
if (x + node.width > this.column) {
504504
continue;
505505
}
506506
if (!this.nodes.find(Utils._isAddNodeIntercepted, {x: x, y: y, node: node})) {
@@ -537,13 +537,13 @@
537537
}
538538
var hasLocked = Boolean(this.nodes.find(function(n) { return n.locked; }));
539539

540-
if (!this.maxRows && !hasLocked) {
540+
if (!this.maxRow && !hasLocked) {
541541
return true;
542542
}
543543

544544
var clonedNode;
545545
var clone = new GridStackEngine(
546-
this.columns,
546+
this.column,
547547
null,
548548
this.float,
549549
0,
@@ -566,26 +566,26 @@
566566
return n !== clonedNode && Boolean(n.locked) && Boolean(n._dirty);
567567
}));
568568
}
569-
if (this.maxRows) {
570-
res &= clone.getGridHeight() <= this.maxRows;
569+
if (this.maxRow) {
570+
res &= clone.getGridHeight() <= this.maxRow;
571571
}
572572

573573
return res;
574574
};
575575

576576
GridStackEngine.prototype.canBePlacedWithRespectToHeight = function(node) {
577-
if (!this.maxRows) {
577+
if (!this.maxRow) {
578578
return true;
579579
}
580580

581581
var clone = new GridStackEngine(
582-
this.columns,
582+
this.column,
583583
null,
584584
this.float,
585585
0,
586586
this.nodes.map(function(n) { return $.extend({}, n); }));
587587
clone.addNode(node);
588-
return clone.getGridHeight() <= this.maxRows;
588+
return clone.getGridHeight() <= this.maxRow;
589589
};
590590

591591
GridStackEngine.prototype.isNodeChangedPosition = function(node, x, y, width, height) {
@@ -686,20 +686,20 @@
686686
obsoleteOpts(opts, 'static_grid', 'staticGrid');
687687
obsoleteOpts(opts, 'is_nested', 'isNested');
688688
obsoleteOpts(opts, 'always_show_resize_handle', 'alwaysShowResizeHandle');
689-
obsoleteOpts(opts, 'width', 'columns');
690-
obsoleteOpts(opts, 'height', 'maxRows');
689+
obsoleteOpts(opts, 'width', 'column');
690+
obsoleteOpts(opts, 'height', 'maxRow');
691691

692692
// container attributes
693-
obsoleteAttr(this.container, 'data-gs-width', 'data-gs-columns');
694-
obsoleteAttr(this.container, 'data-gs-height', 'data-gs-max-rows');
693+
obsoleteAttr(this.container, 'data-gs-width', 'data-gs-column');
694+
obsoleteAttr(this.container, 'data-gs-height', 'data-gs-max-row');
695695
/*eslint-enable camelcase */
696696

697697
opts.itemClass = opts.itemClass || 'grid-stack-item';
698698
var isNested = this.container.closest('.' + opts.itemClass).length > 0;
699699

700700
this.opts = Utils.defaults(opts || {}, {
701-
columns: parseInt(this.container.attr('data-gs-columns')) || 12,
702-
maxRows: parseInt(this.container.attr('data-gs-max-rows')) || 0,
701+
column: parseInt(this.container.attr('data-gs-column')) || 12,
702+
maxRow: parseInt(this.container.attr('data-gs-max-row')) || 0,
703703
itemClass: 'grid-stack-item',
704704
placeholderClass: 'grid-stack-placeholder',
705705
placeholderText: '',
@@ -776,7 +776,7 @@
776776

777777
this._initStyles();
778778

779-
this.grid = new GridStackEngine(this.opts.columns, function(nodes, detachNode) {
779+
this.grid = new GridStackEngine(this.opts.column, function(nodes, detachNode) {
780780
detachNode = detachNode === undefined ? true : detachNode;
781781
var maxHeight = 0;
782782
this.nodes.forEach(function(n) {
@@ -796,7 +796,7 @@
796796
}
797797
});
798798
self._updateStyles(maxHeight + 10);
799-
}, this.opts.float, this.opts.maxRows);
799+
}, this.opts.float, this.opts.maxRow);
800800

801801
if (this.opts.auto) {
802802
var elements = [];
@@ -808,7 +808,7 @@
808808
el: el,
809809
// if x,y are missing (autoPosition) add them to end of list - keep their respective DOM order
810810
i: (parseInt(el.attr('data-gs-x')) || 100) +
811-
(parseInt(el.attr('data-gs-y')) || 100) * _this.opts.columns
811+
(parseInt(el.attr('data-gs-y')) || 100) * _this.opts.column
812812
});
813813
});
814814
Utils.sortBy(elements, function(x) { return x.i; }).forEach(function(item) {
@@ -1296,9 +1296,9 @@
12961296
self.grid.beginUpdate(node);
12971297
cellWidth = self.cellWidth();
12981298
var strictCellHeight = self.cellHeight();
1299-
// TODO: cellHeight cannot be set to cellHeight() (i.e. remove strictCellHeight) right here otherwise
1299+
// TODO: cellHeight = cellHeight() causes issue (i.e. remove strictCellHeight above) otherwise
13001300
// when sizing up we jump almost right away to next size instead of half way there. Not sure
1301-
// why as we don't use ceil() is many places but round().
1301+
// why as we don't use ceil() in many places but round() instead.
13021302
cellHeight = self.container.height() / parseInt(self.container.attr('data-gs-current-height'));
13031303
self.placeholder
13041304
.attr('data-gs-x', o.attr('data-gs-x'))
@@ -1710,7 +1710,7 @@
17101710

17111711
var heightData = Utils.parseHeight(val);
17121712

1713-
if (this.opts.verticalMarginUnit === heightData.unit && this.opts.maxRows === heightData.height) {
1713+
if (this.opts.verticalMarginUnit === heightData.unit && this.opts.maxRow === heightData.height) {
17141714
return ;
17151715
}
17161716
this.opts.verticalMarginUnit = heightData.unit;
@@ -1750,7 +1750,7 @@
17501750

17511751
GridStack.prototype.cellWidth = function() {
17521752
// TODO: take margin into account ($horizontal_padding in .scss) to make cellHeight='auto' square ? (see 810-many-columns.html)
1753-
return Math.round(this.container.outerWidth() / this.opts.columns);
1753+
return Math.round(this.container.outerWidth() / this.opts.column);
17541754
};
17551755

17561756
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
@@ -1759,7 +1759,7 @@
17591759
var relativeLeft = position.left - containerPos.left;
17601760
var relativeTop = position.top - containerPos.top;
17611761

1762-
var columnWidth = Math.floor(this.container.width() / this.opts.columns);
1762+
var columnWidth = Math.floor(this.container.width() / this.opts.column);
17631763
var rowHeight = Math.floor(this.container.height() / parseInt(this.container.attr('data-gs-current-height')));
17641764

17651765
return {x: Math.floor(relativeLeft / columnWidth), y: Math.floor(relativeTop / rowHeight)};
@@ -1808,11 +1808,11 @@
18081808
};
18091809

18101810
GridStack.prototype.setGridWidth = function(gridWidth,doNotPropagate) {
1811-
this.container.removeClass('grid-stack-' + this.opts.columns);
1811+
this.container.removeClass('grid-stack-' + this.opts.column);
18121812
if (doNotPropagate !== true) {
1813-
this._updateNodeWidths(this.opts.columns, gridWidth);
1813+
this._updateNodeWidths(this.opts.column, gridWidth);
18141814
}
1815-
this.opts.columns = gridWidth;
1815+
this.opts.column = gridWidth;
18161816
this.grid.width = gridWidth;
18171817
this.container.addClass('grid-stack-' + gridWidth);
18181818
};

0 commit comments

Comments
 (0)