Skip to content

Commit

Permalink
merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
troolee committed Aug 17, 2016
2 parents ae19e78 + fcd2327 commit 74a6ad6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ Changes
- fix jQuery `size()` ([#486](https://github.com/troolee/gridstack.js/issues/486)).
- update _notify to allow detach ([#411](https://github.com/troolee/gridstack.js/issues/411)).
- fix code that checks for jquery-ui ([#481](https://github.com/troolee/gridstack.js/issues/481)).
- fix `cellWidth` calculation on empty grid

#### v0.2.5 (2016-03-02)

Expand Down
5 changes: 2 additions & 3 deletions dist/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@
var o = $(this);
self.grid.cleanNodes();
self.grid.beginUpdate(node);
cellWidth = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
cellWidth = self.cellWidth();
var strictCellHeight = Math.ceil(o.outerHeight() / o.attr('data-gs-height'));
cellHeight = self.container.height() / parseInt(self.container.attr('data-gs-current-height'));
self.placeholder
Expand Down Expand Up @@ -1494,8 +1494,7 @@
};

GridStack.prototype.cellWidth = function() {
var o = this.container.children('.' + this.opts.itemClass).first();
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
return Math.round(this.container.outerWidth() / this.opts.width);
};

GridStack.prototype.getCellFromPixel = function(position, useOffset) {
Expand Down
4 changes: 2 additions & 2 deletions dist/gridstack.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gridstack.min.map

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions spec/gridstack-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,27 @@ describe('gridstack', function() {
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should return 96.', function() {
it('should return 1/12th of container width.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
verticalMargin: 10,
width: 12
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var res = Math.round($('.grid-stack').outerWidth() / 12);
expect(grid.cellWidth()).toBe(res);
});
it('should return 1/10th of container width.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10,
width: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
expect(grid.cellWidth()).toBe(96);
var res = Math.round($('.grid-stack').outerWidth() / 10);
expect(grid.cellWidth()).toBe(res);
});
});

Expand Down
5 changes: 2 additions & 3 deletions src/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@
var o = $(this);
self.grid.cleanNodes();
self.grid.beginUpdate(node);
cellWidth = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
cellWidth = self.cellWidth();
var strictCellHeight = Math.ceil(o.outerHeight() / o.attr('data-gs-height'));
cellHeight = self.container.height() / parseInt(self.container.attr('data-gs-current-height'));
self.placeholder
Expand Down Expand Up @@ -1494,8 +1494,7 @@
};

GridStack.prototype.cellWidth = function() {
var o = this.container.children('.' + this.opts.itemClass).first();
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
return Math.round(this.container.outerWidth() / this.opts.width);
};

GridStack.prototype.getCellFromPixel = function(position, useOffset) {
Expand Down

0 comments on commit 74a6ad6

Please sign in to comment.