Skip to content

Commit b54d6c9

Browse files
Merge pull request #1 from gridstack/develop
Fastforward my repo
2 parents 03c986d + dda8de1 commit b54d6c9

11 files changed

+45
-67
lines changed

demo/advance.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,11 @@ <h1>Advanced Demo</h1>
117117
acceptWidgets: '.newWidget'
118118
});
119119

120-
grid.on('added', function(e, items) { log('added ', items) });
121-
grid.on('removed', function(e, items) { log('removed ', items) });
122-
grid.on('change', function(e, items) { log('change ', items) });
123-
function log(type, items) {
120+
grid.on('added removed change', function(e, items) {
124121
var str = '';
125122
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
126-
console.log(type + items.length + ' items.' + str );
127-
}
123+
console.log(e.type + ' ' + items.length + ' items:' + str );
124+
});
128125

129126
// TODO: switch jquery-ui out
130127
$('.newWidget').draggable({

demo/column.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@ <h1>column() grid demo</h1>
3838
var grid = GridStack.init({float: true});
3939
var text = document.querySelector('#column-text');
4040

41-
grid.on('added', function(e, items) {log('added ', items)});
42-
grid.on('removed', function(e, items) {log('removed ', items)});
43-
grid.on('change', function(e, items) {log('change ', items)});
44-
function log(type, items) {
41+
grid.on('added removed change', function(e, items) {
4542
var str = '';
4643
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
47-
console.log(type + items.length + ' items.' + str );
48-
}
44+
console.log(e.type + ' ' + items.length + ' items:' + str );
45+
});
4946

5047
var items = [
5148
/* match karma testing

demo/serialization.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ <h1>Serialization demo</h1>
2828
<script type="text/javascript">
2929
var grid = GridStack.init();
3030

31-
grid.on('added', function(e, items) {log('added ', items)});
32-
grid.on('removed', function(e, items) {log('removed ', items)});
33-
grid.on('change', function(e, items) {log('change ', items)});
34-
function log(type, items) {
31+
grid.on('added removed change', function(e, items) {
3532
var str = '';
3633
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
37-
console.log(type + items.length + ' items.' + str );
38-
}
34+
console.log(e.type + ' ' + items.length + ' items:' + str );
35+
});
3936

4037
var serializedData = [
4138
{x: 0, y: 0, width: 2, height: 2},

demo/two.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,16 @@ <h1>Two grids demo</h1>
111111
{x: 0, y: 0, width: 2, height: 2},
112112
{x: 3, y: 1, width: 1, height: 2},
113113
{x: 4, y: 1, width: 1, height: 1},
114-
{x: 2, y: 3, width: 3, height: 1, minWidth: 2, id: 'special', text: 'has minWidth=2'},
114+
{x: 2, y: 3, width: 3, height: 1, maxWidth: 3, id: 'special', text: 'has maxWidth=3'},
115115
{x: 2, y: 5, width: 1, height: 1}
116116
];
117117

118118
grids.forEach(function (grid, i) {
119-
grid.on('added', function(e, items) { log(i, ' added ', items) });
120-
grid.on('removed', function(e, items) { log(i, ' removed ', items) });
121-
grid.on('change', function(e, items) { log(i, ' change ', items) });
122-
function log(id, type, items) {
119+
grid.on('added removed change', function(e, items) {
123120
var str = '';
124121
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
125-
console.log('grid' + id + type + items.length + ' items.' + str );
126-
}
122+
console.log('grid' + i + ' ' + e.type + ' ' + items.length + ' items:' + str );
123+
});
127124

128125
grid.batchUpdate();
129126
items.forEach(function (node) {

doc/CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Change log
3333

3434
## 1.0.0-dev (upcoming)
3535

36-
-- fix [(1166)](https://github.com/gridstack/gridstack.js/issues/1166) resize not taking margin height into account
36+
- fix [(1166)](https://github.com/gridstack/gridstack.js/issues/1166) resize not taking margin height into account
37+
- fix [(1155)](https://github.com/gridstack/gridstack.js/issues/1155) `maxRow` now limit initial item placement if out of bound, preventing broken drag behavior
38+
- fix [(1171)](https://github.com/gridstack/gridstack.js/issues/1171) added event support to call `grid.on('added removed change', callback)` again even with native events.
3739

3840
## v1.0.0 (2020-02-23)
3941

doc/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ to completely lock the widget.
123123

124124
## Events
125125

126-
Those are the events set by the grid when items are added/removed or changed - they use standard JS calls with a CustomElement that stores the list
127-
of nodes that changed (id, x, y, width, height, etc...)
126+
Those are the events set by the grid when items are added/removed or changed - they use standard JS calls with a CustomElement `detail` that stores the list
127+
of nodes that changed (id, x, y, width, height, etc...).
128+
129+
You can call it on a single event name, or space separated list:
130+
`grid.on('added removed change', ...)`
128131

129132
### added(event, items)
130133

spec/e2e/html/1142_change_event_missing.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@
2424
<script type="text/javascript">
2525
var grid = GridStack.init({float: false});
2626

27-
grid.on('added', function(e, items) {log('added ', items)});
28-
grid.on('removed', function(e, items) {log('removed ', items)});
29-
grid.on('change', function(e, items) {log('change ', items)});
30-
function log(type, items) {
27+
grid.on('added removed change', function(e, items) {
3128
var str = '';
3229
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
33-
console.log(type + items.length + ' items.' + str);
34-
}
30+
console.log(e.type + ' ' + items.length + ' items:' + str );
31+
});
3532

3633
$('.grid-stack .grid-stack-item').click(function(e) {
3734
var item = $(e.currentTarget).closest('.grid-stack-item');

spec/e2e/html/1143_nested_acceptWidget_types.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@
6161
var grid = GridStack.init({ acceptWidgets: '.otherWidgetType' }, '.grid-stack.outer');
6262
var gridNest = GridStack.init({ acceptWidgets: '.newWidget' }, '.grid-stack.nested');
6363

64-
grid.on('added', function(e, items) {log('added ', items)});
65-
grid.on('removed', function(e, items) {log('removed ', items)});
66-
grid.on('change', function(e, items) {log('change ', items)});
67-
function log(type, items) {
64+
grid.on('added removed change', function(e, items) {
6865
var str = '';
6966
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
70-
console.log(type + items.length + ' items.' + str );
71-
}
67+
console.log(e.type + ' ' + items.length + ' items:' + str );
68+
});
7269

7370
$('.newWidget').draggable({
7471
revert: 'invalid',

spec/e2e/html/events.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ <h1>Events test</h1>
3030
+ count++ + '</div></div>');
3131
};
3232

33-
grid.on('added', function(e, items) {log('added ', items)});
34-
grid.on('removed', function(e, items) {log('removed ', items)});
35-
grid.on('change', function(e, items) {log('change ', items)});
36-
function log(type, items) {
33+
grid.on('added removed change', function(e, items) {
3734
var str = '';
38-
items.forEach(function(item) { str += ' (x,y,wxh)=' + item.x + ',' + item.y + ' ' + item.width + 'x' + item.height; });
39-
console.log(type + items.length + ' items.' + str );
40-
}
35+
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
36+
console.log(e.type + ' ' + items.length + ' items:' + str );
37+
});
4138

4239
grid.on('disable', function(event) {
4340
var grid = event.target;

spec/gridstack-spec.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ describe('gridstack', function() {
828828
expect(parseInt($widget.attr('data-gs-y'), 10)).toBe(0);
829829
expect(parseInt($widget.attr('data-gs-width'), 10)).toBe(1);
830830
expect(parseInt($widget.attr('data-gs-height'), 10)).toBe(2);
831-
expect($widget.attr('data-gs-auto-position')).toBe(undefined);
831+
expect($widget.attr('data-gs-auto-position')).toBe('true');
832832
expect($widget.attr('data-gs-min-width')).toBe(undefined);
833833
expect($widget.attr('data-gs-max-width')).toBe(undefined);
834834
expect($widget.attr('data-gs-min-height')).toBe(undefined);
@@ -843,7 +843,7 @@ describe('gridstack', function() {
843843
expect(parseInt($widget.attr('data-gs-y'), 10)).toBe(0);
844844
expect(parseInt($widget.attr('data-gs-width'), 10)).toBe(1);
845845
expect(parseInt($widget.attr('data-gs-height'), 10)).toBe(2);
846-
expect($widget.attr('data-gs-auto-position')).toBe(undefined);
846+
expect($widget.attr('data-gs-auto-position')).toBe('true');
847847
expect($widget.attr('data-gs-min-width')).toBe(undefined);
848848
expect($widget.attr('data-gs-max-width')).toBe(undefined);
849849
expect($widget.attr('data-gs-min-height')).toBe(undefined);
@@ -858,7 +858,7 @@ describe('gridstack', function() {
858858
expect(parseInt($widget.attr('data-gs-y'), 10)).toBe(0);
859859
expect(parseInt($widget.attr('data-gs-width'), 10)).toBe(1);
860860
expect(parseInt($widget.attr('data-gs-height'), 10)).toBe(2);
861-
expect($widget.attr('data-gs-auto-position')).toBe(undefined);
861+
expect($widget.attr('data-gs-auto-position')).toBe('true');
862862
expect($widget.attr('data-gs-min-width')).toBe(undefined);
863863
expect($widget.attr('data-gs-max-width')).toBe(undefined);
864864
expect($widget.attr('data-gs-min-height')).toBe(undefined);
@@ -873,7 +873,7 @@ describe('gridstack', function() {
873873
expect(parseInt($widget.attr('data-gs-y'), 10)).toBe(0);
874874
expect(parseInt($widget.attr('data-gs-width'), 10)).toBe(1);
875875
expect(parseInt($widget.attr('data-gs-height'), 10)).toBe(2);
876-
expect($widget.attr('data-gs-auto-position')).toBe(undefined);
876+
expect($widget.attr('data-gs-auto-position')).toBe('true');
877877
expect($widget.attr('data-gs-min-width')).toBe(undefined);
878878
expect($widget.attr('data-gs-max-width')).toBe(undefined);
879879
expect($widget.attr('data-gs-min-height')).toBe(undefined);
@@ -888,7 +888,7 @@ describe('gridstack', function() {
888888
expect(parseInt($widget.attr('data-gs-y'), 10)).toBe(0);
889889
expect(parseInt($widget.attr('data-gs-width'), 10)).toBe(1);
890890
expect(parseInt($widget.attr('data-gs-height'), 10)).toBe(1);
891-
expect($widget.attr('data-gs-auto-position')).toBe(undefined);
891+
expect($widget.attr('data-gs-auto-position')).toBe('true');
892892
expect($widget.attr('data-gs-min-width')).toBe(undefined);
893893
expect($widget.attr('data-gs-max-width')).toBe(undefined);
894894
expect($widget.attr('data-gs-min-height')).toBe(undefined);
@@ -1032,24 +1032,16 @@ describe('gridstack', function() {
10321032
afterEach(function() {
10331033
document.body.removeChild(document.getElementById('gs-cont'));
10341034
});
1035-
it('should do nothing and return node', function() {
1036-
var options = {
1037-
cellHeight: 80,
1038-
verticalMargin: 10
1039-
};
1040-
var grid = GridStack.init(options);
1035+
it('should do nothing and return NULL to mean nothing happened', function() {
1036+
var grid = GridStack.init();
10411037
var items = $('.grid-stack-item');
10421038
grid._updateElement(items[0], function(el, node) {
1043-
var newNode = grid.engine.moveNode(node);
1044-
expect(newNode).toBe(node);
1039+
var hasMoved = grid.engine.moveNode(node);
1040+
expect(hasMoved).toBe(null);
10451041
});
10461042
});
10471043
it('should do nothing and return node', function() {
1048-
var options = {
1049-
cellHeight: 80,
1050-
verticalMargin: 10
1051-
};
1052-
var grid = GridStack.init(options);
1044+
var grid = GridStack.init();
10531045
var items = $('.grid-stack-item');
10541046
grid.minWidth(items[0], 1);
10551047
grid.maxWidth(items[0], 2);

0 commit comments

Comments
 (0)